Exemplo n.º 1
0
def get_xform(formid, request):
    try:
        formid = int(formid)
    except ValueError:
        xform = check_and_set_form_by_id_string(formid, request)
    else:
        xform = check_and_set_form_by_id(int(formid), request)

    if not xform:
        raise exceptions.PermissionDenied(
            _("You do not have permission to view data from this form."))

    return xform
Exemplo n.º 2
0
def get_xform(formid, request):
    try:
        formid = int(formid)
    except ValueError:
        xform = check_and_set_form_by_id_string(formid, request)
    else:
        xform = check_and_set_form_by_id(int(formid), request)

    if not xform:
        raise exceptions.PermissionDenied(_(
            "You do not have permission to view data from this form."))

    return xform
Exemplo n.º 3
0
def get_xform(formid, request, username=None):
    try:
        formid = int(formid)
    except ValueError:
        username = username is None and request.user.username
        xform = check_and_set_form_by_id_string(username, formid, request)
    else:
        xform = check_and_set_form_by_id(int(formid), request)

    if not xform:
        raise exceptions.PermissionDenied(t(
            "You do not have permission to view data from this form."))

    return xform
Exemplo n.º 4
0
def get_xform(formid, request, username=None):
    """
    Returns XForm instance if request.user has permissions to it otherwise it
    raises PermissionDenied() exception.
    """
    try:
        formid = int(formid)
    except ValueError:
        username = username is None and request.user.username
        xform = check_and_set_form_by_id_string(username, formid, request)
    else:
        xform = check_and_set_form_by_id(int(formid), request)

    if not xform:
        raise exceptions.PermissionDenied(
            _("You do not have permission to view data from this form."))

    return xform
Exemplo n.º 5
0
def get_xform(formid, request, username=None):
    """
    Returns XForm instance if request.user has permissions to it otherwise it
    raises PermissionDenied() exception.
    """
    try:
        formid = int(formid)
    except ValueError:
        username = username is None and request.user.username
        xform = check_and_set_form_by_id_string(username, formid, request)
    else:
        xform = check_and_set_form_by_id(int(formid), request)

    if not xform:
        raise exceptions.PermissionDenied(
            _("You do not have permission to view data from this form."))

    return xform
Exemplo n.º 6
0
    def labels(self, request, owner, formid, dataid, **kwargs):
        class TagForm(forms.Form):
            tags = TagField()

        if owner is None and not request.user.is_anonymous():
            owner = request.user.username
        xform = None
        try:
            xform = check_and_set_form_by_id(int(formid), request)
        except ValueError:
            xform = check_and_set_form_by_id_string(formid, request)
        if not xform:
            raise exceptions.PermissionDenied(
                _("You do not have permission to view data from this form."))
        status = 400
        instance = get_object_or_404(ParsedInstance, instance__pk=int(dataid))
        if request.method == 'POST':
            form = TagForm(request.DATA)
            if form.is_valid():
                tags = form.cleaned_data.get('tags', None)
                if tags:
                    for tag in tags:
                        instance.instance.tags.add(tag)
                    instance.save()
                    status = 201
        label = kwargs.get('label', None)
        if request.method == 'GET' and label:
            data = [
                tag['name'] for tag in instance.instance.tags.filter(
                    name=label).values('name')
            ]
        elif request.method == 'DELETE' and label:
            count = instance.instance.tags.count()
            instance.instance.tags.remove(label)
            # Accepted, label does not exist hence nothing removed
            if count == instance.instance.tags.count():
                status = 202
            data = list(instance.instance.tags.names())
        else:
            data = list(instance.instance.tags.names())
        if request.method == 'GET':
            status = 200
        return Response(data, status=status)
Exemplo n.º 7
0
 def labels(self, request, owner, formid, dataid, **kwargs):
     class TagForm(forms.Form):
         tags = TagField()
     if owner is None and not request.user.is_anonymous():
         owner = request.user.username
     xform = None
     try:
         xform = check_and_set_form_by_id(int(formid), request)
     except ValueError:
         xform = check_and_set_form_by_id_string(formid, request)
     if not xform:
         raise exceptions.PermissionDenied(
             _("You do not have permission to view data from this form."))
     status = 400
     instance = get_object_or_404(ParsedInstance, instance__pk=int(dataid))
     if request.method == 'POST':
         form = TagForm(request.DATA)
         if form.is_valid():
             tags = form.cleaned_data.get('tags', None)
             if tags:
                 for tag in tags:
                     instance.instance.tags.add(tag)
                 instance.save()
                 status = 201
     label = kwargs.get('label', None)
     if request.method == 'GET' and label:
         data = [
             tag['name'] for tag in
             instance.instance.tags.filter(name=label).values('name')]
     elif request.method == 'DELETE' and label:
         count = instance.instance.tags.count()
         instance.instance.tags.remove(label)
         # Accepted, label does not exist hence nothing removed
         if count == instance.instance.tags.count():
             status = 202
         data = list(instance.instance.tags.names())
     else:
         data = list(instance.instance.tags.names())
     if request.method == 'GET':
         status = 200
     return Response(data, status=status)