Пример #1
0
def group_edit(request, facility, group_id):
    group = get_object_or_None(FacilityGroup, id=group_id)
    facility = facility or (group and group.facility)

    if request.method != 'POST':
        form = FacilityGroupForm(facility, instance=group)

    else:
        form = FacilityGroupForm(facility, data=request.POST, instance=group)
        if not form.is_valid():
            messages.error(
                request,
                _("Failed to save the group; please review errors below."))
        else:
            form.save()

            redir_url = request.next or request.GET.get("prev") or reverse(
                "add_facility_student")
            redir_url = set_query_params(redir_url, {
                "facility": facility.pk,
                "group": form.instance.pk
            })
            return HttpResponseRedirect(redir_url)

    return {
        "form": form,
        "group_id": group_id,
        "facility": facility,
        "singlefacility": request.session["facility_count"] == 1,
        "title":
        _("Add a new group") if group_id == 'new' else _("Edit group"),
    }
Пример #2
0
def group_edit(request, facility, group_id):
    group = get_object_or_None(FacilityGroup, id=group_id)
    facility = facility or (group and group.facility)

    if request.method != 'POST':
        form = FacilityGroupForm(facility, instance=group)

    else:
        form = FacilityGroupForm(facility, data=request.POST, instance=group)
        if not form.is_valid():
            messages.error(request, _("Failed to save the group; please review errors below."))
        else:
            form.save()

            redir_url = request.next or request.GET.get("prev") or reverse("add_facility_student")
            redir_url = set_query_params(redir_url, {"facility": facility.pk, "group": form.instance.pk})
            return HttpResponseRedirect(redir_url)

    return {
        "form": form,
        "group_id": group_id,
        "facility": facility,
        "singlefacility": request.session["facility_count"] == 1,
        "title": _("Add a new group") if group_id == 'new' else _("Edit group"),
    }
Пример #3
0
    def get_registration_url(self, **kwargs):

        if "device_key" not in kwargs:
            kwargs["device_key"] = urllib.quote(
                Device.get_own_device().public_key)

        return self.path_to_url(
            set_query_params(reverse("register_public_key"), kwargs))
Пример #4
0
 def real_decorator_wrapper_fn(request, *args, **kwargs):
     if Device.get_own_device().is_registered():
         return handler(request, *args, **kwargs)
     else:
         messages.warning(request, _("In order to access %(resource_name)s, you must register your device first." % {"resource_name": unicode(resource_name)}))
         return HttpResponseRedirect(
             set_query_params(reverse('register_public_key'), {'next': request.path})
         )
Пример #5
0
def handler_403(request, *args, **kwargs):
    context = RequestContext(request)
    #message = None  # Need to retrieve, but can't figure it out yet.

    if request.is_ajax():
        return JsonResponseMessageError(_("You must be logged in with an account authorized to view this page (API)."), status=403)
    else:
        messages.error(request, mark_safe(_("You must be logged in with an account authorized to view this page.")))
        return HttpResponseRedirect(set_query_params(reverse("homepage"), {"next": request.get_full_path(), "login": True}))
Пример #6
0
def handler_403(request, *args, **kwargs):
    context = RequestContext(request)
    #message = None  # Need to retrieve, but can't figure it out yet.

    if request.is_ajax():
        return JsonResponseMessageError(_("You must be logged in with an account authorized to view this page (API)."), status=403)
    else:
        messages.error(request, mark_safe(_("You must be logged in with an account authorized to view this page.")))
        return HttpResponseRedirect(set_query_params(reverse("homepage"), {"next": request.get_full_path(), "login": True}))
Пример #7
0
def update_all_distributed(request):
    """
    """
    logging.debug("Getting Khan Academy data.")

    return HttpResponseRedirect(set_query_params(CENTRAL_SERVER_URL + CENTRAL_UPDATE_ALL_PATH, {
        "callback": request.build_absolute_uri(reverse("update_all_distributed_callback")),
        "user_id": request.session["facility_user"].id,
    }))
Пример #8
0
 def real_decorator_wrapper_fn(request, *args, **kwargs):
     if Device.get_own_device().is_registered() or not am_i_online():
         return handler(request, *args, **kwargs)
     else:
         messages.warning(
             request,
             _("In order to access %(resource_name)s, you must register your device first."
               % {"resource_name": unicode(resource_name)}))
         return HttpResponseRedirect(
             set_query_params(reverse('register_public_key'),
                              {'next': request.path}))
Пример #9
0
    def get_registration_url(self, **kwargs):

        if "device_key" not in kwargs:
            kwargs["device_key"] = urllib.quote(Device.get_own_device().public_key)

        return self.path_to_url(set_query_params(reverse("register_public_key"), kwargs))