sahana-s08-de-duplicator team mailing list archive
-
sahana-s08-de-duplicator team
-
Mailing list archive
-
Message #00014
Re: code for people : Array
i will update on this once working
On Wed, Nov 24, 2010 at 6:42 PM, Akilandeswari Ramakrishnan <
aramakr@xxxxxxxx> wrote:
> Hi Pradnya,
>
> I added this in the pr.py module. As of now, I have collected the values
> of one record in strlist array..
> u can test by passing the same array twice.
>
> jwalgo(strlist,strlist)
>
> *Code for the menu:*
>
> def shn_menu():
> response.menu_options = [
> [T("Home"), False, URL(r=request, f="index")],
> [T("Search for a Person"), False, URL(r=request, f="person",
> args="search_simple")],
> [T("Persons"), False, URL(r=request, f="person"), [
> [T("List"), False, URL(r=request, f="person")],
> [T("Add"), False, URL(r=request, f="person", args="create")],
> ]],
> [T("Groups"), False, URL(r=request, f="group"), [
> [T("List"), False, URL(r=request, f="group")],
> [T("Add"), False, URL(r=request, f="group", args="create")],
> ]],
> #S08 - De-duplicator
> * [T("De-duplicator"), False, URL(r=request,
> f="people_duplicates")]]*
>
> *defined a function:*
>
>
> #-------------------------------------------------------------------------------------------------------
> #-----------------------------S08 - People
> deduplictor-------------------------------------------------
>
> #-------------------------------------------------------------------------------------------------------
>
> def people_duplicates():
> """
> Handle De-duplication of People
> """
> ''' Duplicate identification is done based on the 'first name only'.
> * This routine takes the first name from the 'pr_person' table
> * Each retrieved first name is passed to soundex algorithm
> * The soundex value is stored in the Table
> * Soundex value of each record is compared against every other
> record in the table
> * Result is shown along with the dd
> '''
>
> persons=db().select (db.pr_person.pe_label,
> db.pr_person.missing,
> db.pr_person.first_name,
> db.pr_person.middle_name,
> db.pr_person.last_name,
> db.pr_person.preferred_name,
> db.pr_person.local_name,
> db.pr_person.age_group,
> db.pr_person.gender,
> db.pr_person.date_of_birth,
> db.pr_person.nationality,
> db.pr_person.country,
> db.pr_person.religion,
> db.pr_person.marital_status,
> db.pr_person.occupation,
> db.pr_person.tags,
> db.pr_person.comments
> )
> for person in persons:
> strlist =[]
> strlist.append(person.pe_label)
> strlist.append(person.missing)
> strlist.append(person.first_name)
> strlist.append(person.middle_name)
> strlist.append(person.last_name)
> strlist.append(person.preferred_name)
> strlist.append(person.local_name)
> strlist.append(person.age_group)
> strlist.append(person.gender)
> strlist.append(person.date_of_birth)
> strlist.append(person.nationality)
> strlist.append(person.country)
> strlist.append(person.religion)
> strlist.append(person.marital_status)
> strlist.append(person.occupation)
> strlist.append(person.tags)
> strlist.append(person.comments)
> print strlist
>
>
> # S08 No authorization
> if deployment_settings.get_security_map() and not
> shn_has_role("MapAdmin"):
> unauthorised()
>
> def delete_people(old, new):
> # Find all tables which link to the People table <pr_person>
> # @ToDo Replace with db.gis_location._referenced_by
> tables = shn_table_links("pr_person")
>
> for table in tables:
> for count in range(len(tables[table])):
> field = tables[str(db[table])][count]
> query = db[table][field] == old
> db(query).update(**{field:XXX})
>
> # Remove the record
> db(db.pr_person.id == old).update(deleted=True)
>
> return
>
> def open_btn(id):
> return A(T("Load Details"), _id=id, _href=URL(r=request,
> f="person"), _class="action-btn", _target="_blank")
>
> def links_btn(id):
> return A(T("Linked Records"), _id=id, _href=URL(r=request,
> f="location_links"), _class="action-btn", _target="_blank")
>
> # Unused: we do all filtering client-side using AJAX
> filter = request.vars.get("filter", None)
>
> #repr_select = lambda l: len(l.name) > 48 and "%s..." % l.name[:44] or
> l.name
> repr_select = lambda l: l.first_name # and "%s (%s)" % (l.first_name,
> response.s3.gis.location_hierarchy[l.level]) or l.first_name
>
> if filter:
> requires = IS_ONE_OF(db, "pr_person.id", repr_select,
> filterby="first_name", filter_opts=(filter,),
> orderby="pr_person.first_name", sort=True)
> else:
> requires = IS_ONE_OF(db, "pr_person.id", repr_select,
> orderby="pr_person.first_name", sort=True, zero=T("Select a Person"))
>
> table = db.pr_person
> form = SQLFORM.factory(
> Field("old", table, requires=requires, label =
> SPAN(B(T("Old")), " (" + T("To delete") + ")"),
> comment=DIV(links_btn("linkbtn_old"), open_btn("btn_old"))),
> Field("new", table, requires=requires, label =
> B(T("New")), comment=DIV(links_btn("linkbtn_new"), open_btn("btn_new"))),
> formstyle = s3_formstyle
> )
>
> form.custom.submit.attributes['_value'] = T("Delete Old")
>
> if form.accepts(request.vars, session):
> _vars = form.vars
>
> if not _vars.old == _vars.new:
> # Take Action
> delete_location(_vars.old, _vars.new)
> session.confirmation = T("People De-duplicated")
> redirect(URL(r=request))
> else:
> response.error = T("Person should be different!")
>
> elif form.errors:
> response.error = T("Need to select 2 Persons")
>
> return dict(form=form)
>
> #---------------------------------------------------------------------------------------------------------------------------------------
>
>
References