class TaskModelTest(TestCase): def setUp(self): self.obj = Task(name="Task teste 1", is_done=False) def test_create(self): self.obj.save() self.assertEqual(1, self.obj.pk)
def add_checklist(request, pk): pet = get_object_or_404(Pet, pk=pk) if request.method == 'POST': form = ChecklistForm2(request.POST) sitterform = UserForm(request.POST, user=request.user) if form.is_valid() and sitterform.is_valid(): start_date = form.cleaned_data.get('start_date') end_date = form.cleaned_data.get('end_date') sitter = sitterform.cleaned_data.get('sitter') task1 = request.POST['task1'] task2 = request.POST['task2'] task3 = request.POST['task3'] task4 = request.POST['task4'] task5 = request.POST['task5'] task6 = request.POST['task6'] task7 = request.POST['task7'] task8 = request.POST['task8'] task9 = request.POST['task9'] task10 = request.POST['task10'] print (start_date) print (end_date) delta = end_date - start_date print(delta.days) existing_visit = Visit.objects.filter(sitter_id=sitter).filter(due_date_on=start_date) num_of_days = delta.days if delta.days == 0: if existing_visit: visitpk = existing_visit[0] Checklist.objects existing_checklist = Checklist.objects.filter(visit=visitpk).filter(pet_id=pet) if existing_checklist: checklist = existing_checklist[0] else: checklist = Checklist(visit=visitpk, pet_id=pet) checklist.save() if task1: new_task1 = Task(description=task1, checklist_id=checklist) new_task1.save() if task2: new_task2 = Task(description=task2, checklist_id=checklist) new_task2.save() if task3: new_task3 = Task(description=task3, checklist_id=checklist) new_task3.save() if task4: new_task4 = Task(description=task4, checklist_id=checklist) new_task4.save() if task5: new_task5 = Task(description=task5, checklist_id=checklist) new_task5.save() if task6: new_task6 = Task(description=task6, checklist_id=checklist) new_task6.save() if task7: new_task7 = Task(description=task7, checklist_id=checklist) new_task7.save() if task8: new_task8 = Task(description=task8, checklist_id=checklist) new_task8.save() if task9: new_task9 = Task(description=task9, checklist_id=checklist) new_task9.save() if task10: new_task10 = Task(description=task10, checklist_id=checklist) new_task10.save() print("EXISTING VISIT WITH DATE AND USER") else: new_visit = Visit(sitter_id=sitter, due_date_on=start_date) new_visit.save() visit_id = new_visit.pk new_checklist = Checklist(visit=new_visit, pet_id=pet) new_checklist.save() if task1: new_task1 = Task(description=task1, checklist_id=new_checklist) new_task1.save() if task2: new_task2 = Task(description=task2, checklist_id=new_checklist) new_task2.save() if task3: new_task3 = Task(description=task3, checklist_id=new_checklist) new_task3.save() if task4: new_task4 = Task(description=task4, checklist_id=new_checklist) new_task4.save() if task5: new_task5 = Task(description=task5, checklist_id=new_checklist) new_task5.save() if task6: new_task6 = Task(description=task6, checklist_id=new_checklist) new_task6.save() if task7: new_task7 = Task(description=task7, checklist_id=new_checklist) new_task7.save() if task8: new_task8 = Task(description=task8, checklist_id=new_checklist) new_task8.save() if task9: new_task9 = Task(description=task9, checklist_id=new_checklist) new_task9.save() if task10: new_task10 = Task(description=task10, checklist_id=new_checklist) new_task10.save() print("A NEW VISIT WITH DATE AND USER") else: for day in range(num_of_days+1): print("MORE THAN ONE DAY!") current_date = start_date + datetime.timedelta(days=day) print(current_date) existing_visit = Visit.objects.filter(sitter_id=sitter).filter(due_date_on=current_date) if existing_visit: print("EXISTING VISIT") visitpk = existing_visit[0] print(visitpk) Checklist.objects existing_checklist = Checklist.objects.filter(visit=visitpk).filter(pet_id=pet) if existing_checklist: checklist = existing_checklist[0] else: checklist = Checklist(visit=visitpk, pet_id=pet) checklist.save() if task1: new_task1 = Task(description=task1, checklist_id=checklist) new_task1.save() if task2: new_task2 = Task(description=task2, checklist_id=checklist) new_task2.save() if task3: new_task3 = Task(description=task3, checklist_id=checklist) new_task3.save() if task4: new_task4 = Task(description=task4, checklist_id=checklist) new_task4.save() if task5: new_task5 = Task(description=task5, checklist_id=checklist) new_task5.save() if task6: new_task6 = Task(description=task6, checklist_id=checklist) new_task6.save() if task7: new_task7 = Task(description=task7, checklist_id=checklist) new_task7.save() if task8: new_task8 = Task(description=task8, checklist_id=checklist) new_task8.save() if task9: new_task9 = Task(description=task9, checklist_id=checklist) new_task9.save() if task10: new_task10 = Task(description=task10, checklist_id=checklist) new_task10.save() print("SAME DAY") else: new_visit = Visit(sitter_id=sitter, due_date_on=current_date) new_visit.save() visit_id = new_visit.pk new_checklist = Checklist(visit=new_visit, pet_id=pet) new_checklist.save() if task1: new_task1 = Task(description=task1, checklist_id=new_checklist) new_task1.save() if task2: new_task2 = Task(description=task2, checklist_id=new_checklist) new_task2.save() if task3: new_task3 = Task(description=task3, checklist_id=new_checklist) new_task3.save() if task4: new_task4 = Task(description=task4, checklist_id=new_checklist) new_task4.save() if task5: new_task5 = Task(description=task5, checklist_id=new_checklist) new_task5.save() if task6: new_task6 = Task(description=task6, checklist_id=new_checklist) new_task6.save() if task7: new_task7 = Task(description=task7, checklist_id=new_checklist) new_task7.save() if task8: new_task8 = Task(description=task8, checklist_id=new_checklist) new_task8.save() if task9: new_task9 = Task(description=task9, checklist_id=new_checklist) new_task9.save() if task10: new_task10 = Task(description=task10, checklist_id=new_checklist) new_task10.save() print("DIFFERENT DAYS") return redirect('home') else: form = ChecklistForm2() sitterform = UserForm(user=request.user) return render(request, 'add_checklist.html', {'form': form, 'pet' : pet, 'sitterform': sitterform})
def create_task(request, project): task_name = request.POST.get("taskname") task_description = request.POST.get("taskdescription") t = Task(name=task_name, description=task_description, user=request.user, project=project) t.save()
def send_acknowldgement_email(book, press_editors): from_email = Setting.objects.get( group__name='email', name='from_address', ).value author_text = Setting.objects.get( group__name='email', name='author_submission_ack', ).value editor_text = Setting.objects.get( group__name='email', name='editor_submission_ack', ).value press_name = Setting.objects.get( group__name='general', name='press_name', ).value try: principal_contact_name = Setting.objects.get( group__name='general', name='primary_contact_name').value except: principal_contact_name = None context = { 'base_url': Setting.objects.get( group__name='general', name='base_url', ).value, 'submission': book, 'press_name': press_name, 'principal_contact_name': principal_contact_name, } email.send_email( get_setting('submission_ack_subject', 'email_subject', 'Submission Acknowledgement'), context, from_email, book.owner.email, author_text, book=book, kind='submission', ) if len(press_editors) > 1: editor = press_editors[0] cc_eds = [ed.email for ed in press_editors if ed != press_editors[0]] else: editor = press_editors[0] cc_eds = None email.send_email( get_setting('new_submission_subject', 'email_subject', 'New Submission'), context, from_email, editor.email, editor_text, book=book, cc=cc_eds, kind='submission', ) for editor in press_editors: notification = Task( book=book, assignee=editor, creator=press_editors[0], text='A new submission, {0}, has been made.'.format(book.title), workflow='review') notification.save()