Skip to content

Commit

Permalink
S3Map() Method on /map (Filterable resource displayed on map). Fix/en…
Browse files Browse the repository at this point in the history
…hance various issues with Search and Project Communities
  • Loading branch information
flavour committed Jun 17, 2012
1 parent 9836d01 commit bea8d7f
Show file tree
Hide file tree
Showing 35 changed files with 1,477 additions and 1,075 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5a1d337 (2012-06-15 23:48:21)
9836d01 (2012-06-17 01:57:00)
3 changes: 2 additions & 1 deletion controllers/hrm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
Human Resource Management
"""

module = request.controller
resourcename = request.function

Expand Down Expand Up @@ -157,7 +158,7 @@ def staff():
# Remove Type filter from the Search widget
human_resource_search = s3mgr.model.get_config(tablename,
"search_method")
human_resource_search._S3Search__advanced.pop(1)
human_resource_search.advanced.pop(1)
s3mgr.configure(tablename,
list_fields = list_fields,
search_method = human_resource_search)
Expand Down
6 changes: 3 additions & 3 deletions controllers/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def index():
else:
redirect(URL(f="project"))

module_name = deployment_settings.modules[module].name_nice
response.title = module_name
return dict(module_name=module_name)
#module_name = deployment_settings.modules[module].name_nice
#response.title = module_name
#return dict(module_name=module_name)

# =============================================================================
def create():
Expand Down
1 change: 1 addition & 0 deletions controllers/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def vehicle():
title_list = T("Vehicles"),
title_update = T("Edit Vehicle"),
title_search = T("Search Vehicles"),
title_map = T("Map of Vehicles"),
subtitle_create = T("Add New Vehicle"),
label_list_button = T("List Vehicles"),
label_create_button = ADD_VEHICLE,
Expand Down
11 changes: 6 additions & 5 deletions controllers/vol.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
Volunteer Management
"""

module = request.controller
resourcename = request.function

Expand Down Expand Up @@ -79,7 +80,7 @@ def human_resource():
human_resource_search = s3mgr.model.get_config(tablename,
"search_method")
# Facility
human_resource_search._S3Search__advanced.pop(5)
human_resource_search.advanced.pop(5)
s3mgr.configure(tablename,
search_method = human_resource_search)

Expand Down Expand Up @@ -176,7 +177,7 @@ def volunteer():
human_resource_search = s3mgr.model.get_config(tablename,
"search_method")
# Remove Facility
human_resource_search._S3Search__advanced.pop(5)
human_resource_search.advanced.pop(5)
if deployment_settings.get_hrm_experience() == "programme":
# Add Programme Virtual Fields
table.virtualfields.append(s3db.hrm_programme_virtual_fields())
Expand All @@ -192,7 +193,7 @@ def volunteer():
report_options.facts = report_fields
# Add VF to the Search Filters
# Remove deprecated Active/Obsolete
human_resource_search._S3Search__advanced.pop(1)
human_resource_search.advanced.pop(1)
table.status.readable = False
table.status.writable = False
widget = s3base.S3SearchOptionsWidget(
Expand All @@ -206,7 +207,7 @@ def volunteer():
}
),
search_widget = ("human_resource_search_active", widget[0])
human_resource_search._S3Search__advanced.insert(1, search_widget)
human_resource_search.advanced.insert(1, search_widget)
def hrm_programme_opts():
"""
Provide the options for the HRM programme search filter
Expand All @@ -232,7 +233,7 @@ def hrm_programme_opts():
options = hrm_programme_opts
),
search_widget = ("human_resource_search_programme", widget[0])
human_resource_search._S3Search__advanced.insert(3, search_widget)
human_resource_search.advanced.insert(3, search_widget)
else:
list_fields.append("status")
s3.crud_strings[tablename] = s3.crud_strings["hrm_volunteer"]
Expand Down
1 change: 1 addition & 0 deletions models/00_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ def address_update(table, record_id):
title_list = T("Records"),
title_update = T("Edit Record"),
title_search = T("Search Records"),
title_map = T("Map"),
subtitle_create = T("Add New Record"),
label_list_button = T("List Records"),
label_create_button = ADD_RECORD,
Expand Down
1 change: 1 addition & 0 deletions models/00_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ def s3_rest_controller(prefix=None, resourcename=None, **attr):
http = ["GET", "POST"],
representation="pdf")
r.set_handler("import", s3base.S3Importer())
r.set_handler("map", s3base.S3Map())

# Execute the request
output = r(**attr)
Expand Down
1 change: 1 addition & 0 deletions modules/eden/fire.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def model(self):
title_update = T("Edit Station Details"),
title_search = T("Search for Fire Station"),
title_upload = T("Upload Fire Stations List"),
title_map = T("Map of Fire Stations"),
subtitle_create = T("Add New Fire Station"),
label_list_button = T("List Fire Stations"),
label_create_button = ADD_FIRE_STATION,
Expand Down
1 change: 1 addition & 0 deletions modules/eden/flood.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def model(self):
title_list = T("Gauges"),
title_update = T("Edit Gauge"),
title_search = T("Search Gauges"),
title_map = T("Map of Gauges"),
subtitle_create = T("Add New Gauge"),
label_list_button = T("List Gauges"),
label_create_button = ADD_GAUGE,
Expand Down
1 change: 1 addition & 0 deletions modules/eden/hms.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ def model(self):
title_list = T("Hospitals"),
title_update = T("Edit Hospital"),
title_search = T("Find Hospital"),
title_map = T("Map of Hospitals"),
subtitle_create = T("Add New Hospital"),
label_list_button = T("List Hospitals"),
label_create_button = ADD_HOSPITAL,
Expand Down
90 changes: 42 additions & 48 deletions modules/eden/hrm.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def model(self):
T = current.T
db = current.db
s3 = current.response.s3
s3db = current.s3db
settings = current.deployment_settings
controller = current.request.controller

Expand Down Expand Up @@ -250,7 +249,7 @@ def hrm_course_opts():
@ToDo: S3resource-based version to use accessible_realm-based
filtering rather than crude 'this user's org'
"""
ctable = s3db.hrm_course
ctable = current.s3db.hrm_course
organisation_id = current.auth.user.organisation_id
query = (ctable.deleted == False) & \
((ctable.organisation_id == organisation_id) | \
Expand Down Expand Up @@ -284,7 +283,7 @@ def hrm_course_opts():
name="human_resource_search_org",
label=T("Organization"),
field="organisation_id",
represent = s3db.org_organisation_represent,
represent = self.org_organisation_represent,
cols = 3,
),
S3SearchLocationHierarchyWidget(
Expand Down Expand Up @@ -354,7 +353,7 @@ def hrm_course_opts():
name="human_resource_search_org",
label=T("Organization"),
field="organisation_id",
represent = s3db.org_organisation_represent,
represent = self.org_organisation_represent,
cols = 3
),
S3SearchLocationHierarchyWidget(
Expand Down Expand Up @@ -563,29 +562,23 @@ def hrm_human_resource_deduplicate(item):
"""

if item.tablename == "hrm_human_resource":

db = current.db
s3db = current.s3db

hrtable = s3db.hrm_human_resource

data = item.data

person_id = data.person_id
person_id = "person_id" in data and data.person_id
org = "organisation_id" in data and data.organisation_id

# This allows only one HR record per person and organisation,
# if multiple HR records of the same person with the same org
# are desired, then this needs an additional criteria in the
# query (e.g. job title, or type):

query = (hrtable.deleted != True) & \
(hrtable.person_id == person_id)
table = item.table

query = (table.deleted != True) & \
(table.person_id == person_id)
if org:
query = query & \
(hrtable.organisation_id == org)
row = db(query).select(hrtable.id,
limitby=(0, 1)).first()
query = query & (table.organisation_id == org)
row = current.db(query).select(table.id,
limitby=(0, 1)).first()
if row:
item.id = row.id
item.method = item.METHOD.UPDATE
Expand Down Expand Up @@ -846,34 +839,31 @@ def model(self):

# -------------------------------------------------------------------------
@staticmethod
def hrm_job_role_duplicate(job):
def hrm_job_role_duplicate(item):
"""
This callback will be called when importing records
it will look to see if the record being imported is a duplicate.
@param job: An S3ImportJob object which includes all the details
of the record being imported
If the record is a duplicate then it will set the job method to update
Rules for finding a duplicate:
- Look for a record with the same name, ignoring case
"""

if job.tablename == "hrm_job_role":
table = job.table
name = "name" in job.data and job.data.name
org = "organisation_id" in job.data and job.data.organisation_id
if item.tablename == "hrm_job_role":
data = item.data
name = "name" in data and data.name
org = "organisation_id" in data and data.organisation_id

table = item.table
query = (table.name.lower() == name.lower())
if org:
query = query & (table.organisation_id == org)
_duplicate = current.db(query).select(table.id,
limitby=(0, 1)).first()
if _duplicate:
job.id = _duplicate.id
job.data.id = _duplicate.id
job.method = job.METHOD.UPDATE
duplicate = current.db(query).select(table.id,
limitby=(0, 1)).first()
if duplicate:
item.id = duplicate.id
item.method = item.METHOD.UPDATE

# =============================================================================
class S3HRSkillModel(S3Model):
Expand Down Expand Up @@ -1933,9 +1923,10 @@ def hrm_competency_duplicate(job):
"""

if job.tablename == "hrm_competency":
data = job.data
person = "person_id" in data and data.person_id
skill = "skill_id" in data and data.skill_id
table = job.table
person = "person_id" in job.data and job.data.person_id
skill = "skill_id" in job.data and job.data.skill_id
query = (table.person_id == person) & \
(table.skill_id == skill)

Expand Down Expand Up @@ -1963,9 +1954,10 @@ def hrm_certificate_duplicate(job):
"""

if job.tablename == "hrm_certificate":
table = job.table
name = "name" in job.data and job.data.name
data = job.data
name = "name" in data and data.name

table = job.table
query = (table.name.lower() == name.lower())
_duplicate = current.db(query).select(table.id,
limitby=(0, 1)).first()
Expand Down Expand Up @@ -2061,8 +2053,6 @@ def hrm_competency_rating_duplicate(job):
"""

if job.tablename == "hrm_competency_rating":
table = job.table
stable = current.s3db.hrm_skill_type
name = "name" in job.data and job.data.name
skill = False
for cjob in job.components:
Expand All @@ -2072,6 +2062,8 @@ def hrm_competency_rating_duplicate(job):
if skill == False:
return

table = job.table
stable = current.s3db.hrm_skill_type
query = (table.name.lower() == name.lower()) & \
(table.skill_type_id == stable.id) & \
(stable.value.lower() == skill.lower())
Expand Down Expand Up @@ -2099,9 +2091,9 @@ def hrm_course_duplicate(job):
"""

if job.tablename == "hrm_course":
table = job.table
name = "name" in job.data and job.data.name

table = job.table
query = (table.name.lower() == name.lower())
_duplicate = current.db(query).select(table.id,
limitby=(0, 1)).first()
Expand All @@ -2127,9 +2119,9 @@ def hrm_skill_duplicate(job):
"""

if job.tablename == "hrm_skill":
table = job.table
name = "name" in job.data and job.data.name

table = job.table
query = (table.name.lower() == name.lower())
_duplicate = current.db(query).select(table.id,
limitby=(0, 1)).first()
Expand All @@ -2155,9 +2147,9 @@ def hrm_skill_type_duplicate(job):
"""

if job.tablename == "hrm_skill_type":
table = job.table
name = "name" in job.data and job.data.name

table = job.table
query = (table.name.lower() == name.lower())
_duplicate = current.db(query).select(table.id,
limitby=(0, 1)).first()
Expand All @@ -2183,12 +2175,12 @@ def hrm_training_event_duplicate(job):
"""

if job.tablename == "hrm_training_event":
table = job.table
start_date = "start_date" in job.data and job.data.start_date
data = job.data
start_date = "start_date" in data and data.start_date
if not start_date:
return
course_id = "course_id" in job.data and job.data.course_id
site_id = "site_id" in job.data and job.data.site_id
course_id = "course_id" in data and data.course_id
site_id = "site_id" in data and data.site_id
# Need to provide a range of dates as otherwise second differences prevent matches
# - assume that if we have multiple training courses of the same
# type at the same site then they start at least a minute apart
Expand Down Expand Up @@ -2218,6 +2210,7 @@ def hrm_training_event_duplicate(job):
minute = 0
start_end_date = datetime.datetime(year, month, day, hour, minute)

table = job.table
query = (table.course_id == course_id) & \
(table.start_date >= start_start_date) & \
(table.start_date < start_end_date)
Expand Down Expand Up @@ -2247,10 +2240,11 @@ def hrm_training_duplicate(job):
"""

if job.tablename == "hrm_training":
table = job.table
training_event_id = "training_event_id" in job.data and job.data.training_event_id
person_id = "person_id" in job.data and job.data.person_id
data = job.data
training_event_id = "training_event_id" in data and data.training_event_id
person_id = "person_id" in data and data.person_id

table = job.table
query = (table.person_id == person_id) & \
(table.training_event_id == training_event_id)
_duplicate = current.db(query).select(table.id,
Expand Down
1 change: 1 addition & 0 deletions modules/eden/irs.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ def model(self):
title_update = T("Edit Incident Report"),
title_upload = T("Import Incident Reports"),
title_search = T("Search Incident Reports"),
title_map = T("Map of Incident Reports"),
subtitle_create = T("Add New Incident Report"),
label_list_button = T("List Incident Reports"),
label_create_button = ADD_INC_REPORT,
Expand Down
Loading

0 comments on commit bea8d7f

Please sign in to comment.