Start repository

parents

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

databases/*.log
databases/*.table
documentation/
errors/
sessions/
cache/
private/appconfig.ini
**/*.pyc
Write something about this app.
Developed with web2py.
The web2py welcome app is licensed under public domain
(except for the css and js files that it includes, which have their own third party licenses).
You can modify this license when you add your own code.
File added
T.force('en')
@auth.requires(lambda: (auth.has_membership('Administrator_back')) or (auth.has_membership('Specialist')) or (auth.has_membership('Manager')) or (auth.has_membership('General Manager')))
def index():
#get the user cities
user_city = db(db.admin_user_city.user_id==auth.user_id).select(db.admin_user_city.city_id)
usercities= set()
#create a set with the user's cities
for r in user_city:
usercities.add(r.city_id)
#restrict the user to its cities
db.amenities._common_filter = lambda query: db.amenities.city_code.belongs(usercities)
session.active_method="index"
session.active_controller="amenities"
return dict(grid=SQLFORM.smartgrid(db.amenities, linked_tables=[], user_signature=False))
def getAmenities():
response.generic_patterns = ['json']
amenities = db(db.amenities).select(db.amenities.country_code,
db.amenities.country, orderby=db.amenities.city_name)
return amenities
def getAmenitiesLevel():
response.generic_patterns = ['json']
amenities = db((db.amenities.country_code==request.post_vars.country_code) &
(db.amenities.city_code == request.post_vars.city_code)).select(db.amenities.amenity_level, orderby=db.amenities.amenity_level ,distinct=True)
return dict(levels=amenities)
@auth.requires(lambda: (auth.has_membership('Administrator_back')) or (auth.has_membership('Specialist')) or (auth.has_membership('Manager')) or (auth.has_membership('General Manager')))
def import_csv():
countries = db(db.countries).select(
db.countries.id, db.countries.country)
form = FORM(
_action=URL("amenities","/process_csv")
,_method="post"
,*[DIV(_class='form-group',
*[
LABEL(
"Select a country:", _class='col-xs-12', _for="country_code"
),
SELECT(
_name='country_code'
,_id="country_code"
, *[OPTION(countries[i].country, _value=str(countries[i].id)) for i in range(len(countries))], _class="form-control")
]
)
, DIV(_class='form-group',
*[
LABEL(
"Select a city:", _class='col-xs-12', _for="city_code"
)
,SELECT(
_name='city_code', _id="city_code", _class="form-control")
]
)
, DIV(_class='form-group',
*[
LABEL(
"Select a file:", _class='col-xs-12', _for="csv_file"
)
,INPUT(
_type='file',
_name='csv_file', _id="csv_file", _class=""
,_text='Browse'
,_accept=".csv")
]
)
, DIV(_class='form-group',
*[
INPUT(_type='submit',
_class="col-xs-12 col-sm-6 col-md-4 col-lg-3 btn btn-default")
]
)
]
)
return dict(form=form)
@auth.requires(lambda: (auth.has_membership('Administrator_back')) or (auth.has_membership('Specialist')) or (auth.has_membership('Manager')) or (auth.has_membership('General Manager')))
def process_csv():
response.generic_patterns = ['*']
message=''
import csv
import shutil
import pandas as pd
import os
try:
filename=request.vars.csv_file.filename
file=request.vars.csv_file.file
file_name=os.path.join(request.folder,'uploads',filename)
shutil.copyfileobj(file,open(file_name,"wb"))
message+=T("The file was uploaded successfully ")
data=pd.read_csv(file_name,sep=",", encoding='utf-8',quotechar='"')
data['country_code'] = request.post_vars.country_code
data['city_code'] = request.post_vars.city_code
data['user_id']=auth.user_id
data.to_csv(file_name, sep=',', encoding='utf-8',index=False,doublequote=True,quotechar='"',quoting=csv.QUOTE_MINIMAL)
db.amenities.import_from_csv_file(open(file_name))
message+=insert_spatial_data("amenities")
os.remove(file_name)
if session.status!= False:
session.status=True
message+=T("The file was imported successfully into the database")
except Exception as e:
db.rollback()
message+=T("There was an error when importing the file")
message=message+" "+str(e)
session.status=False
else:
db.commit()
session.message = message
redirect(URL("amenities","index"))
@auth.requires(lambda: (auth.has_membership('Administrator_back')) or (auth.has_membership('Specialist')) or (auth.has_membership('Manager')) or (auth.has_membership('General Manager')))
def delete():
countries = db(db.countries).select(db.countries.id, db.countries.country)
form = FORM(
_action=URL("amenities","/massive_delete_amenities")
,_method="post"
,*[DIV(_class='form-group',
*[
LABEL(
"Select a country:", _class='col-xs-12', _for="country_code"
),
SELECT(
_name='country_code'
,_id="country_code"
, *[OPTION(countries[i].country, _value=str(countries[i].id)) for i in range(len(countries))], _class="form-control")
]
)
, DIV(_class='form-group',
*[
LABEL(
"Select a city:", _class='col-xs-12', _for="city_code"
)
,SELECT(
_name='city_code', _id="city_code", _class="form-control")
]
)
, DIV(_class='form-group',
*[
LABEL(
"Select a amenity level:", _class='col-xs-12', _for="level"
)
,SELECT(
_name='level', _id="level", _class="form-control")
]
)
, DIV(_class='form-group',
*[
INPUT(_type='submit',
_class="col-xs-12 col-sm-6 col-md-4 col-lg-3 btn btn-default")
]
)
]
)
return dict(form=form)
@auth.requires(lambda: (auth.has_membership('Administrator_back')) or (auth.has_membership('Specialist')) or (auth.has_membership('Manager')) or (auth.has_membership('General Manager')))
def massive_delete_amenities():
message=""
try:
data=dict()
data['country_code'] = request.post_vars.country_code
data['city_code'] = request.post_vars.city_code
data['level'] = request.post_vars.level
data['user_id']=auth.user_id
db((db.amenities.country_code==data['country_code']) & (db.amenities.city_code==data['city_code']