def put(self, task_id): task_id = int(task_id) json_data = json.loads(self.request.body) was_positive = json_data.get("goodJob") task_event = models.update_task_event_feedback(task_id, was_positive) if task_event: task = models.get_task(task_id) obj = jsons.get_task_json(task) update_json = {} update_json['eventType'] = 'taskFeedback' update_json['taskId'] = task_id update_json['positive'] = task_event.positive_feedback update_json['negative'] = task_event.negative_feedback member = models.get_member_key().get() update_json['doneBy'] = member.first_name + " " + member.last_name #if member.avatar: #update_json['avatar'] = member.avatar json_data = json.dumps(obj) update_data = json.dumps(update_json) publisher.update_clients(models.get_members_list(), update_data) self.response.out.write(json_data)
def get(self): members_list = models.get_members_list() members = jsons.get_all_members_json(members_list) json_data = {} json_data["houseName"] = models.get_household_key_for_current_user().get().name json_data["members"] = members json_data = json.dumps(json_data) self.response.out.write(json_data)
def put(self): json_data = json.loads(self.request.body) newOrder = json_data['newOrder'] oldOrder = json_data['oldOrder'] # This is swap # oldOrderTask = models.Task.query(models.Task.order == oldOrder).fetch()[0] # oldOrderTask.order = newOrder # # newOrderTask = models.Task.query(models.Task.order == newOrder).fetch()[0] # newOrderTask.order = oldOrder # # oldOrderTask.put() # newOrderTask.put() # If the new order (index) is bigger, this means that the task was moved down the list. # Hence, all the tasks in between must have their order decreased by 1 oldOrderTask = models.Task.query(models.Task.order == oldOrder).fetch()[0] if newOrder > oldOrder: q = models.Task.query(models.Task.order > oldOrder, models.Task.order <= newOrder) tasks = q.fetch() for task in tasks: task.order -= 1 task.put() # Else the new order (index) is smaller, this means that the task was moved up the list. # Hence, all the tasks in between must have their order increased by 1 else: q = models.Task.query(models.Task.order >= newOrder, models.Task.order < oldOrder) tasks = q.fetch() for task in tasks: task.order += 1 task.put() oldOrderTask.order = newOrder oldOrderTask.put() update_json = {} update_json['eventType'] = 'orderChangedEvent' update_json['taskChangedName'] = oldOrderTask.name member = models.get_member_key().get() update_json['doneBy'] = member.first_name + " " + member.last_name update_data = json.dumps(update_json) publisher.update_clients(models.get_members_list(), update_data) self.response.out.write(oldOrderTask.name + ": last order " + str(oldOrder) + " new order:" + str(newOrder))
def put(self): json_data = json.loads(self.request.body) task_id = json_data.get("taskID") task = models.edit_task(task_id, json_data) task_json = jsons.get_task_json(task) update_json = {} update_json['eventType'] = 'editTask' update_json['task'] = task_json json_data = json.dumps(task_json) update_data = json.dumps(update_json) publisher.update_clients(models.get_members_list(), update_data) self.response.out.write(json_data)
def get(self): models.populate_default_values(models.get_household_key_for_current_user()) # Send an event to everyone that table was repopulated update_json = {} update_json['eventType'] = 'populatedEvent' member = models.get_member_key().get() update_json['doneBy'] = member.first_name + " " + member.last_name update_data = json.dumps(update_json) publisher.update_clients(models.get_members_list(), update_data) self.response.out.write("All the data has been populated. <br> NOTE: If you open this URL again, it will be added again.")
def delete(self, task_id): task_id_int = int(task_id) models.delete_task(task_id_int) obj = { 'taskId': task_id_int } update_json = {} update_json['eventType'] = 'deleteTask' update_json['taskId'] = task_id_int json_data = json.dumps(obj) update_data = json.dumps(update_json) publisher.update_clients(models.get_members_list(), update_data) self.response.out.write(json_data)
def delegate_task_loop(specificTask=None): memberList = models.get_members_list( orderBy=models.Member.total_difficulty_done_assigned) if specificTask: delegate_task(specificTask, memberList) specificTask.put() else: tasks = models.get_all_tasks() for task in tasks: if not task.assigned: delegate_task(task, memberList) task.put() for member in memberList: member.put()
def post(self): json_data = json.loads(self.request.body) task_name = json_data.get("name") frequency = int(json_data.get("frequency")) description = json_data.get("description") difficulty = int(json_data.get("difficulty")) style = json_data.get("iconClass") task = models.add_task(task_name, difficulty, description, frequency, style) task = task.get() delegator.delegate_task_loop(task) task_json = jsons.get_task_json(task) update_json = {} update_json['eventType'] = 'addTask' update_json['task'] = task_json json_data = json.dumps(task_json) update_data = json.dumps(update_json) publisher.update_clients(models.get_members_list(), update_data) self.response.out.write(json_data)
def post(self, task_id): task_id = int(task_id) new_task_event = models.add_task_event(task_id).get() task = models.get_task(task_id) obj = jsons.get_task_json(task) update_json = {} update_json['eventType'] = 'taskEvent' update_json['taskId'] = task_id update_json[strings.assignedInitials] = task.get_delagated_initials() update_json[strings.completedByInitials] = new_task_event.completed_by.get().get_initials() member = models.get_member_key().get() update_json['doneBy'] = member.first_name + " " + member.last_name #if member.avatar: #update_json['avatar'] = member.avatar json_data = json.dumps(obj) update_data = json.dumps(update_json) publisher.update_clients(models.get_members_list(), update_data) self.response.out.write(json_data)
def get_house_json(): """ :return: Params: """ house_dict = {} users_dict = {} house = models.get_household_key_for_current_user().get() house_dict['name'] = house.name members = models.get_members_list() for member in members: user_dict = {} user_dict['firstName'] = member.first_name user_dict['lastName'] = member.last_name is_owner = member.key.id() == house.owner.id() user_dict['isOwner'] = is_owner user_dict['notificationsOn'] = member.notifications_on if member.last_name: user_dict['initials'] = (member.first_name[0] + member.last_name[0]).upper() else: user_dict['initials'] = (member.first_name[0]).upper() users_dict[member.key.id()] = user_dict house_dict['users'] = users_dict return house_dict
def get(self): try: charttype = self.request.GET['charttype'] self.response.headers['Content-Type'] = 'application/json' if charttype == "housechart": # Get the household key houseKey = models.get_household_key_for_current_user() #Get all members membersKeys = models.get_members_list(houseKey,keys_only=True) # response = {"house_name":houseKey.get().name } # response = {} # Chart 1 - Total amount of Difficulty Done and Assigned (TDDA) for each member # Array of Arrays with each data point data = [] # Array of Date Strings labels = [] # Array of member Names series = [] members = models.get_members_list(houseKey, keys_only=False) for member in members: labels.append(member.first_name) tdda = member.total_difficulty_done_assigned if tdda < 0: tdda = 0 data.append(tdda) response["chart1"]= { "data": data, "labels" : labels } # Chart 2 - Activity in the last 7 days # Array of Arrays with each data point data = [] # Array of Date Strings labels = [] # Array of member Names series = [] dateBefore7Days = datetime.datetime.now() - datetime.timedelta(days=6) # Add the labels as weekdays for j in range(5): day = dateBefore7Days + datetime.timedelta(days=j) labels.append(str(day.strftime("%a"))) # Add Yesterday and Today as labels labels.append("Yesterday") labels.append("Today") # For 7 days for i in range(len(membersKeys)): memberData = [] series.append(membersKeys[i].get().first_name) for j in range(7): day = dateBefore7Days + datetime.timedelta(days=j) memberData.append(models.get_all_task_events_count_for_member_for_date(membersKeys[i],day)) data.append(memberData) response["chart2"]= { "data": data, "labels" : labels, "series": series } # Chart 3 - Overall task distribution # Array of Arrays with each data point data = [] # Array of Tasks labels = [] # Array of member Names series = [] # Get the household key houseKey = models.get_household_key_for_current_user() #Get all members taskKeys = models.get_all_tasks_for_household(houseKey) for taskKey in taskKeys: labels.append(taskKey.get().name) # For 7 days for i in range(len(membersKeys)): memberData = [] series.append(membersKeys[i].get().first_name) for taskKey in taskKeys: memberData.append(models.get_all_task_events_count_for_task_and_member(taskKey, membersKeys[i])) data.append(memberData) response["chart3"]= { "data": data, "labels" : labels, "series": series } self.response.out.write(json.dumps(response)) elif charttype == "userchart": if not 'userid' in self.request.GET.keys(): #TODO return an error self.response.out.write("ERROR: userid must be present") pass else: memberKey = models.get_member_key(self.request.GET['userid']) # Get the household key houseKey = models.get_household_key_for_current_user() #Get all members taskKeys = models.get_all_tasks_for_household(houseKey) response = {} taskEventsPerTask = [] for taskKey in taskKeys: numOfTasks = models.get_all_task_events_count_for_task_and_member(taskKey, memberKey) if numOfTasks > 0: element = { 'name': taskKey.get().name , 'value': numOfTasks } taskEventsPerTask.append(element) response['taskeventspertask'] = taskEventsPerTask response['feedbackevents'] = models.get_all_positive_negative_labels_for_member(memberKey, taskKeys) self.response.out.write(json.dumps(response)) elif charttype == "tilechart": if not 'taskid' in self.request.GET.keys(): #TODO return an error self.response.out.write("ERROR: taskid must be present") pass else: taskKey = models.get_task_key(self.request.GET['taskid']) # Get the household key houseKey = models.get_household_key_for_current_user() #Get all members membersKeys = models.get_members_list(houseKey, keys_only=True) response = {} # Array of data points data = [] # Array of Member names labels = [] for i in range(len(membersKeys)): taskEventsCnt = models.get_all_task_events_count_for_task_and_member(taskKey, membersKeys[i]) if taskEventsCnt >0: # Only add the data point if it is bigger 0 labels.append(membersKeys[i].get().first_name) data.append(taskEventsCnt) response["chart1"]= { "data": data, "labels" : labels } self.response.out.write(json.dumps(response)) except Exception as e: # TODO: Return errors. # THIS IS ERROR. The chartype must be specified !!!! But for now just send it like that print(e)