def edit_resource (form): oldcatguid = get_guid_by_name(form.get('oldcategory')) catguid = get_guid_by_name(form.get('category')) if catguid != oldcatguid: change_resource_category(form.get('id'), oldcatguid, catguid) form['category'] = catguid del form['oldcategory'] if form.get('url'): form['url'] = cleanse_url(form.get('url')) # No new file uploaded if not form.get('filename'): # Did it previously exist? if form.get('oldfilename'): form['filename'] = form.get('oldfilename') # Is there an upload? if form.get('filename') and form.get('contents'): filename = sanitize_file_name(form.get('filename')) form['filename'] = filename open(os.path.join(FILEDIR, filename), 'wb').write(form.get('contents')) # Was there one previously? if form.get('oldfilename'): os.remove(os.path.join(FILEDIR, form.get('oldfilename'))) del form['oldfilename'] try: del form['contents'] except: pass wP(form, os.path.join(REZDIR, form.get('id')))
def add_donor(dtype, dname): fn = D.get(dtype) L = rP(fn) if not L: L = [] if dname not in L: L.append(dname) wP(L, fn)
def add_donor (dtype, dname): fn = D.get(dtype) L = rP(fn) if not L: L = [] if dname not in L: L.append(dname) wP(L, fn)
def delete_member (comm_id, mb_id): mb_map = get_members(comm_id) if mb_id in mb_map.keys(): del mb_map[mb_id] wP(mb_map, os.path.join(DATADIR, comm_id, 'members.map')) order = get_members_order(comm_id) if mb_id in order: del order[order.index(mb_id)] wP(order, os.path.join(DATADIR, comm_id, 'members.order'))
def add_member (comm_id, mb_title, mb_name, mb_email, mb_year): this_id = get_next_member_id(comm_id) members_map = get_members(comm_id) members_map[this_id] = {'title': mb_title, 'name': mb_name, 'email': mb_email, 'year': mb_year} wP( members_map, os.path.join(DATADIR, comm_id, 'members.map') ) members_ord = get_members_order(comm_id) # [] if this_id not in members_ord: members_ord.append(this_id) wP( members_ord, os.path.join(DATADIR, comm_id, 'members.order') ) return this_id
def edit_category (oldname, newname): mapdict = get_rtc_name_map() CATGUID = False for guid in mapdict.keys(): catstring = mapdict[guid] if catstring == oldname: CATGUID = guid if CATGUID: mapdict[CATGUID] = newname wP(mapdict, RTC_MAP_FILE) else: return True # indicates error
def add_category (catname): GUID = str(random.randint(10000000,99999999)) catdict = get_rtc_categories() mapdict = get_rtc_name_map() catnames = mapdict.values() if catname not in catnames: mapdict[GUID] = catname catdict[GUID] = [] wP(mapdict, RTC_MAP_FILE) wP(catdict, RTC_CAT_FILE) else: return True # indicates error
def change_resource_category (rezid, oldcat, newcat=None): """ Don't pass newcat during resource deletion. """ catdict = get_rtc_categories() currentrezlist = catdict.get(oldcat) if rezid in currentrezlist: currentrezlist.remove(rezid) catdict[oldcat] = currentrezlist if newcat: catdict[newcat].append(rezid) wP(catdict, RTC_CAT_FILE)
def save_minutes (form): M, D, Y = form.get('date') # Save data file fobj = form.get('datafile') # existence of file already checked contents = fobj.value fext = os.path.splitext(fobj.filename)[-1] doc_fn = 'acva_minutes_%s_%s_%s%s' % (Y, M, D, fext) open(os.path.join(MINDOC_DIR, doc_fn), 'wb').write(contents) # Save pickle form['datafile'] = doc_fn file_id = str(get_int_from_YMD(Y, M, D)) wP(form, os.path.join(MINS_DIR, file_id))
def save_minutes(form): M, D, Y = form.get('date') # Save data file fobj = form.get('datafile') # existence of file already checked contents = fobj.value fext = os.path.splitext(fobj.filename)[-1] doc_fn = 'acva_minutes_%s_%s_%s%s' % (Y, M, D, fext) open(os.path.join(MINDOC_DIR, doc_fn), 'wb').write(contents) # Save pickle form['datafile'] = doc_fn file_id = str(get_int_from_YMD(Y, M, D)) wP(form, os.path.join(MINS_DIR, file_id))
def save_job (form): if form.get('id'): # edit JOB_ID = form.get('id') else: # new JOB_ID = get_new_job_ID() form['id'] = JOB_ID form['posted'] = time.localtime(time.time()) if form.get('web_link_url'): form['web_link_url'] = cleanse_url(form.get('web_link_url')) M, D, Y = form.get('expires') form['exp_tuple'] = get_tuple_from_YMD(Y, M, D) fullpath = os.path.join(JOBDIR, JOB_ID) wP(form, fullpath)
def add_committee (comm_name): # Create committee directory this_id = get_next_committee_id() newpath = os.path.join(DATADIR, this_id) os.mkdir(newpath) comm_map = get_committees() comm_map[this_id] = {'name': comm_name} wP(comm_map, COMM_MAP) comm_ord = get_committee_order() # [] if this_id not in comm_ord: comm_ord.append(this_id) wP(comm_ord, COMM_ORD) return this_id
def delete_committee (comm_id): """ This does not touch the directory in which the committee members were saved. It merely removes it from the indices. """ comms = get_committees() if comm_id in comms.keys(): del comms[comm_id] wP(comms, COMM_MAP) order = get_committee_order() if comm_id in order: del order[order.index(comm_id)] wP(order, COMM_ORD)
def save_job(form): if form.get('id'): # edit JOB_ID = form.get('id') else: # new JOB_ID = get_new_job_ID() form['id'] = JOB_ID form['posted'] = time.localtime(time.time()) if form.get('web_link_url'): form['web_link_url'] = cleanse_url(form.get('web_link_url')) M, D, Y = form.get('expires') form['exp_tuple'] = get_tuple_from_YMD(Y, M, D) fullpath = os.path.join(JOBDIR, JOB_ID) wP(form, fullpath)
def delete_category (catname): """ Category_Delete.py already checks to make sure there are no resources tied to this category. """ catdict = get_rtc_categories() mapdict = get_rtc_name_map() CATGUID = False for guid in mapdict.keys(): catstring = mapdict[guid] if catstring == catname: CATGUID = guid if CATGUID: del mapdict[CATGUID] del catdict[CATGUID] wP(mapdict, RTC_MAP_FILE) wP(catdict, RTC_CAT_FILE) else: return True # indicates error
def add_resource (form): guid = get_guid_by_name(form.get('category')) form['category'] = guid if form.get('url'): form['url'] = cleanse_url(form.get('url')) if form.get('filename') and form.get('contents'): filename = sanitize_file_name(form.get('filename')) form['filename'] = filename open(os.path.join(FILEDIR, filename), 'wb').write(form.get('contents')) try: del form['contents'] except: pass FILEID = str(random.randint(10000000,99999999)) form['id'] = FILEID wP(form, os.path.join(REZDIR, FILEID)) catdict = get_rtc_categories() catdict[form.get('category')].append(FILEID) wP(catdict, RTC_CAT_FILE)
def updateCommittees(form): FINAL = {} for k in form.keys(): FINAL[k] = {} FINAL[k]['title'], FINAL[k]['name'], FINAL[k]['year'] = form.get(k) wP(FINAL, COMFILE)
def save_residency(form): if not form.get('id'): id = str(uuid.uuid4()) form['id'] = id filepath = os.path.join(REZDIR, form.get('id')) wP(form, filepath)
def reorder_committees (new_order): # Blue Monday wP(new_order, COMM_ORD)
def save_residency (form): if not form.get('id'): id = str(uuid.uuid4()) form['id'] = id filepath = os.path.join(REZDIR, form.get('id')) wP(form, filepath)
def rename_committee (comm_id, new_name): comms = get_committees() comms[comm_id]['name'] = new_name wP(comms, COMM_MAP)
def get_new_job_ID (): newid = rP(JOBCOUNT) nextid = newid +1 wP(nextid, JOBCOUNT) return str(newid)
def reorder_members (comm_id, new_order): # Bizarre Love Triangle MB_ORD = os.path.join(DATADIR, comm_id, 'members.order') wP(new_order, MB_ORD)
def toggle_travel(): flag = rP(TRAVELFLAG) if flag == True: wP(False, TRAVELFLAG) else: wP(True, TRAVELFLAG)
def updateBOD(form): FINAL = {} for k in form.keys(): FINAL[k] = {} FINAL[k]['name'], FINAL[k]['email'], FINAL[k]['year'] = form.get(k) wP(FINAL, BODFILE)
def get_new_job_ID(): newid = rP(JOBCOUNT) nextid = newid + 1 wP(nextid, JOBCOUNT) return str(newid)
def del_donor (dtype, dname): fn = D.get(dtype) L = rP(fn) if dname in L: del L[L.index(dname)] wP(L, fn)
def del_donor(dtype, dname): fn = D.get(dtype) L = rP(fn) if dname in L: del L[L.index(dname)] wP(L, fn)