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 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 get_user_events (username): evs = [] rg = rP(EVENT_REGISTER) if rg.has_key(username): if rg.get(username): evs = rg.get(username) return evs
def get_annual_news(): AN = [] all = glob.glob(os.path.join(AMTGDIR, '*')) all.sort() all.reverse() for x in all: AN.append(rP(os.path.join(x))) return AN
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 get_action_items(): AN = [] all = glob.glob(os.path.join(ACTIDIR, '*')) all.sort() all.reverse() for x in all: AN.append(rP(os.path.join(x))) return AN
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 get_event_info (id): pick = rP(os.path.join(EVENTDIR, id)) t = time.gmtime(int(id)) pick['dayofweek'] = time.strftime('%a', t) pick['display_date'] = time.strftime('%A, %B %d, %Y', t) pick['month'] = time.strftime('%B', t) pick['day'] = str(t[2]) pick['year'] = str(t[0]) return pick
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 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 get_news_by_year (year=None): if not year: year = now_year() MATCH = [] all = glob.glob(os.path.join(NEWSDIR, '*')) all.sort() all.reverse() for nipath in all: niname = os.path.basename(nipath) niyear = str(time.localtime(int(niname))[0]) if niyear == year: MATCH.append(rP(os.path.join(nipath))) return MATCH
def get_news_by_year(year=None): if not year: year = now_year() MATCH = [] all = glob.glob(os.path.join(NEWSDIR, '*')) all.sort() all.reverse() for nipath in all: niname = os.path.basename(nipath) niyear = str(time.localtime(int(niname))[0]) if niyear == year: MATCH.append(rP(os.path.join(nipath))) return MATCH
def get_user_acct(username, with_pass=False): if username: username = username.lower() a = os.path.join(ACCTDIR, username) if os.path.exists(a): b = rP(a) if not with_pass: if b.has_key('password'): del b['password'] return b else: return {} else: return {}
def get_user_acct (username, with_pass=False): if username: username = username.lower() a = os.path.join(ACCTDIR, username) if os.path.exists(a): b = rP(a) if not with_pass: if b.has_key('password'): del b['password'] return b else: return {} else: return {}
def fstates (): allaccts = glob.glob(os.path.join(ADIR, '*')) for fpath in allaccts: p = rP(fpath) ct = p.get('country') st = p.get('state') if ct == 'USA': if st not in USA_STATES_LOOKUP.keys(): print '%s (USA) state is %s' % (os.path.basename(fpath), st) if ct == 'Canada': if st not in CAN_STATES_LOOKUP.keys(): print '%s (CAN) state is %s' % (os.path.basename(fpath), st) if ct == 'Mexico': if st not in MEX_STATES_LOOKUP.keys(): print '%s (MEX) state is %s' % (os.path.basename(fpath), st)
def get_users (utype): if utype in ['diplomate', 'diplomates', 'd']: REG = DIPL_REGISTER elif utype in ['resident', 'residents', 'r']: REG = RESD_REGISTER elif utype in ['emeritus', 'e']: REG = EMER_REGISTER elif utype in ['honorary', 'h']: REG = HONO_REGISTER elif utype in ['memoriam', 'm']: REG = MEMO_REGISTER else: return {} L = rP(REG) FINAL = {} for username in L: upick = get_user_acct(username) upick['username'] = username uuid = '%s_%s_%s' % (upick.get('sn'), upick.get('fn'), username) FINAL[uuid] = upick return FINAL
def get_users(utype): if utype in ['diplomate', 'diplomates', 'd']: REG = DIPL_REGISTER elif utype in ['resident', 'residents', 'r']: REG = RESD_REGISTER elif utype in ['emeritus', 'e']: REG = EMER_REGISTER elif utype in ['honorary', 'h']: REG = HONO_REGISTER elif utype in ['memoriam', 'm']: REG = MEMO_REGISTER else: return {} L = rP(REG) FINAL = {} for username in L: upick = get_user_acct(username) upick['username'] = username uuid = '%s_%s_%s' % (upick.get('sn'), upick.get('fn'), username) FINAL[uuid] = upick return FINAL
def register(regfile, filename, title): r = rP(regfile) r[filename] = title wP(r, regfile)
def get_constitution_info(): return rP(DOC_CONST_INFO)
def get_journal_access (): return rP(JOURNALIST)
def get_all_possible_categories (): return rP(MASTER_CATEGORY_LIST)
def unregister (regfile, filename): r = rP(regfile) if filename in r.keys(): del r[filename] wP(r, regfile)
def get_constitution_info (): return rP(DOC_CONST_INFO)
def get_categories (): return rP(CATEGORIES_FILE)
def get_access (): return rP(ACCESS_FILE)
def get_titles (): return rP(TITLES_FILE)
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 is_email_registered (email): if email: email = email.lower() d = rP(EMAIL_REGISTER) return email in d.keys()
def get_descriptions (): return rP(DESC_FILE)
def is_email_registered(email): if email: email = email.lower() d = rP(EMAIL_REGISTER) return email in d.keys()
def unregister(regfile, filename): r = rP(regfile) if filename in r.keys(): del r[filename] wP(r, regfile)
def get_doc_dict(dtype, dcat=None): pd = get_doc_dir(dtype, dcat) if pd: return (os.path.basename(pd), rP(os.path.join(pd, '.info')))
def get_news_item (id): for ddir in (NEWSDIR, AMTGDIR, ACTIDIR): p = os.path.join(ddir, id) if os.path.exists(p): return rP(p)
def register (regfile, filename, title): r = rP(regfile) r[filename] = title wP(r, regfile)
def get_news_item(id): for ddir in (NEWSDIR, AMTGDIR, ACTIDIR): p = os.path.join(ddir, id) if os.path.exists(p): return rP(p)
def get_doc_dict (dtype, dcat=None): pd = get_doc_dir(dtype, dcat) if pd: return ( os.path.basename(pd), rP(os.path.join(pd, '.info')) )
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 get_archive_list (doctype, category): dd = get_doc_dir(doctype, category) archfile = os.path.join(dd, '.archivelist') return rP(archfile)
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)