def create_item(rdb): #Get the item data from the form: event_id = request.POST.get('event_id','').strip() task_id = request.POST.get('task_id','').strip() iname = request.POST.get('item_name','').strip() icost = request.POST.get('item_cost','').strip() inotes = request.POST.get('item_notes','').strip() istatus = request.POST.get('item_status','').strip() #get current user info user = request.get_cookie('account', secret='pass') user_id = str(int(rdb.zscore('accounts:usernames', user))) #Create new item_id item_id = int(rdb.hget('task:' + user_id + ':' + event_id + ':' + task_id, 'numitems')) + 1 item_key = 'item:%s:%s:%s' % (user_id, event_id, task_id, item_id) #Try to add the new item to the database. try: rdb.hmset(item_key, { 'iname' : iname, 'icost' : icost, 'inotes' : inotes, 'istatus' : constants.getStatusIntFromStr(istatus) }) rdb.hset('task:' + user_id + ':' + event_id + ':' + task_id, 'numitems', item_id) except: return None return (user_id, event_id)
def create_event(rdb): try: #get incoming fields etype = request.POST.get('visibility','').strip() estatus = request.POST.get('status','').strip() eduedate = request.POST.get('datepicker','').strip() eventdesc = request.POST.get('event_description','').strip() ename = request.POST.get('event_name','').strip() #print ename, eventdesc, eduedate, etype #get current user info user = request.get_cookie('account', secret='pass') user_id = str(int(rdb.zscore('accounts:usernames', user))) #print user, user_id #Increment number of user's events, get new value: event_id = str(rdb.hincrby('account:' + user_id, 'numevents', 1)) #print event_id #Add event info to db rdb.hmset('event:' + user_id + ':' + event_id, { 'ename' : ename, 'eduedate' : eduedate, 'eventdesc' : eventdesc, 'numinvited' : 0, 'responded' : 0, 'numattending' : 1, 'estatus' : constants.getStatusIntFromStr(estatus), 'etype' : constants.getEventTypeFromStr(etype), 'numtasks' : 0 }) #add event to its respective lists if constants.getEventTypeFromStr(etype) == constants.EVENT_TYPE_PUBLIC: #add event to public list rdb.sadd('events:public', 'event:' + user_id + ':' + event_id) #add event to user's public list rdb.sadd('account:' + user_id + ':public', 'event:' + user_id + ':' + event_id) else: #add even to user's private list rdb.sadd('account:' + user_id + ':private', 'event:' + user_id + ':' + event_id) #add owner to admin list for this event rdb.sadd('event:' + user_id + ':' + event_id + ':admins', user_id) return (user_id, event_id) except: return None
def edit_task(rdb, user_id, event_id, task_id): try: #get incoming fields tname = request.POST.get('task_name','').strip() tinfo = request.POST.get('task_info','').strip() tcost = request.POST.get('task_cost','').strip() tstatus = request.POST.get('status','').strip() task_key = 'task:%s:%s:%s' % (user_id, event_id, task_id) rdb.hmset(task_key, { 'tname' : tname, 'tinfo' : tinfo, 'tcost' : tcost, 'tstatus' : constants.getStatusIntFromStr(tstatus) }) return (user_id, event_id, task_id) except: return None