V4.0 - This new version, incorporates multiple bug fixes and some improvements

### Improvemnets
- The job's buffer generation no longer needs the study area
- The job's buffer generation no longer needs the study area
- During the scenario generation the following policies are copied
from the table population_layers hcost_level, vacant_hu_level,
infill_level, prioritize_tod_level, beyond_udp_level, only_vacant_level
-The way to develop new indicators in the tool has been changed
to facilitate the process.

### Fixes
- The infrastructure_consolidation_costs has been removed from the
calculation of unfrastructure costs
- Fixed a bug in the calculation emissions transport,
the error happened when the square have no values
for transit distance or job_density_avge
parent e0143195
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).
The UP_Calculator app is licensed under MIT License
You can modify this license when you add your own code.
MIT License
Copyright (c) 2018 CAPSUS S.C.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
......@@ -2,7 +2,7 @@ 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)
user_city = db(db.admin_user_city.created_by==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:
......@@ -11,6 +11,9 @@ def index():
db.amenities._common_filter = lambda query: db.amenities.city_code.belongs(usercities)
session.active_method="index"
session.active_controller="amenities"
if 'edit' in request.args or 'new' in request.args:
db.amenities.created_on.writable = False
db.amenities.created_by.writable = False
return dict(grid=SQLFORM.smartgrid(db.amenities, linked_tables=[], user_signature=False))
......@@ -94,7 +97,7 @@ def process_csv():
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['created_by']=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")
......@@ -127,6 +130,7 @@ def delete():
SELECT(
_name='country_code'
,_id="country_code"
,_required=True
, *[OPTION(countries[i].country, _value=str(countries[i].id)) for i in range(len(countries))], _class="form-control")
]
)
......@@ -136,7 +140,7 @@ def delete():
"Select a city:", _class='col-xs-12', _for="city_code"
)
,SELECT(
_name='city_code', _id="city_code", _class="form-control")
_name='city_code', _id="city_code",_required=True, _class="form-control")
]
)
, DIV(_class='form-group',
......@@ -145,12 +149,12 @@ def delete():
"Select a amenity level:", _class='col-xs-12', _for="level"
)
,SELECT(
_name='level', _id="level", _class="form-control")
_name='level', _id="level",_required=True, _class="form-control")
]
)
, DIV(_class='form-group',
*[
INPUT(_type='submit',
INPUT(_type='submit', _id="delete_all_confirm",
_class="col-xs-12 col-sm-6 col-md-4 col-lg-3 btn btn-default")
]
)
......@@ -167,7 +171,7 @@ def massive_delete_amenities():
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
data['created_by']=auth.user_id
db((db.amenities.country_code==data['country_code']) & (db.amenities.city_code==data['city_code'])& (db.amenities.amenity_level==data['level'])).delete()
message += T("All the amenities where deleted")
session.status = True
......
This diff is collapsed.
......@@ -2,14 +2,16 @@ 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)
user_city = db(db.admin_user_city.created_by==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.buffers._common_filter = lambda query: db.buffers.city_code.belongs(usercities)
if 'edit' in request.args or 'new' in request.args:
db.buffers.created_on.writable = False
db.buffers.created_by.writable = False
return dict(grid=SQLFORM.smartgrid(db.buffers, linked_tables=[], user_signature=False,
editable=(auth.has_membership('Administrator_back') or auth.has_membership('Specialist') or auth.has_membership('Manager') or auth.has_membership('General Manager')),
deletable=(auth.has_membership('Administrator_back') or auth.has_membership('Specialist') or auth.has_membership('Manager') or auth.has_membership('General Manager'))
......@@ -18,7 +20,7 @@ def 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 study_area():
#get the user cities
user_city = db(db.admin_user_city.user_id==auth.user_id).select(db.admin_user_city.city_id)
user_city = db(db.admin_user_city.created_by==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:
......@@ -97,7 +99,7 @@ def process_csv():
data=pd.read_csv(file_name,sep=",", encoding='utf-8',quotechar='"')
data['country_code'] = request.post_vars.country_code
data['user_id']=auth.user_id
data['created_by']=auth.user_id
newtam=(int)(data.geometry.map(lambda x: len(x)).max())
if csv.field_size_limit()<newtam:
csv.field_size_limit(newtam)
......@@ -191,7 +193,7 @@ def process_study_area_csv():
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['created_by']=auth.user_id
data.to_csv(file_name, sep=',', encoding='utf-8',index=False,doublequote=True,quotechar='"',quoting=csv.QUOTE_MINIMAL)
db.study_area.import_from_csv_file(open(file_name))
message+=insert_spatial_study_area("study_area")
......@@ -295,6 +297,7 @@ def delete():
SELECT(
_name='country_code'
,_id="country_code"
,_required=True
, *[OPTION(countries[i].country, _value=str(countries[i].id)) for i in range(len(countries))], _class="form-control")
]
)
......@@ -304,7 +307,7 @@ def delete():
"Select a city:", _class='col-xs-12', _for="city_code"
)
,SELECT(
_name='city_code', _id="city_code", _class="form-control")
_name='city_code', _id="city_code",_required=True, _class="form-control")
]
)
, DIV(_class='form-group',
......@@ -313,12 +316,12 @@ def delete():
"Select a buffer level:", _class='col-xs-12', _for="level"
)
,SELECT(
_name='level', _id="level", _class="form-control")
_name='level', _id="level",_required=True, _class="form-control")
]
)
, DIV(_class='form-group',
*[
INPUT(_type='submit',
INPUT(_type='submit', _id="delete_all_confirm",
_class="col-xs-12 col-sm-6 col-md-4 col-lg-3 btn btn-default")
]
)
......@@ -335,7 +338,7 @@ def massive_delete_buffers():
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
data['created_by']=auth.user_id
db((db.buffers.country_code==data['country_code']) & (db.buffers.city_code==data['city_code']) & (db.buffers.level==data['level'])).delete()
message += T("All the buffers level where deleted")
session.status = True
......@@ -353,4 +356,63 @@ def getBuffertLevel():
response.generic_patterns = ['json']
footprint = db((db.buffers.country_code==request.post_vars.country_code) &
(db.buffers.city_code == request.post_vars.city_code)).select(db.buffers.level, orderby=db.buffers.level ,distinct=True)
return dict(levels=footprint)
\ No newline at end of file
return dict(levels=footprint)
@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_study_area():
countries = db(db.countries).select(db.countries.id, db.countries.country)
form = FORM(
_action=URL("buffers","/process_delete_study_area")
,_method="post"
,*[DIV(_class='form-group',
*[
LABEL(
"Select a country:", _class='col-xs-12', _for="country_code"
),
SELECT(
_name='country_code'
,_id="country_code"
,_required=True
, *[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",_required=True, _class="form-control")
]
)
, DIV(_class='form-group',
*[
INPUT(_type='submit', _id="delete_all_confirm",
_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_delete_study_area():
message=""
try:
data=dict()
data['country_code'] = request.post_vars.country_code
data['city_code'] = request.post_vars.city_code
data['created_by']=auth.user_id
db((db.study_area.country_code==data['country_code']) & (db.study_area.city_code==data['city_code'])).delete()
message += T("All the study area was deleted")
session.status = True
except Exception as e:
db.rollback()
message += T("There was an error when deleting the study area")
message = message + " " + str(e)
session.status = False
else:
db.commit()
session.message = message
redirect(URL("buffers","index"))
\ No newline at end of file
......@@ -4,14 +4,16 @@ def index():
session.active_method = "index"
session.active_controller = "cities"
#get the user cities
user_city = db(db.admin_user_city.user_id==auth.user_id).select(db.admin_user_city.city_id)
user_city = db(db.admin_user_city.created_by==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.cities._common_filter = lambda query: db.cities.id.belongs(usercities)
if 'edit' in request.args or 'new' in request.args:
db.cities.created_on.writable = False
db.cities.created_by.writable = False
return dict(grid=SQLFORM.smartgrid(db.cities,
linked_tables=['housing_costs', 'amenities', 'hazards', 'footprint', 'criteria', 'transit', 'population', 'road_intersections', 'jobs', 'assumpions', 'source_origin', 'municipalities'],
user_signature=False,
......@@ -25,7 +27,7 @@ def set_user_city(form):
city=request.post_vars["city_code"]
cities = db(db.cities.city_code==city,ignore_common_filters=True).select(db.cities.id)
print("2",cities)
db.admin_user_city.insert(city_id=cities[0].id,user_id=auth.user_id)
db.admin_user_city.insert(city_id=cities[0].id,created_by=auth.user_id)
except Exception as e:
print (e,cities,auth.user_id)
......@@ -34,7 +36,7 @@ def getCities():
response.generic_patterns = ['json']
#get the user cities
user_city = db(db.admin_user_city.user_id==auth.user_id).select(db.admin_user_city.city_id)
user_city = db(db.admin_user_city.created_by==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:
......@@ -101,7 +103,7 @@ def process_csv():
data = pd.read_csv(file_name, sep=",", encoding='utf-8', quotechar='"')
data['country_code'] = request.post_vars.country_code
data['user_id'] = auth.user_id
data['created_by'] = auth.user_id
data.to_csv(file_name, sep=',', encoding='utf-8', index=False,
doublequote=True, quotechar='"', quoting=csv.QUOTE_MINIMAL)
db.cities.import_from_csv_file(open(file_name))
......@@ -123,7 +125,7 @@ def process_csv():
cities = db((db.cities.city_code.belongs(_cities))&
(db.cities.country_code==request.post_vars.country_code),ignore_common_filters=True).select(db.cities.id)
for city in cities:
db.admin_user_city.insert(city_id=city["id"],user_id=auth.user_id)
db.admin_user_city.insert(city_id=city["id"],created_by=auth.user_id)
session.message = message
redirect(URL("cities", "index"))
......
......@@ -3,6 +3,9 @@ T.force('en')
def index():
session.active_method="index"
session.active_controller="countries"
if 'edit' in request.args or 'new' in request.args:
db.countries.created_on.writable = False
db.countries.created_by.writable = False
return dict(grid=SQLFORM.smartgrid(db.countries, linked_tables=['cities'], user_signature=False,
editable=(auth.has_membership('Administrator_back') or auth.has_membership('Manager') or auth.has_membership('General Manager')),
deletable=(auth.has_membership('Administrator_back') or auth.has_membership('Manager') or auth.has_membership('General Manager')),
......@@ -59,7 +62,7 @@ def process_csv():
message+=T("The file was uploaded successfully ")
data=pd.read_csv(file_name,sep=",", encoding='utf-8',quotechar='"')
data['user_id']=auth.user_id
data['created_by']=auth.user_id
data.to_csv(file_name, sep=',', encoding='utf-8',index=False,doublequote=True,quotechar='"',quoting=csv.QUOTE_MINIMAL)
db.countries.import_from_csv_file(open(file_name))
os.remove(file_name)
......
......@@ -4,13 +4,18 @@ def index():
session.active_method="index"
session.active_controller="criteria"
#get the user cities
user_city = db(db.admin_user_city.user_id==auth.user_id).select(db.admin_user_city.city_id)
user_city = db(db.admin_user_city.created_by==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.criteria._common_filter = lambda query: db.criteria.city_code.belongs(usercities)
if 'edit' in request.args or 'new' in request.args:
db.criteria.created_on.writable = False
db.criteria.created_by.writable = False
return dict(grid=SQLFORM.smartgrid(db.criteria, linked_tables=[], user_signature=False,
editable=(auth.has_membership('Administrator_back') or auth.has_membership('Manager') or auth.has_membership('General Manager') or auth.has_membership('Specialist')),
deletable=(auth.has_membership('Administrator_back') or auth.has_membership('Manager') or auth.has_membership('General Manager') or auth.has_membership('Specialist'))
......@@ -90,7 +95,7 @@ def process_csv():
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['created_by']=auth.user_id
data.to_csv(file_name, sep=',', encoding='utf-8',index=False,doublequote=True,quotechar='"',quoting=csv.QUOTE_MINIMAL)
db.criteria.import_from_csv_file(open(file_name))
os.remove(file_name)
......@@ -120,6 +125,7 @@ def delete():
SELECT(
_name='country_code'
,_id="country_code"
,_required=True
, *[OPTION(countries[i].country, _value=str(countries[i].id)) for i in range(len(countries))], _class="form-control")
]
)
......@@ -129,12 +135,12 @@ def delete():
"Select a city:", _class='col-xs-12', _for="city_code"
)
,SELECT(
_name='city_code', _id="city_code", _class="form-control")
_name='city_code', _id="city_code",_required=True, _class="form-control")
]
)
, DIV(_class='form-group',
*[
INPUT(_type='submit',
INPUT(_type='submit', _id="delete_all_confirm",
_class="col-xs-12 col-sm-6 col-md-4 col-lg-3 btn btn-default")
]
)
......@@ -150,7 +156,7 @@ def massive_delete_criteria():
data=dict()
data['country_code'] = request.post_vars.country_code
data['city_code'] = request.post_vars.city_code
data['user_id']=auth.user_id
data['created_by']=auth.user_id
db((db.criteria.country_code==data['country_code']) & (db.criteria.city_code==data['city_code'])).delete()
message += T("All the criteria was deleted")
session.status = True
......
......@@ -4,13 +4,18 @@ def index():
session.active_method="index"
session.active_controller="cycle"
#get the user cities
user_city = db(db.admin_user_city.user_id==auth.user_id).select(db.admin_user_city.city_id)
user_city = db(db.admin_user_city.created_by==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.cycle._common_filter = lambda query: db.cycle.city_code.belongs(usercities)
if 'edit' in request.args or 'new' in request.args:
db.cycle.created_on.writable = False
db.cycle.created_by.writable = False
return dict(grid=SQLFORM.smartgrid(db.cycle, linked_tables=[], user_signature=False,
editable=(auth.has_membership('Administrator_back') or auth.has_membership('Manager') or auth.has_membership('General Manager') or auth.has_membership('Specialist')),
deletable=(auth.has_membership('Administrator_back') or auth.has_membership('Manager') or auth.has_membership('General Manager') or auth.has_membership('Specialist')),
......@@ -99,7 +104,7 @@ def process_csv():
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['created_by']=auth.user_id
data.to_csv(file_name, sep=',', encoding='utf-8',index=False,doublequote=True,quotechar='"',quoting=csv.QUOTE_MINIMAL)
newtam=(int)(data.location.map(lambda x: len(x)).max())
if csv.field_size_limit()<newtam:
......@@ -135,6 +140,7 @@ def delete():
SELECT(
_name='country_code'
,_id="country_code"
,_required=True
, *[OPTION(countries[i].country, _value=str(countries[i].id)) for i in range(len(countries))], _class="form-control")
]
)
......@@ -144,7 +150,7 @@ def delete():
"Select a city:", _class='col-xs-12', _for="city_code"
)
,SELECT(
_name='city_code', _id="city_code", _class="form-control")
_name='city_code', _id="city_code",_required=True, _class="form-control")
]
)
, DIV(_class='form-group',
......@@ -153,12 +159,12 @@ def delete():
"Select a amenity level:", _class='col-xs-12', _for="level"
)
,SELECT(
_name='level', _id="level", _class="form-control")
_name='level', _id="level",_required=True, _class="form-control")
]
)
, DIV(_class='form-group',
*[
INPUT(_type='submit',
INPUT(_type='submit', _id="delete_all_confirm",
_class="col-xs-12 col-sm-6 col-md-4 col-lg-3 btn btn-default")
]
)
......@@ -175,7 +181,7 @@ def massive_delete_cycle():
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
data['created_by']=auth.user_id
db((db.cycle.country_code==data['country_code']) & (db.cycle.city_code==data['city_code'])& (db.cycle.cycle_level==data['level'])).delete()
message += T("All the cycle where deleted")
session.status = True
......
......@@ -5,13 +5,18 @@ def index():
session.active_controller="footprint"
#get the user cities
user_city = db(db.admin_user_city.user_id==auth.user_id).select(db.admin_user_city.city_id)
user_city = db(db.admin_user_city.created_by==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.footprint._common_filter = lambda query: db.footprint.city_code.belongs(usercities)
if 'edit' in request.args or 'new' in request.args:
db.footprint.created_on.writable = False
db.footprint.created_by.writable = False
return dict(grid=SQLFORM.smartgrid(db.footprint, linked_tables=[], user_signature=False,
editable=(auth.has_membership('Administrator_back') or auth.has_membership('Manager') or auth.has_membership('General Manager') or auth.has_membership('Specialist')),
deletable=(auth.has_membership('Administrator_back') or auth.has_membership('Manager') or auth.has_membership('General Manager') or auth.has_membership('Specialist'))
......@@ -98,7 +103,7 @@ def process_csv():
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['created_by']=auth.user_id
newtam=(int)(data.geometry.map(lambda x: len(x)).max())
if csv.field_size_limit()<newtam:
csv.field_size_limit(newtam)
......@@ -133,13 +138,14 @@ def delete():
SELECT(
_name='country_code'
,_id="country_code"
,_required=True
, *[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 a city:", _class='col-xs-12',_required=True, _for="city_code"
)
,SELECT(
_name='city_code', _id="city_code", _class="form-control")
......@@ -148,7 +154,7 @@ def delete():
, DIV(_class='form-group',
*[
LABEL(
"Select a amenity level:", _class='col-xs-12', _for="level"
"Select a amenity level:", _class='col-xs-12',_required=True, _for="level"
)
,SELECT(
_name='level', _id="level", _class="form-control")
......@@ -156,7 +162,7 @@ def delete():
)
, DIV(_class='form-group',
*[
INPUT(_type='submit',
INPUT(_type='submit', _id="delete_all_confirm",
_class="col-xs-12 col-sm-6 col-md-4 col-lg-3 btn btn-default")
]
)
......@@ -173,7 +179,7 @@ def massive_delete_footprint():
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
data['created_by']=auth.user_id
db((db.footprint.country_code==data['country_code']) & (db.footprint.city_code==data['city_code']) & (db.footprint.level==data['level'])).delete()
message += T("All the footprint where deleted")
session.status = True
......
......@@ -4,13 +4,18 @@ def index():
session.active_method="index"
session.active_controller="hazards"
#get the user cities
user_city = db(db.admin_user_city.user_id==auth.user_id).select(db.admin_user_city.city_id)
user_city = db(db.admin_user_city.created_by==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.hazards._common_filter = lambda query: db.hazards.city_code.belongs(usercities)
if 'edit' in request.args or 'new' in request.args:
db.hazards.created_on.writable = False
db.hazards.created_by.writable = False
return dict(grid=SQLFORM.smartgrid(db.hazards, linked_tables=[], user_signature=False,
editable=(auth.has_membership('Administrator_back') or auth.has_membership('Manager') or auth.has_membership('General Manager') or auth.has_membership('Specialist')),
deletable=(auth.has_membership('Administrator_back') or auth.has_membership('Manager') or auth.has_membership('General Manager') or auth.has_membership('Specialist'))
......@@ -97,7 +102,7 @@ def process_csv():
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['created_by']=auth.user_id
newtam=(int)(data.location.map(lambda x: len(x)).max())
if csv.field_size_limit()<newtam:
csv.field_size_limit(newtam)
......@@ -132,6 +137,7 @@ def delete():
SELECT(
_name='country_code'
,_id="country_code"
,_required=True
, *[OPTION(countries[i].country, _value=str(countries[i].id)) for i in range(len(countries))], _class="form-control")
]
)
......@@ -141,7 +147,7 @@ def delete():
"Select a city:", _class='col-xs-12', _for="city_code"
)
,SELECT(
_name='city_code', _id="city_code", _class="form-control")
_name='city_code', _id="city_code",_required=True, _class="form-control")
]
)
, DIV(_class='form-group',
......@@ -150,12 +156,12 @@ def delete():
"Select a amenity level:", _class='col-xs-12', _for="level"
)
,SELECT(
_name='level', _id="level", _class="form-control")
_name='level', _id="level",_required=True, _class="form-control")
]
)
, DIV(_class='form-group',
*[
INPUT(_type='submit',
INPUT(_type='submit', _id="delete_all_confirm",
_class="col-xs-12 col-sm-6 col-md-4 col-lg-3 btn btn-default")
]
)
......@@ -172,7 +178,7 @@ def massive_delete_hazards():
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
data['created_by']=auth.user_id
db((db.hazards.country_code==data['country_code']) & (db.hazards.city_code==data['city_code'])& (db.hazards.hazard_level==data['level'])).delete()
message += T("All the hazards where deleted")
session.status = True
......
......@@ -4,13 +4,18 @@ def index():
session.active_method="index"
session.active_controller="housing_costs"
#get the user cities
user_city = db(db.admin_user_city.user_id==auth.user_id).select(db.admin_user_city.city_id)
user_city = db(db.admin_user_city.created_by==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.housing_costs._common_filter = lambda query: db.housing_costs.city_code.belongs(usercities)
if 'edit' in request.args or 'new' in request.args:
db.housing_costs.created_on.writable = False
db.housing_costs.created_by.writable = False
return dict(grid=SQLFORM.smartgrid(db.housing_costs, linked_tables=[], user_signature=False,
editable=(auth.has_membership('Administrator_back') or auth.has_membership('Manager') or auth.has_membership('General Manager') or auth.has_membership('Specialist')),
deletable=(auth.has_membership('Administrator_back') or auth.has_membership('Manager') or auth.has_membership('General Manager') or auth.has_membership('Specialist'))
......@@ -95,11 +100,12 @@ def process_csv():
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['created_by']=auth.user_id
#data.hu_cost.fillna(-1, inplace=True)
#data.loc[data.hu_cost=='', 'd'] = -1
#data.fillna('null', inplace=True)
data.hu_cost.fillna(-1, inplace=True)
if 'hu_cost' in data.columns:
data.hu_cost.fillna(-1, inplace=True)
data.to_csv(file_name, sep=',', encoding='utf-8',index=False,doublequote=True,quotechar='"',quoting=csv.QUOTE_MINIMAL)
db.housing_costs.import_from_csv_file(open(file_name))
message+=insert_spatial_data("housing_costs")
......@@ -132,6 +138,7 @@ def delete():
SELECT(