def get(self): # req_json = json.loads(self.request.body) # expense_name = req_json[IDENTIFIER_EXPENSE_NAME] expense_name = self.request.get(IDENTIFIER_EXPENSE_NAME) # user_email = req_json[IDENTIFIER_USER_EMAIL] user_email = self.request.get(IDENTIFIER_USER_EMAIL) # new_sharer_email = req_json[IDENTIFIER_NEW_EMAIL] new_sharer_email = self.request.get(IDENTIFIER_NEW_EMAIL) target_expense = None expense_lst = Expense.query(Expense.expense_name == expense_name) for expense in expense_lst: if user_email in expense.user_email_lst: target_expense = expense break if target_expense == None: response = {} response[ 'error'] = 'the expense: ' + expense_name + ' has not been created' return self.respond(**response) if not new_sharer_email in target_expense.user_email_lst: target_expense.user_email_lst.insert(0, new_sharer_email) target_expense.put() self.respond(expense_id=target_expense.expense_id, new_user=new_sharer_email, status="Success")
def get(self): apt_name = self.request.get(IDENTIFIER_APT_NAME) user_email = self.request.get(IDENTIFIER_USER_EMAIL) apt_lst = Apartment.query(Apartment.apt_name == apt_name).fetch() cur_apt = None for apt in apt_lst: if user_email in apt.user_email_lst: cur_apt = apt if cur_apt == None: response = {} response[ 'error'] = 'the apt: ' + apt_name + ' is not available for user: ' + user_email return self.respond(**response) for expense_id in cur_apt.expense_id_lst: expense_lst = Expense.query( Expense.expense_id == expense_id).fetch() if len(expense_lst) > 0: expense = expense_lst[0] if not expense.is_paid: expense.checkout() cur_apt.total_cost += expense.total_cost cur_apt.put() self.respond(status="Success")
def get(self): cover_url = None # if IDENTIFIER_ITEM_PHOTO in req_json: # cover_url = req_json[IDENTIFIER_ITEM_PHOTO] item_id = uuid.uuid4() # req_json = json.loads(self.request.body) # item_name = req_json[IDENTIFIER_ITEM_NAME] item_name = self.request.get(IDENTIFIER_ITEM_NAME) # expense_name = req_json[IDENTIFIER_EXPENSE_NAME] expense_name = self.request.get(IDENTIFIER_EXPENSE_NAME) # buyer_email = req_json[IDENTIFIER_BUYER_EMAIL] buyer_email = self.request.get(IDENTIFIER_BUYER_EMAIL) # sharer_email_lst = req_json[IDENTIFIER_SHARER_LIST] sharer_emails = self.request.get(IDENTIFIER_SHARER_LIST) sharer_email_lst = sharer_emails.split(",") expense_lst = Expense.query(Expense.expense_name == expense_name) expense_id = None # total_cost = float(req_json[IDENTIFIER_TOTAL_COST]) cost = self.request.get(IDENTIFIER_TOTAL_COST) total_cost = float(cost) target_expense = None for expense in expense_lst: if buyer_email in expense.user_email_lst: expense_id = expense.expense_id target_expense = expense break if expense_id == None: response = {} response['error'] = 'the buyer email: ' + buyer_email + ' is not valid for this expense/apartment' return self.respond(**response) new_item = Item(item_id = str(item_id), item_name = item_name, cover_url = cover_url, expense_id = expense_id, buyer_email = buyer_email, sharer_email_lst = sharer_email_lst, total_cost = total_cost ) new_item.put() target_expense.item_id_lst.insert(0, str(item_id)) target_expense.put() self.respond(item_id_id = str(item_id), status="Success")
def get(self): cover_url = None # if IDENTIFIER_ITEM_PHOTO in req_json: # cover_url = req_json[IDENTIFIER_ITEM_PHOTO] item_id = uuid.uuid4() # req_json = json.loads(self.request.body) # item_name = req_json[IDENTIFIER_ITEM_NAME] item_name = self.request.get(IDENTIFIER_ITEM_NAME) # expense_name = req_json[IDENTIFIER_EXPENSE_NAME] expense_name = self.request.get(IDENTIFIER_EXPENSE_NAME) # buyer_email = req_json[IDENTIFIER_BUYER_EMAIL] buyer_email = self.request.get(IDENTIFIER_BUYER_EMAIL) # sharer_email_lst = req_json[IDENTIFIER_SHARER_LIST] sharer_emails = self.request.get(IDENTIFIER_SHARER_LIST) sharer_email_lst = sharer_emails.split(",") expense_lst = Expense.query(Expense.expense_name == expense_name) expense_id = None # total_cost = float(req_json[IDENTIFIER_TOTAL_COST]) cost = self.request.get(IDENTIFIER_TOTAL_COST) total_cost = float(cost) target_expense = None for expense in expense_lst: if buyer_email in expense.user_email_lst: expense_id = expense.expense_id target_expense = expense break if expense_id == None: response = {} response[ 'error'] = 'the buyer email: ' + buyer_email + ' is not valid for this expense/apartment' return self.respond(**response) new_item = Item(item_id=str(item_id), item_name=item_name, cover_url=cover_url, expense_id=expense_id, buyer_email=buyer_email, sharer_email_lst=sharer_email_lst, total_cost=total_cost) new_item.put() target_expense.item_id_lst.insert(0, str(item_id)) target_expense.put() self.respond(item_id_id=str(item_id), status="Success")
def get(self): print("get finish task request") task_id = self.request.get(IDENTIFIER_TASK_ID) total_cost = self.request.get(IDENTIFIER_TOTAL_COST) user_email = self.request.get(IDENTIFIER_USER_EMAIL) total_cost = float(total_cost) print("get cost " + str(total_cost)) tasks = Task.query(Task.task_id == task_id).fetch() task = tasks[0] print("Found the task " + task.task_name) if task.finished: response = {} response['error'] = 'the task has already been finished' return self.respond(**response) if user_email != task.charger_email: response = {} response['error'] = 'the task has been assigned to other roommate' return self.respond(**response) task.finished = True task.put() item_id = str(uuid.uuid4()) sharer_lst = task.candidate_lst # sharer_lst.remove(task.charger_email) # newly removed this line print("creating item ") new_Item = Item(item_id=item_id, cover_url=str(task.photo_blobkey), expense_id=task.expense_id, total_cost=total_cost, buyer_email=task.charger_email, sharer_email_lst=sharer_lst, item_name=task.task_name) new_Item.put() expenses = Expense.query(Expense.expense_id == task.expense_id).fetch() if len(expenses) == 0: print("cannot find the expense") else: expense = expenses[0] item_ids = expense.item_id_lst item_ids.append(item_id) expense.item_id_lst = item_ids expense.put() print("done ") self.respond(item_name=task.task_name, item_id=task.task_id, status="Success")
def get(self): expense_name = self.request.get(IDENTIFIER_EXPENSE_NAME) apt_name = self.request.get(IDENTIFIER_APT_NAME) user_email = self.request.get(IDENTIFIER_USER_EMAIL) apt_lst = Apartment.query(Apartment.apt_name == apt_name).fetch() cur_apt = None for apt in apt_lst: if user_email in apt.user_email_lst: cur_apt = apt if cur_apt == None: response = {} response[ 'error'] = 'the apt: ' + apt_name + ' is not available for user: '******'error'] = 'the apt: ' + apt_name + ' does not have a expense named: ' + expense_name return self.respond(**response) if cur_expense.is_paid: response = {} response[ 'error'] = 'the : ' + expense_name + ' has already been paid' return self.respond(**response) cur_expense.checkout() cur_apt.total_cost += cur_expense.total_cost cur_apt.put() user_info_lst = [] for user_email in cur_apt.user_email_lst: users = User.query(User.user_email == user_email).fetch() user = users[0] user_info = {} user_info['email:'] = user_email user_info['nick_name'] = user.nick_name user_info['owe'] = user.cost user_info['owed'] = user.borrow user_info['balance'] = user.owe user_info_lst.append(user_info) self.respond(user_info_lst=user_info_lst, status="Success")
def get(self): expense_name = self.request.get(IDENTIFIER_EXPENSE_NAME) apt_name = self.request.get(IDENTIFIER_APT_NAME) user_email = self.request.get(IDENTIFIER_USER_EMAIL) apt_lst = Apartment.query(Apartment.apt_name == apt_name).fetch() cur_apt = None for apt in apt_lst: if user_email in apt.user_email_lst: cur_apt = apt if cur_apt == None: response = {} response['error'] = 'the apt: ' + apt_name + ' is not available for user: '******'error'] = 'the apt: ' + apt_name + ' does not have a expense named: ' + expense_name return self.respond(**response) if cur_expense.is_paid: response = {} response['error'] = 'the : ' + expense_name + ' has already been paid' return self.respond(**response) cur_expense.checkout() cur_apt.total_cost += cur_expense.total_cost cur_apt.put() user_info_lst = [] for user_email in cur_apt.user_email_lst: users = User.query(User.user_email == user_email).fetch() user = users[0] user_info = {} user_info['email:'] = user_email user_info['nick_name'] = user.nick_name user_info['owe'] = user.cost user_info['owed'] = user.borrow user_info['balance'] = user.owe user_info_lst.append(user_info) self.respond(user_info_lst = user_info_lst, status="Success")
def get(self): apt_id = self.request.get(IDENTIFIER_APT_ID) target_apt_lst = Apartment.query(Apartment.apt_id == apt_id).fetch() if len(target_apt_lst) != 1: print "target_apt_lst length error:" + str(len(target_apt_lst)) query_apt = target_apt_lst[0] expense_id_lst = query_apt.expense_id_lst print "expense_id_lst length:" + str(len(expense_id_lst)) unassigned_tasks_lst = [] assigned_tasks_lst = [] finished_tasks_lst = [] for expense_id in expense_id_lst: # expense_id = self.request.get(IDENTIFIER_EXPENSE_ID) expenses = Expense.query(Expense.expense_id == expense_id).fetch() if len(expenses) == 0: continue expense = expenses[0] tasks = expense.getAllTasks() for task in tasks: cur_task = {} cur_task['photo_blobkey'] = str(task.photo_blobkey) cur_task['creator_nickname'] = task.getCreaterNickName() cur_task['creator_email'] = task.creater_email cur_task['task_name'] = task.task_name cur_task['description'] = task.description cur_task['task_id'] = str(task.task_id) cur_task['expense_id'] = str(task.expense_id) cur_task['candidate_lst_str'] = task.getCandidateListString() if task.assigned: cur_task['charger_name'] = task.getChargerNickName() cur_task['charger_email'] = task.charger_email if task.finished: finished_tasks_lst.append(cur_task) else: assigned_tasks_lst.append(cur_task) else: unassigned_tasks_lst.append(cur_task) task_info = {} task_info['finished_tasks_lst'] = finished_tasks_lst task_info['unassigned_tasks_lst'] = unassigned_tasks_lst task_info['assigned_tasks_lst'] = assigned_tasks_lst self.respond(task_info=task_info, status="Success")
def get(self): apt_id = self.request.get(IDENTIFIER_APT_ID) target_apt_lst = Apartment.query(Apartment.apt_id == apt_id).fetch() if len(target_apt_lst)!=1: print "target_apt_lst length error:" + str(len(target_apt_lst)) query_apt = target_apt_lst[0] expense_id_lst = query_apt.expense_id_lst print "expense_id_lst length:" + str(len(expense_id_lst)) unassigned_tasks_lst = [] assigned_tasks_lst = [] finished_tasks_lst = [] for expense_id in expense_id_lst: # expense_id = self.request.get(IDENTIFIER_EXPENSE_ID) expenses = Expense.query(Expense.expense_id == expense_id).fetch() if len(expenses) == 0: continue expense = expenses[0] tasks = expense.getAllTasks() for task in tasks: cur_task = {} cur_task['photo_blobkey'] = str(task.photo_blobkey) cur_task['creator_nickname'] = task.getCreaterNickName() cur_task['creator_email'] = task.creater_email cur_task['task_name'] = task.task_name cur_task['description'] = task.description cur_task['task_id'] = str(task.task_id) cur_task['expense_id'] = str(task.expense_id) cur_task['candidate_lst_str'] = task.getCandidateListString() if task.assigned: cur_task['charger_name'] = task.getChargerNickName() cur_task['charger_email'] = task.charger_email if task.finished: finished_tasks_lst.append(cur_task) else: assigned_tasks_lst.append(cur_task) else: unassigned_tasks_lst.append(cur_task) task_info = {} task_info['finished_tasks_lst'] = finished_tasks_lst task_info['unassigned_tasks_lst'] = unassigned_tasks_lst task_info['assigned_tasks_lst'] = assigned_tasks_lst self.respond(task_info=task_info, status="Success")
def get(self): print("get finish task request") task_id = self.request.get(IDENTIFIER_TASK_ID) total_cost = self.request.get(IDENTIFIER_TOTAL_COST) user_email = self.request.get(IDENTIFIER_USER_EMAIL) total_cost = float(total_cost) print("get cost " + str(total_cost)) tasks = Task.query(Task.task_id == task_id).fetch() task = tasks[0] print("Found the task " + task.task_name) if task.finished: response = {} response['error'] = 'the task has already been finished' return self.respond(**response) if user_email != task.charger_email: response = {} response['error'] = 'the task has been assigned to other roommate' return self.respond(**response) task.finished = True task.put() item_id = str(uuid.uuid4()) sharer_lst = task.candidate_lst # sharer_lst.remove(task.charger_email) # newly removed this line print("creating item ") new_Item = Item(item_id = item_id, cover_url = str(task.photo_blobkey), expense_id = task.expense_id, total_cost = total_cost, buyer_email = task.charger_email, sharer_email_lst = sharer_lst, item_name = task.task_name) new_Item.put() expenses = Expense.query(Expense.expense_id == task.expense_id).fetch() if len(expenses) == 0: print("cannot find the expense"); else: expense = expenses[0] item_ids = expense.item_id_lst item_ids.append(item_id) expense.item_id_lst = item_ids expense.put() print("done ") self.respond(item_name = task.task_name, item_id = task.task_id, status="Success")
def get(self): # req_json = json.loads(self.request.body) # expense_name = req_json[IDENTIFIER_EXPENSE_NAME] expense_name = self.request.get(IDENTIFIER_EXPENSE_NAME) # user_email = req_json[IDENTIFIER_USER_EMAIL] user_email = self.request.get(IDENTIFIER_USER_EMAIL) # new_sharer_email = req_json[IDENTIFIER_NEW_EMAIL] new_sharer_email = self.request.get(IDENTIFIER_NEW_EMAIL) target_expense = None expense_lst = Expense.query(Expense.expense_name == expense_name) for expense in expense_lst: if user_email in expense.user_email_lst: target_expense = expense break if target_expense == None: response = {} response['error'] = 'the expense: ' + expense_name + ' has not been created' return self.respond(**response) if not new_sharer_email in target_expense.user_email_lst: target_expense.user_email_lst.insert(0, new_sharer_email) target_expense.put() self.respond(expense_id = target_expense.expense_id, new_user = new_sharer_email, status="Success")
def get(self): apt_name = self.request.get(IDENTIFIER_APT_NAME) user_email = self.request.get(IDENTIFIER_USER_EMAIL) apt_lst = Apartment.query(Apartment.apt_name == apt_name).fetch() cur_apt = None for apt in apt_lst: if user_email in apt.user_email_lst: cur_apt = apt if cur_apt == None: response = {} response['error'] = 'the apt: ' + apt_name + ' is not available for user: ' + user_email return self.respond(**response) for expense_id in cur_apt.expense_id_lst: expense_lst = Expense.query(Expense.expense_id == expense_id).fetch() if len(expense_lst) > 0: expense = expense_lst[0] if not expense.is_paid: expense.checkout() cur_apt.total_cost += expense.total_cost cur_apt.put() self.respond(status="Success")
def get(self): expense_id = self.request.get(IDENTIFIER_EXPENSE_ID) print "expense_id :" + expense_id expenses = Expense.query(Expense.expense_id == expense_id).fetch() expense = expenses[0] expense_name = expense.expense_name items = expense.getAllItems() tasks = expense.getAllTasks() expected_cost = 0.0 items_lst = [] is_paid = expense.is_paid expense_user_lst = expense.getUserNickNameLst() for item in items: expected_cost += item.total_cost cur_item = {} cur_item['item_cost'] = item.total_cost cur_item['is_paid'] = item.is_paid cur_item['item_id'] = str(item.item_id) cur_item['cover_url'] = item.cover_url cur_item['buyer'] = item.getBuyer() cur_item['sharer_lst'] = item.getSharersNickName() cur_item['sharer_email_lst'] = item.sharer_email_lst cur_item['item_name'] = item.item_name cur_item[ 'expense_id'] = item.expense_id # fixed ; there was no expense_id attached here cur_item['buyer_email'] = item.buyer_email items_lst.append(cur_item) finished_tasks_lst = [] unassigned_tasks_lst = [] assigned_tasks_lst = [] for task in tasks: cur_task = {} cur_task['photo'] = str(task.photo_blobkey) cur_task['creater'] = task.getCreaterNickName() cur_task['creater_email'] = task.creater_email cur_task['task_name'] = task.task_name cur_task['task_id'] = str(task.task_id) if task.assigned: cur_task['person in charge'] = task.getChargerNickName() cur_task['person in charge email'] = task.charger_email if task.finished: finished_tasks_lst.append(cur_task) else: assigned_tasks_lst.append(cur_task) else: unassigned_tasks_lst.append(cur_task) task_info = {} task_info['finished_tasks_lst'] = finished_tasks_lst task_info['unassigned_tasks_lst'] = unassigned_tasks_lst task_info['assigned_tasks_lst'] = assigned_tasks_lst user_email_lst = expense.user_email_lst self.respond(total_cost=expected_cost, items_lst=items_lst, is_paid=is_paid, expense_name=expense_name, expense_user_lst=expense_user_lst, user_email_lst=user_email_lst, task_info=task_info, status='Success')
def get(self): expense_id = uuid.uuid4() # req_json = json.loads(self.request.body) # expense_name = req_json[IDENTIFIER_EXPENSE_NAME ] expense_name = self.request.get(IDENTIFIER_EXPENSE_NAME) # user_email = req_json[IDENTIFIER_USER_EMAIL] user_email = self.request.get(IDENTIFIER_USER_EMAIL) # apt_name = req_json[IDENTIFIER_APT_NAME] apt_name = self.request.get(IDENTIFIER_APT_NAME) user_emails = self.request.get(IDENTIFIER_USER_LIST) user_email_lst = user_emails.split(",") target_apt_lst = Apartment.query( Apartment.apt_name == apt_name).fetch() target_apt = None for apt in target_apt_lst: if user_email in apt.user_email_lst: target_apt = apt break if target_apt == None: response = {} response[ 'error'] = 'the user: '******' is not valid for apt: ' + apt_name return self.respond(**response) # user_email_lst.insert(0, user_email) # check whether this apt name is valid or not expense_lst = Expense.query(Expense.expense_name == expense_name) for expense in expense_lst: for user in user_email_lst: if user in expense.user_email_lst: response = {} response[ 'error'] = 'the apartment name: ' + expense_name + ' has not been used for ' + user return self.respond(**response) # check whether all of these email are valid users for user in user_email_lst: users = User.query(User.user_email == user).fetch() if len(users) == 0: response = {} response[ 'error'] = 'the email: ' + user + ' has not been registered' return self.respond(**response) cover_url = None # if IDENTIFIER_APT_PHOTO in req_json: # cover_url = req_json[IDENTIFIER_APT_PHOTO] new_expense = Expense(apt_id=target_apt.apt_id, creater_email=user_email, user_email_lst=user_email_lst, cover_url=cover_url, expense_name=expense_name, total_cost=0, is_paid=False, expense_id=str(expense_id)) target_apt.expense_id_lst.insert(0, str(expense_id)) new_expense.put() target_apt.put() self.respond(expense_id=str(expense_id), status="Success")
def get(self): expense_id = self.request.get(IDENTIFIER_EXPENSE_ID) print "expense_id :" + expense_id expenses = Expense.query(Expense.expense_id == expense_id).fetch() expense = expenses[0] expense_name = expense.expense_name items = expense.getAllItems() tasks = expense.getAllTasks() expected_cost = 0.0 items_lst = [] is_paid = expense.is_paid expense_user_lst = expense.getUserNickNameLst() for item in items: expected_cost += item.total_cost cur_item = {} cur_item['item_cost'] = item.total_cost cur_item['is_paid'] = item.is_paid cur_item['item_id'] = str(item.item_id) cur_item['cover_url'] = item.cover_url cur_item['buyer'] = item.getBuyer() cur_item['sharer_lst'] = item.getSharersNickName() cur_item['sharer_email_lst'] = item.sharer_email_lst cur_item['item_name'] = item.item_name cur_item['expense_id'] = item.expense_id # fixed ; there was no expense_id attached here cur_item['buyer_email'] = item.buyer_email items_lst.append(cur_item) finished_tasks_lst = [] unassigned_tasks_lst = [] assigned_tasks_lst = [] for task in tasks: cur_task = {} cur_task['photo'] = str(task.photo_blobkey) cur_task['creater'] = task.getCreaterNickName() cur_task['creater_email'] = task.creater_email cur_task['task_name'] = task.task_name cur_task['task_id'] = str(task.task_id) if task.assigned: cur_task['person in charge'] = task.getChargerNickName() cur_task['person in charge email'] = task.charger_email if task.finished: finished_tasks_lst.append(cur_task) else: assigned_tasks_lst.append(cur_task) else: unassigned_tasks_lst.append(cur_task) task_info = {} task_info['finished_tasks_lst'] = finished_tasks_lst task_info['unassigned_tasks_lst'] = unassigned_tasks_lst task_info['assigned_tasks_lst'] = assigned_tasks_lst user_email_lst=expense.user_email_lst self.respond(total_cost = expected_cost, items_lst = items_lst, is_paid = is_paid, expense_name = expense_name, expense_user_lst = expense_user_lst, user_email_lst=user_email_lst, task_info = task_info, status = 'Success')
def get(self): expense_id = uuid.uuid4() # req_json = json.loads(self.request.body) # expense_name = req_json[IDENTIFIER_EXPENSE_NAME ] expense_name = self.request.get(IDENTIFIER_EXPENSE_NAME) # user_email = req_json[IDENTIFIER_USER_EMAIL] user_email = self.request.get(IDENTIFIER_USER_EMAIL) # apt_name = req_json[IDENTIFIER_APT_NAME] apt_name = self.request.get(IDENTIFIER_APT_NAME) user_emails = self.request.get(IDENTIFIER_USER_LIST) user_email_lst = user_emails.split(",") target_apt_lst = Apartment.query(Apartment.apt_name == apt_name).fetch() target_apt = None for apt in target_apt_lst: if user_email in apt.user_email_lst: target_apt = apt break if target_apt == None: response = {} response['error'] = 'the user: '******' is not valid for apt: ' + apt_name return self.respond(**response) # user_email_lst.insert(0, user_email) # check whether this apt name is valid or not expense_lst = Expense.query(Expense.expense_name == expense_name) for expense in expense_lst: for user in user_email_lst: if user in expense.user_email_lst: response = {} response['error'] = 'the apartment name: ' + expense_name + ' has not been used for ' + user return self.respond(**response) # check whether all of these email are valid users for user in user_email_lst: users = User.query(User.user_email == user).fetch() if len(users) == 0: response = {} response['error'] = 'the email: ' + user + ' has not been registered' return self.respond(**response) cover_url = None # if IDENTIFIER_APT_PHOTO in req_json: # cover_url = req_json[IDENTIFIER_APT_PHOTO] new_expense = Expense(apt_id = target_apt.apt_id, creater_email = user_email, user_email_lst = user_email_lst, cover_url = cover_url, expense_name = expense_name, total_cost = 0, is_paid = False, expense_id = str(expense_id )) target_apt.expense_id_lst.insert(0, str(expense_id)) new_expense.put() target_apt.put() self.respond(expense_id = str(expense_id), status="Success")