def add_engineering_day(request, project_number, wbs_id): project = get_object_or_404(Project, project_number=project_number) check_project_write_acl(project, request.user) # Will return Http404 if user isn't allowed to view project work_item = WorkItem.objects.get(id=wbs_id) if request.method == 'POST': form = EngineeringDayForm(request.POST) if form.is_valid(): t = form.save(commit=False) logging.debug('''resource => %s, work_date => %s, day_type => %s''' % ( t.resource, t.work_date, t.day_type )) available_resources = get_resources_for_engineering_day(request, project_number, wbs_id, t.work_date.strftime("%Y"), t.work_date.strftime("%m"), t.work_date.strftime("%d"), t.day_type, as_json=False) logging.debug('''Resource ID is: %s''' % t.resource.id ) logging.debug('''Available resources are: %s''' % available_resources ) if t.resource.id not in [ r['pk'] for r in available_resources ]: logging.debug('''User has tried to book %s on %s when he hasn't got the correct skillset''' % ( t.resource, t.work_date )) return HttpResponse( handle_generic_error("Sorry - this resource hasn't got the skillset to work on this task")) if EngineeringDay.objects.filter(work_date=t.work_date, resource=t.resource, day_type__in=[ t.day_type, 2]).count() > 0: logging.debug('''User has tried to book %s on %s when he has existing engineering days booked''' % ( t.resource, t.work_date )) return HttpResponse( handle_generic_error("Sorry - this resource is already booked at this time.")) t.save() work_item.engineering_days.add(t) work_item.save() return HttpResponse( return_json_success() ) else: return HttpResponse( handle_form_errors(form.errors))
def delete_checkpoint_report(request, project_number, report_id): project = Project.objects.get(project_number=project_number) try: report = ExecutiveSummary.objects.get(id=report_id) except ExecutiveSummary.DoesNotExist: return HttpResponse( handle_generic_error("Report does not exist")) project.executive_summary.remove(report) project.save() return HttpResponse( return_json_success() )
def delete_lesson(request, project_number, lesson_id): project = Project.objects.get(project_number=project_number) try: lesson = LessonLearnt.objects.get(id=lesson_id) except Lesson.DoesNotExist: return HttpResponse( handle_generic_error("Lesson does not exist")) project.lessons_learnt.remove(lesson) project.save() return HttpResponse( return_json_success() )
def delete_lesson(request, project_number, lesson_id): project = Project.objects.get(project_number=project_number) try: lesson = LessonLearnt.objects.get(id=lesson_id) except Lesson.DoesNotExist: return HttpResponse(handle_generic_error("Lesson does not exist")) project.lessons_learnt.remove(lesson) project.save() return HttpResponse(return_json_success())
def delete_risk(request, project_number, risk_id): project = Project.objects.get(project_number=project_number) try: risk = Risk.objects.get(id=risk_id) except Risk.DoesNotExist: return HttpResponse(handle_generic_error("Risk does not exist")) project.risks.remove(risk) project.save() return HttpResponse(return_json_success())
def delete_checkpoint_report(request, project_number, report_id): project = Project.objects.get(project_number=project_number) try: report = ExecutiveSummary.objects.get(id=report_id) except ExecutiveSummary.DoesNotExist: return HttpResponse(handle_generic_error("Report does not exist")) project.executive_summary.remove(report) project.save() return HttpResponse(return_json_success())
def delete_risk(request, project_number, risk_id): project = Project.objects.get(project_number=project_number) try: risk = Risk.objects.get(id=risk_id) except Risk.DoesNotExist: return HttpResponse( handle_generic_error("Risk does not exist")) project.risks.remove(risk) project.save() return HttpResponse( return_json_success() )
def delete_file(request, project_number): project = Project.objects.get(project_number=project_number) file = ProjectFile.objects.get(id=request.POST['pk']) if user_has_write_access(project, request.user): project.files.remove(file) project.save() return HttpResponse( return_json_success() ) else: return HttpResponse( handle_generic_error("Sorry - you don't have permission to delete this file")) r
def delete_issue(request, project_number, issue_id): project = Project.objects.get(project_number=project_number) check_project_read_acl(project, request.user) # Will return Http404 if user isn't allowed to view project try: issue = Issue.objects.get(id=issue_id) except: return HttpResponse( handle_generic_error("Issue does not exist")) project.issues.remove(issue) project.save() return HttpResponse( return_json_success() )
def delete_file(request, project_number): project = Project.objects.get(project_number=project_number) file = ProjectFile.objects.get(id=request.POST['pk']) if user_has_write_access(project, request.user): project.files.remove(file) project.save() return HttpResponse(return_json_success()) else: return HttpResponse( handle_generic_error( "Sorry - you don't have permission to delete this file")) r
def delete_deliverable(request, project_number, deliverable_id): # Some security - only allow users to view objects they are allowed to via read_acl project = get_object_or_404(Project, project_number=project_number) check_project_read_acl(project, request.user) # Will return Http404 if user isn't allowed to view project if user_has_write_access(project, request.user): deliverable = Deliverable.objects.get(id=deliverable_id) project.deliverables.remove(deliverable) project.save() return HttpResponse(return_json_success()) else: return HttpResponse(handle_generic_error("Sorry - you don't have sufficient access to update the project"))
def add_wip_engineering_day(request, wip_report, work_item_id): work_item = get_object_or_404(WIPItem, id=work_item_id) wip_report = WIPReport.objects.get(name=wip_report) if request.method == 'POST': form = EngineeringDayForm(request.POST) if form.is_valid(): t = form.save(commit=False) logging.debug('''resource => %s, work_date => %s, day_type => %s''' % ( t.resource, t.work_date, t.day_type )) available_resources = get_resources_for_engineering_day(request, wip_report, t.work_date.strftime("%Y"), t.work_date.strftime("%m"), t.work_date.strftime("%d"), t.day_type, as_json=False) logging.debug('''Resource ID is: %s''' % t.resource.id ) logging.debug('''Available resources are: %s''' % available_resources ) if t.resource.id not in [ r['pk'] for r in available_resources ]: logging.debug('''User has tried to book %s on %s when he hasn't got the correct skillset''' % ( t.resource, t.work_date )) return HttpResponse( handle_generic_error("Sorry - this resource hasn't got the skillset to work on this task")) if EngineeringDay.objects.filter(work_date=t.work_date, resource=t.resource, day_type__in=[ t.day_type, 2]).count() > 0: logging.debug('''User has tried to book %s on %s when he has existing engineering days booked''' % ( t.resource, t.work_date )) return HttpResponse( handle_generic_error("Sorry - this resource is already booked at this time.")) # Check the rota, make sure resource isn't on holiday or training etc try: rota = RotaItem.objects.get(date=t.work_date, person=t.resource) if rota.activity.unavailable_for_projects: return HttpResponse( handle_generic_error("Sorry - this resource has an entry in the Rota stopping you booking this Engineering Day.")) except RotaItem.DoesNotExist: pass t.save() work_item.engineering_days.add(t) work_item.save() logging.debug('''Booked engineering day for %s on %s''' % ( t.resource, t.work_date )) return HttpResponse( return_json_success() ) else: return HttpResponse( handle_form_errors(form.errors))
def delete_issue(request, project_number, issue_id): project = Project.objects.get(project_number=project_number) check_project_read_acl( project, request.user ) # Will return Http404 if user isn't allowed to view project try: issue = Issue.objects.get(id=issue_id) except: return HttpResponse(handle_generic_error("Issue does not exist")) project.issues.remove(issue) project.save() return HttpResponse(return_json_success())
def delete_deliverable(request, project_number, deliverable_id): # Some security - only allow users to view objects they are allowed to via read_acl project = get_object_or_404(Project, project_number=project_number) check_project_read_acl( project, request.user ) # Will return Http404 if user isn't allowed to view project if user_has_write_access(project, request.user): deliverable = Deliverable.objects.get(id=deliverable_id) project.deliverables.remove(deliverable) project.save() return HttpResponse(return_json_success()) else: return HttpResponse( handle_generic_error( "Sorry - you don't have sufficient access to update the project" ))
def add_heading(request, wip_report): wip_report = get_object_or_404(WIPReport, name=wip_report) # Some security allow_access = False for group in request.user.groups.all(): if group in wip_report.write_acl.all(): allow_access = True if allow_access: form = WIPHeadingForm(request.POST) if form.is_valid(): t = form.save() wip_report.headings.add(t) wip_report.save() _add_wip_to_archive(wip_report) return HttpResponse( return_json_success() ) else: return HttpResponse( handle_form_errors(form.errors)) else: return HttpResponse( handle_generic_error("Sorry, you don't have permissions to add a WIP heading"))