def modify_priority(request, *args, **kws): """ Allows investigators to prioritize observers for a project. """ pcode, i_id, dir = args project = Project.objects.filter(pcode = pcode)[0] project.normalize_investigators() I = project.investigator_set.get(id = i_id) key = 'priority' if dir == "down" else '-priority' t = None for i in project.investigator_set.order_by(key): if i.observer: if t: t.priority, i.priority = i.priority, t.priority t.save() i.save() break if i == I: t = i revision.comment = get_rev_comment(request, project, "modify_priority") return HttpResponseRedirect("/project/%s" % pcode)
def dynamic_contact(request, *args, **kws): """ Allows investigators to update their dynamic contact information. """ user = User.objects.get(id = args[0]) if request.method == 'GET': return render_to_response("users/dynamic_contact_form.html" , {'u': user , 'requestor': get_requestor(request)}) else: # POST user.contact_instructions = request.POST.get("contact_instructions", "") user.save() revision.comment = get_rev_comment(request, user, "dynamic_contact_save") return HttpResponseRedirect("/profile/%s" % args[0])
def toggle_required_friend(request, *args, **kws): """ Allows investigators to designate required friends for a project. """ pcode, f_id = args f = Friend.objects.get(project__pcode = pcode, id = f_id) f.required = not f.required f.save() revision.comment = get_rev_comment(request, f, "toggle_required_friend") return HttpResponse( json.dumps({"success" : "ok"}) , mimetype = "text/plain")
def toggle_session(request, *args, **kws): """ Allows investigators to enables or disable a session for a project. """ pcode, sid = args s = Sesshun.objects.get(project__pcode = pcode, id = sid) s.status.enabled = not s.status.enabled s.status.save() revision.comment = get_rev_comment(request, s, "toggle_session") return HttpResponse( json.dumps({"success" : "ok"}) , mimetype = "text/plain")
def project_snotes(request, *args, **kwds): """ Allows schedulers to attach a note to a project. """ project = get_object_or_404(Project, pcode = args[0]) if request.method == 'GET': return render_to_response("users/project_snotes_form.html" , {'p' : project , 'requestor': get_requestor(request)}) else: # POST project.schedulers_notes = request.POST.get("notes", "") project.save() revision.comment = get_rev_comment(request, project, "project_snotes_save") return HttpResponseRedirect("/project/%s" % args[0])
def project_notes(request, *args, **kwds): """ Allows investigators to attach notes to one of their projects. """ pcode, = args project = get_object_or_404(Project, pcode = pcode) if request.method == 'GET': return render_to_response("users/project_notes_form.html" , {'p' : project , 'requestor': get_requestor(request)}) else: # POST project.notes = request.POST.get("notes", "") project.save() revision.comment = get_rev_comment(request, project, "project_notes_save") return HttpResponseRedirect("/project/%s" % pcode)
def toggle_observer(request, *args, **kws): """ Allows investigators to designate observers for a project. """ pcode, i_id = args i = Investigator.objects.get(project__pcode = pcode, id = i_id) i.observer = not i.observer i.save() project = Project.objects.filter(pcode=pcode)[0] project.normalize_investigators() revision.comment = get_rev_comment(request, i, "toggle_observer") return HttpResponse( json.dumps({"success" : "ok"}) , mimetype = "text/plain")
def blackout_worker(request, kind, forObj, b_id, requestor, urlRedirect): "Does most of the work for processing blackout forms" try: # use the requestor's time zone preference - not the users, # since this could be for a project blackout. tz = requestor.preference.timeZone except ObjectDoesNotExist: tz = "UTC" tz_form = PreferencesForm(initial = {'timeZone' : tz}) if request.method == 'POST': tz_form = PreferencesForm(request.POST) if tz_form.is_valid(): tzp = tz_form.cleaned_data['timeZone'] else: tz_form = PreferencesForm() tzp = tz f = BlackoutForm(request.POST) f.format_dates(tzp, request.POST) if f.is_valid(): if request.POST.get('_method', '') == 'PUT': b = Blackout.objects.get(id = b_id) else: if kind == "project_blackout": b = Blackout(project = forObj) else: b = Blackout(user = forObj) b.initialize(tzp, f.cleaned_start, f.cleaned_end, f.cleaned_data['repeat'], f.cleaned_until, f.cleaned_data['description']) revision.comment = get_rev_comment(request, b, "blackout") return HttpResponseRedirect(urlRedirect) else: b = Blackout.objects.get(id = b_id) if b_id is not None else None if request.GET.get('_method', '') == "DELETE" and b is not None: b.delete() return HttpResponseRedirect(urlRedirect) f = BlackoutForm.initialize(b, tz) if b is not None else BlackoutForm() blackoutUrl = "%d/" % int(b_id) if b_id is not None else "" # the forms we render have different actions according to whether # these blackouts are for users or projects if kind == "project_blackout": for_name = forObj.pcode form_action = "/project/%s/blackout/%s" % (forObj.pcode, blackoutUrl) cancel_action = "/project/%s" % forObj.pcode else: for_name = forObj.display_name() form_action = "/profile/%d/blackout/%s" % (forObj.id, blackoutUrl) cancel_action = "/profile/%d" % forObj.id return render_to_response("users/blackout_form.html" , {'form' : f , 'b_id' : b_id , 'action' : form_action , 'cancel' : cancel_action , 'for_name' : for_name , 'tz' : tz , 'tz_form' : tz_form })