def create_tasklist(form_data, method='create', instance=None): tasklistform = TasklistForm(form_data) if tasklistform.is_valid(): name = tasklistform.cleaned_data['name'] try: description = tasklistform.cleaned_data['description'] except: description = None try: notes = tasklistform.cleaned_data['notes'] except: notes = None status = tasklistform.cleaned_data['status'] if method == 'create': tasklist = TaskList(name=name, description=description, notes=notes, status=status) tasklist.save() elif method == 'edit': tasklist = TaskList.objects.get(id=instance.id) tasklist.name = name tasklist.description = description tasklist.notes = notes tasklist.status = status tasklist.save() return 0 return 255
def kanbanpage(request, tasklist_to_show_id=None): user_mail = request.session['user_mail'] if tasklist_to_show_id: tasklist = TaskList.objects.get(id=tasklist_to_show_id) tasks = SimpleTask.get_tasks_from_tasklist(tasklist) else: tasks = SimpleTask.get_all_tasks_by_user(user_mail) initial_backlog = SimpleTask.get_kanban_backlog_tasks(tasks) data_dict_obj = BuildTemplateContext('all', initial_backlog) final_backlog = data_dict_obj.get_data() all_tasklists = TaskList.get_tasklists_from_user(user_mail) final_backlog['all_tasklists'] = all_tasklists in_progress = SimpleTask.objects.filter(tasklist__user__email=user_mail, in_progress=True) finished = SimpleTask.objects.filter(tasklist__user__email=user_mail, in_progress=False, is_done=True) context = {"backlog": final_backlog, "in_progress": in_progress, "finished": finished} return render(request, "kanban.html", context)
def coveys_matrix_page(request, tasklist_to_show_id=None): user_mail = request.session['user_mail'] if tasklist_to_show_id: tasklist = TaskList.objects.get(id=tasklist_to_show_id) tasks = SimpleTask.get_tasks_from_tasklist(tasklist) else: tasks = SimpleTask.get_all_tasks_by_user(user_mail) backlog_tasks = SimpleTask.get_matrix_backlog_tasks(tasks) backlog_obj = BuildTemplateContext('all', backlog_tasks) final_backlog = backlog_obj.get_data() all_user_tasks = SimpleTask.get_all_tasks_by_user(user_mail) matrix_obj = BuildTemplateContext('matrix', all_user_tasks) matrix_data = matrix_obj.get_data() all_tasklists = TaskList.get_tasklists_from_user(user_mail) final_backlog['all_tasklists'] = all_tasklists return render(request, "stephen_covey_matrix.html", { 'backlog': final_backlog, 'matrix_data': matrix_data })
def post(self, request): if request.data.get('name', None) and request.data.get('name') != '': # Getting request data name = request.data.get('name') description = request.data.get('description') if request.data.get('description', None) else '' urgency = request.data.get('urgency') # Writing to database try: new_list = TaskList(name=name, description=description, urgency=urgency) new_list.save() new_list_access = ListAccess(user=request.user, list=new_list, role='owner') new_list_access.save() # Response back res_dict = { 'status': 'success', 'message': 'List created successfully', 'data': {'id': new_list.id, 'name': new_list.name, 'description': new_list.description, 'urgency': new_list.urgency} } res = Response() res.status_code = 201 res.data = res_dict except ValueError as val_err: # Response back res_dict = { 'status': 'failed', 'message': 'Something went wrong writing to DB, {0}'.format(val_err), 'data': {} } res = Response() res.status_code = 400 res.data = res_dict except Exception as e: # Response back res_dict = { 'status': 'failed', 'message': 'Something unexpected happened!, {0}'.format(e), 'data': {} } res = Response() res.status_code = 400 res.data = res_dict return res
def editcategory(request): list_id = request.POST['list_id'] tasklist_to_edit = TaskList.get_tasklist_by_id(id=list_id) new_list_name = request.POST['list_name'] new_list_color = request.POST['list_color'] tasklist_to_edit.name = new_list_name tasklist_to_edit.color = new_list_color tasklist_to_edit.save() return redirect('/tasks')
def tasks_dashboard(request, tasklist_to_show_id=None, display='all'): user_mail = request.session['user_mail'] if tasklist_to_show_id: tasklist = TaskList.get_tasklist_by_id(id=tasklist_to_show_id) tasks = SimpleTask.get_tasks_from_tasklist(tasklist) else: tasks = SimpleTask.get_all_tasks_by_user(user_mail) data_dict_obj = BuildTemplateContext(display, tasks) data_dict = data_dict_obj.get_data() all_tasklists = TaskList.get_tasklists_from_user(user_mail) data_dict['all_tasklists'] = all_tasklists if tasklist_to_show_id: data_dict['tasklist_to_show'] = tasklist return render(request, "tasks.html", data_dict)
def show_tasklist(request, id): user_mail = request.session['user_mail'] if id == 0: request.session['tasklist_to_show_id'] = 0 id = None try: tasklist = TaskList.objects.get(id=id) if tasklist in TaskList.get_tasklists_from_user(user_mail): return tasks_dashboard(request, tasklist_to_show_id=id) else: return tasks_dashboard(request) except (ObjectDoesNotExist): return tasks_dashboard(request)
def one_category_kanbanpage(request, id): user_mail = request.session['user_mail'] if id == 0: return kanbanpage(request, tasklist_to_show_id=None) try: tasklist = TaskList.objects.get(id=id) if tasklist in TaskList.get_tasklists_from_user(user_mail): return kanbanpage(request, tasklist_to_show_id=id) else: return kanbanpage(request, tasklist_to_show_id=None) except(ObjectDoesNotExist): return kanbanpage(request, tasklist_to_show_id=None)
def sort_by(request, type, id): user_mail = request.session['user_mail'] if id == 0: return tasks_dashboard(request, tasklist_to_show_id=None, display=type) try: tasklist = TaskList.objects.get(id=id) if tasklist in TaskList.get_tasklists_from_user(user_mail): return tasks_dashboard(request, tasklist_to_show_id=id, display=type) else: return tasks_dashboard(request) except (ObjectDoesNotExist): return tasks_dashboard(request)
def covey_sort_backlog(request, id): user_mail = request.session['user_mail'] if id == 0: return coveys_matrix_page(request, tasklist_to_show_id=None) try: tasklist = TaskList.objects.get(id=id) if tasklist in TaskList.get_tasklists_from_user(user_mail): return coveys_matrix_page(request, tasklist_to_show_id=id) else: return coveys_matrix_page(request, tasklist_to_show_id=None) except (ObjectDoesNotExist): return coveys_matrix_page(request, tasklist_to_show_id=None)
def update_task(request): id = request.POST['task_id'] task = SimpleTask.get_task_with_id(id) task.name = request.POST['name'] task.due_date = request.POST['due_date'] task.is_important = request.POST['importance'] task.is_urgent = request.POST['emergency'] if len(str(task.due_date)) > 5: task.due_date_clean_display = convert_to_clean_date(task.due_date) task.due_date = convert_into_date_type(str(task.due_date)) else: task.due_date = None task.due_date_clean_display = None task.description = request.POST['description'] new_category_id = request.POST['tasklists'] new_tasklist = TaskList.get_tasklist_by_id(new_category_id) task.tasklist = new_tasklist task.save() return tasks_dashboard(request, tasklist_to_show_id=new_tasklist.id)
def addtask(request): task_name = request.POST['name'] due_date = request.POST['due_date'] description = request.POST['description'] tasklist_id = request.POST['tasklists'] importance = request.POST['importance'] emergency = request.POST['emergency'] user_tasklist = TaskList.get_tasklist_by_id(id=tasklist_id) if not due_date: due_date = None task = SimpleTask(tasklist=user_tasklist, name=task_name, due_date=due_date, description=description, creation=timezone.now(), is_important=importance, is_urgent=emergency) if task.due_date: task.due_date_clean_display = convert_to_clean_date(task.due_date) task.save() return tasks_dashboard(request, tasklist_to_show_id=user_tasklist.id)
def deletecategory(request): list_id = request.POST['list_id'] tasklist_to_edit = TaskList.get_tasklist_by_id(id=list_id) tasklist_to_edit.delete() return redirect('/tasks')
def test_get_tasklist_by_id(self): tl = TaskList.get_tasklist_by_id(self.tasklist_1.id) self.assertTrue(isinstance(tl, TaskList)) self.assertEqual(tl.name, self.tasklist_1.name) self.assertEqual(tl.color, self.tasklist_1.color)
def test_get_tasklists_from_user(self): tl = TaskList.get_tasklists_from_user(self.user.email) self.assertTrue(isinstance(tl[0], TaskList)) self.assertEqual(tl[0].name, "Loisirs")