def cache_role(username, role, action): if username: username = username.lower() REG = '' if role == 'resident': REG = RESD_REGISTER if role == 'diplomate': REG = DIPL_REGISTER if role == 'emeritus': REG = EMER_REGISTER if role == 'honorary': REG = HONO_REGISTER if role == 'memoriam': REG = MEMO_REGISTER if REG: L = rP(REG) if not L: L = [] if action == 'reg': if username not in L: L.append(username) wP(L, REG) if action == 'dereg': if username in L: del L[L.index(username)] wP(L, REG)
def cache_role (username, role, action): if username: username = username.lower() REG = '' if role == 'resident': REG = RESD_REGISTER if role == 'diplomate': REG = DIPL_REGISTER if role == 'emeritus': REG = EMER_REGISTER if role == 'honorary': REG = HONO_REGISTER if role == 'memoriam': REG = MEMO_REGISTER if REG: L = rP(REG) if not L: L = [] if action == 'reg': if username not in L: L.append(username) wP(L, REG) if action == 'dereg': if username in L: del L[L.index(username)] wP(L, REG)
def deregister_event (username, event_id): pick = rP(EVENT_REGISTER) elist = pick.get(username, []) while event_id in elist: del elist[elist.index(event_id)] pick[username] = elist wP(pick, EVENT_REGISTER)
def register_email_addr(email, userid): # duplicate email addresses should have already been checked if email: email = email.lower() d = rP(EMAIL_REGISTER) if not d.has_key(email): d[email] = userid wP(d, EMAIL_REGISTER)
def reset_password (username): if username: username = username.lower() ui = get_user_acct(username, with_pass=True) newpass = generate_random() ui['password'] = hash_string(newpass) wP(ui, os.path.join(ACCTDIR, username)) send_reset_password(ui.get('email'), newpass)
def reset_password(username): if username: username = username.lower() ui = get_user_acct(username, with_pass=True) newpass = generate_random() ui['password'] = hash_string(newpass) wP(ui, os.path.join(ACCTDIR, username)) send_reset_password(ui.get('email'), newpass)
def register_email_addr (email, userid): # duplicate email addresses should have already been checked if email: email = email.lower() d = rP(EMAIL_REGISTER) if not d.has_key(email): d[email] = userid wP(d, EMAIL_REGISTER)
def save_doc_access (filename, role): # One role at a time, please. # {role: [list,of,filenames], other: [], } p = rP(ACCESS_FILE) file_list = p.get(role, []) if filename not in file_list: file_list.append(filename) p[role] = file_list wP(p, ACCESS_FILE)
def save_doc_to_category (filename, category): # One category at a time, please. # {categoryname: [list,of,filenames], other: [], } p = rP(CATEGORIES_FILE) file_list = p.get(category, []) if filename not in file_list: file_list.append(filename) p[category] = file_list wP(p, CATEGORIES_FILE)
def reorder_master_category_list (catname, direction): existing_order = get_all_possible_categories() existing_index = existing_order.index(catname) popped = existing_order.pop(existing_index) if direction == 'up': new_index = existing_index - 1 else: new_index = existing_index + 1 existing_order.insert(new_index, popped) wP(existing_order, MASTER_CATEGORY_LIST)
def change_for_hire_status(username, form): if username: username = username.lower() ui = get_user_acct(username, with_pass=True) for param in ['show_for_hire', 'for_hire_areas', 'for_hire_services']: ui[param] = form.get(param) if form.get('for_hire_url'): ui['for_hire_url'] = cleanse_url(form.get('for_hire_url')) else: ui['for_hire_url'] = '' wP(ui, os.path.join(ACCTDIR, username))
def save_event (form): event_url = form.get('link_url') if event_url: event_url = cleanse_url(event_url) form['link_url'] = event_url m, d, y = form.get('date') event_id = create_event_id(y, m, d) filepath = os.path.join(EVENTDIR, event_id) wP(form, filepath) register_event(form.get('username'), event_id) return event_id
def change_for_hire_status (username, form): if username: username = username.lower() ui = get_user_acct(username, with_pass=True) for param in ['show_for_hire', 'for_hire_areas', 'for_hire_services']: ui[param] = form.get(param) if form.get('for_hire_url'): ui['for_hire_url'] = cleanse_url(form.get('for_hire_url')) else: ui['for_hire_url'] = '' wP(ui, os.path.join(ACCTDIR, username))
def edit_master_category (newcatname, oldcatname=None): p = get_all_possible_categories() or [] metadatapick = get_categories() if oldcatname: p = rm_fr_list(p, oldcatname) if oldcatname in metadatapick.keys(): metadatapick[newcatname] = metadatapick[oldcatname] del metadatapick[oldcatname] wP(metadatapick, CATEGORIES_FILE) if newcatname not in p: p.append(newcatname) wP(p, MASTER_CATEGORY_LIST)
def save_constitution(form): try: M, D, Y = form.get('date') except TypeError: M, D, Y, = form.get('date').split('/') # Save data file fobj = form.get('datafile') # existence of file already checked contents, filename = fobj.value, fobj.filename filename = sanitize_file_name(filename) open(os.path.join(DOC_CONST_DIR, filename), 'wb').write(contents) form['datafile'] = filename wP(form, DOC_CONST_INFO)
def save_manual_account(form): new_userid = get_new_user_id(form.get('fn'), form.get('sn')) destination = os.path.join(ACCTDIR, new_userid) roles = form.get('roles', []) # Force List if type(roles) is ListType: form['roles'] = roles elif type(roles) is StringType: form['roles'] = [roles] wP(form, destination) for role in form['roles']: cache_role(new_userid, role, 'reg')
def save_manual_account (form): new_userid = get_new_user_id(form.get('fn'), form.get('sn')) destination = os.path.join(ACCTDIR, new_userid) roles = form.get('roles', []) # Force List if type(roles) is ListType: form['roles'] = roles elif type(roles) is StringType: form['roles'] = [roles] wP(form, destination) for role in form['roles']: cache_role(new_userid, role, 'reg')
def archive_document (doctype, category, filename): # This adds if not in list, removes if in list. Toggle status, basically. dd = get_doc_dir(doctype, category) archfile = os.path.join(dd, '.archivelist') archivelist = rP(archfile) if not archivelist: archivelist = [] if filename not in archivelist: archivelist.append(filename) else: del archivelist[archivelist.index(filename)] wP(archivelist, archfile)
def writeContent(self): wr = self.writeln qs = self.request().fields() ISA = is_site_admin(self.request()) wr('<h1>%s</h1>' % (self.title())) linksdict = rP(LINKFILE) if self.request()._environ.get('REQUEST_METHOD') == 'POST': form = qs u = form.get('url') if not u.startswith('http://'): form['url'] = 'http://' + u linkid = str(int(time.time())) linksdict[linkid] = form wP(linksdict, LINKFILE) self.response().sendRedirect("Links") else: if qs.get('delete_link_id'): timeid = qs['delete_link_id'] del linksdict[qs.get('delete_link_id')] wP(linksdict, LINKFILE) self.response().sendRedirect("Links") else: # display if ISA: wr('<P><table>') wr('<form action="Links" method="POST"><tr><td colspan="2"><b>Add Link</b><br>') wr('<tr><td>Title to display:<td><input type="text" name="title" value=""><br>') wr('<tr><td>Web Address:<td><input type="text" name="url" value=""><br>') wr('<tr><td colspan="2"><input type="submit" value="Add Link">') wr('</table></form>') wr('</P>') if linksdict: titlesandids = [] for timeid in linksdict.keys(): d = linksdict[timeid] t = (d.get('title'), timeid) titlesandids.append(t) titlesandids.sort() for title, timeid in titlesandids: url = linksdict[timeid].get('url') wr('<P><a href="%s">%s</a>' % (url, title)) if ISA: wr('<a href="Links?delete_link_id=%s"><img src="/g/delete.png" alt="delete" width="17" height="17" border="0" /></a>' % (timeid)) wr('</P>') else: wr('<P>Sorry, there are no links right now.</P>')
def save_news (form): dirtosaveto = NEWSDIR if form.get('annualnews') == 'true': dirtosaveto = AMTGDIR del form['annualnews'] if form.get('actionitem') == 'true': dirtosaveto = ACTIDIR del form['actionitem'] if not form.get('id'): form['id'] = get_id() form['added'] = time.strftime('%d %b %Y', time.localtime(int(form['id']))) filepath = os.path.join(dirtosaveto, form['id']) wP(form, filepath)
def save_news(form): dirtosaveto = NEWSDIR if form.get('annualnews') == 'true': dirtosaveto = AMTGDIR del form['annualnews'] if form.get('actionitem') == 'true': dirtosaveto = ACTIDIR del form['actionitem'] if not form.get('id'): form['id'] = get_id() form['added'] = time.strftime('%d %b %Y', time.localtime(int(form['id']))) filepath = os.path.join(dirtosaveto, form['id']) wP(form, filepath)
def save_constitution (form): # try: # M, D, Y = form.get('date') # except TypeError: # M, D, Y, = form.get('date').split('/') M, D, Y, = form.get('date').split('/') # Save data file fobj = form.get('datafile') # existence of file already checked contents, filename = fobj.value, fobj.filename filename = sanitize_file_name(filename) open(os.path.join(DOC_CONST_DIR, filename), 'wb').write(contents) form['datafile'] = filename wP(form, DOC_CONST_INFO)
def set_journal_access (form): """ form is {username: yes|no} """ accesslist = get_journal_access() if not accesslist: accesslist = [] for username in form.keys(): if form.get(username) == 'yes': if username not in accesslist: accesslist.append(username) else: if username in accesslist: del accesslist[accesslist.index(username)] wP(accesslist, JOURNALIST)
def save_user_info (username, form): if username: username = username.lower() ui = get_user_acct(username, with_pass=True) # Is user changing email address? if form.get('email') != form.get('original_email'): unregister_email_addr(username) register_email_addr (form.get('email'), username) # Remove unwanted form fields. cruft = ['form_hash', 'form_username', 'original_email'] for c in cruft: if form.has_key(c): del form[c] # Update & Save for k in form.keys(): ui[k] = form[k] wP(ui, os.path.join(ACCTDIR, username))
def save_user_roles(username, roles): if username: username = username.lower() ui = get_user_acct(username, with_pass=True) if type(roles) is ListType: ui['roles'] = roles elif type(roles) is StringType: ui['roles'] = [roles] wP(ui, os.path.join(ACCTDIR, username)) # cache role # for x in ['diplomate', 'resident']: for x in ALL_ROLES: if x != 'admin': if x in ui['roles']: cache_role(username, x, 'reg') else: cache_role(username, x, 'dereg')
def save_user_info(username, form): if username: username = username.lower() ui = get_user_acct(username, with_pass=True) # Is user changing email address? if form.get('email') != form.get('original_email'): unregister_email_addr(username) register_email_addr(form.get('email'), username) # Remove unwanted form fields. cruft = ['form_hash', 'form_username', 'original_email'] for c in cruft: if form.has_key(c): del form[c] # Update & Save for k in form.keys(): ui[k] = form[k] wP(ui, os.path.join(ACCTDIR, username))
def save_user_roles(username, roles): if username: username = username.lower() ui = get_user_acct(username, with_pass=True) if type(roles) is ListType: ui['roles'] = roles elif type(roles) is StringType: ui['roles'] = [roles] wP(ui, os.path.join(ACCTDIR, username)) # cache role # for x in ['diplomate', 'resident']: for x in ALL_ROLES: if x != 'admin': if x in ui['roles']: cache_role (username, x, 'reg') else: cache_role (username, x, 'dereg')
def save_registration (form): # required fields & matching passwords already checked form['roles'] = [] if form.get('hc') == HARV_DIPL: form['roles'].append('diplomate') MAINROLE = 'diplomate' elif form.get('hc') == HARV_RESD: form['roles'].append('resident') MAINROLE = 'resident' form['password'] = hash_string(form.get('pw1')) for a in ['x', 'y', 'hc', 'pw1', 'pw2']: if form.has_key(a): del form[a] form['vcode'] = generate_random() new_userid = get_new_user_id(form.get('fn'), form.get('sn')) destination = os.path.join(ACCTDIR, new_userid) wP(form, destination) # cache role cache_role (new_userid, MAINROLE, 'reg') # duplicate email addresses should have already been checked register_email_addr(form.get('email'), new_userid) send_registration_confirm(form.get('email'), new_userid) return new_userid
def save_registration(form): # required fields & matching passwords already checked form['roles'] = [] if form.get('hc') == HARV_DIPL: form['roles'].append('diplomate') MAINROLE = 'diplomate' elif form.get('hc') == HARV_RESD: form['roles'].append('resident') MAINROLE = 'resident' form['password'] = hash_string(form.get('pw1')) for a in ['x', 'y', 'hc', 'pw1', 'pw2']: if form.has_key(a): del form[a] form['vcode'] = generate_random() new_userid = get_new_user_id(form.get('fn'), form.get('sn')) destination = os.path.join(ACCTDIR, new_userid) wP(form, destination) # cache role cache_role(new_userid, MAINROLE, 'reg') # duplicate email addresses should have already been checked register_email_addr(form.get('email'), new_userid) send_registration_confirm(form.get('email'), new_userid) return new_userid
def unregister_email_addr(userid): d = rP(EMAIL_REGISTER) for k in d.keys(): if d[k] == userid: del d[k] wP(d, EMAIL_REGISTER)
def unregister (regfile, filename): r = rP(regfile) if filename in r.keys(): del r[filename] wP(r, regfile)
def register (regfile, filename, title): r = rP(regfile) r[filename] = title wP(r, regfile)
def remove_doc_description (filename): p = rP(DESC_FILE) if filename in p.keys(): del p[filename] wP(p, DESC_FILE)
def unregister(regfile, filename): r = rP(regfile) if filename in r.keys(): del r[filename] wP(r, regfile)
def register(regfile, filename, title): r = rP(regfile) r[filename] = title wP(r, regfile)
def remove_doc_from_category (filename, category): p = rP(CATEGORIES_FILE) file_list = p.get(category, []) new_list = rm_fr_list(file_list, filename) p[category] = new_list wP(p, CATEGORIES_FILE)
def remove_doc_access (filename, role): p = rP(ACCESS_FILE) file_list = p.get(role, []) new_list = rm_fr_list(file_list, filename) p[role] = new_list wP(p, ACCESS_FILE)
def archive_doc (filename): filename_list = get_archived() if filename not in filename_list: filename_list.append(filename) wP(filename_list, ARCHIVED_FILE)
def activate_doc (filename): filename_list = get_archived() new_list = rm_fr_list (filename_list, filename) wP(new_list, ARCHIVED_FILE)
def remove_master_category (catname): # Make sure you can't remove category that's not empty yet! p = get_all_possible_categories() if is_category_empty(catname): p = rm_fr_list(p, catname) wP(p, MASTER_CATEGORY_LIST)
def register_event (username, event_id): pick = rP(EVENT_REGISTER) if not pick.has_key(username): pick[username] = [] pick[username].append(event_id) wP(pick, EVENT_REGISTER)
def change_password(username, newpass): if username: username = username.lower() ui = get_user_acct(username, with_pass=True) ui['password'] = hash_string(newpass) wP(ui, os.path.join(ACCTDIR, username))
def change_password (username, newpass): if username: username = username.lower() ui = get_user_acct(username, with_pass=True) ui['password'] = hash_string(newpass) wP(ui, os.path.join(ACCTDIR, username))
def unregister_email_addr (userid): d = rP(EMAIL_REGISTER) for k in d.keys(): if d[k] == userid: del d[k] wP(d, EMAIL_REGISTER)