Пример #1
0
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)
Пример #2
0
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)
Пример #3
0
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)
Пример #4
0
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)
Пример #5
0
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)
Пример #6
0
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)
Пример #7
0
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)
Пример #8
0
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)
Пример #9
0
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)
Пример #10
0
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)
Пример #11
0
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))
Пример #12
0
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
Пример #13
0
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))
Пример #14
0
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)
Пример #15
0
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)
Пример #16
0
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')
Пример #17
0
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')
Пример #18
0
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)
Пример #19
0
    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>')
Пример #20
0
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)
Пример #21
0
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)
Пример #22
0
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)
Пример #23
0
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)
Пример #24
0
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))
Пример #25
0
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')
Пример #26
0
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))
Пример #27
0
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')
Пример #28
0
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
Пример #29
0
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
Пример #30
0
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)
Пример #31
0
def unregister (regfile, filename):
    r = rP(regfile)
    if filename in r.keys():
        del r[filename]
    wP(r, regfile)
Пример #32
0
def register (regfile, filename, title):
    r = rP(regfile)
    r[filename] = title
    wP(r, regfile)
Пример #33
0
def remove_doc_description (filename):
    p = rP(DESC_FILE)
    if filename in p.keys():
        del p[filename]
        wP(p, DESC_FILE)
Пример #34
0
def unregister(regfile, filename):
    r = rP(regfile)
    if filename in r.keys():
        del r[filename]
    wP(r, regfile)
Пример #35
0
def register(regfile, filename, title):
    r = rP(regfile)
    r[filename] = title
    wP(r, regfile)
Пример #36
0
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)
Пример #37
0
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)
Пример #38
0
def archive_doc (filename):
    filename_list = get_archived()
    if filename not in filename_list:
        filename_list.append(filename)
    wP(filename_list, ARCHIVED_FILE)
Пример #39
0
def activate_doc (filename):
    filename_list = get_archived()
    new_list = rm_fr_list (filename_list, filename)
    wP(new_list, ARCHIVED_FILE)
Пример #40
0
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)
Пример #41
0
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)
Пример #42
0
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))
Пример #43
0
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))
Пример #44
0
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)