Exemple #1
0
def add_attachment(request,
                   app_label,
                   module_name,
                   pk,
                   template_name='attachments/add.html',
                   extra_context={}):

    next = request.POST.get('next', '/')
    model = get_model(app_label, module_name)
    if model is None:
        return HttpResponseRedirect(next)
    obj = get_object_or_404(model, pk=pk)
    form = AttachmentForm(request.POST, request.FILES)

    if form.is_valid():
        form.save(request, obj)
        messages.success(request, ugettext('Your attachment was uploaded.'))
        return HttpResponseRedirect(next)
    else:
        template_context = {
            'form': form,
            'form_url': add_url_for_obj(obj),
            'next': next,
        }
        template_context.update(extra_context)
        return render_to_response(template_name, template_context,
                                  RequestContext(request))
 def get_form(self, context):
     obj = self.get_object(context)
     if obj:
         f = AttachmentForm()
         f.form_url = add_url_for_obj(obj)
         return f
     else:
         return None
def attachment_form(context, obj):
    """
    Renders a "upload attachment" form
    """
    return {
        'form': AttachmentForm(),
        'form_url': add_url_for_obj(obj),
        'next': context['request'].build_absolute_uri(),
    }
def attachment_form(context, obj):
    """
    Renders a "upload attachment" form
    """
    if context['request'].user.is_authenticated():
        return {
            'form': AttachmentForm(),
            'form_url': add_url_for_obj(obj),
            'next': context['request'].build_absolute_uri(),
        }
    else:
        return {
            'form': None,
        }
def attachment_form(context, obj):
    """
    Renders a "upload attachment" form.
    
    The user must own ``attachments.add_attachment permission`` to add
    attachments.
    """
    if context["user"].has_perm("attachments.add_attachment"):
        return {
            "form": AttachmentForm(),
            "form_url": add_url_for_obj(obj),
            "next": context["request"].build_absolute_uri(),
        }
    else:
        return {"form": None}
Exemple #6
0
 def render(self, context):
     ctype, object_id = self.get_target_ctype_pk(context)
     obj = self.get_object(context)
     if object_id:
         template_search_list = ["attachments/add_form.html"]
         context.push()
         formstr = render_to_string(
             template_search_list, {
                 'form': self.get_form(context),
                 'form_url': add_url_for_obj(obj),
                 'object_id': obj.id
             }, context)
         context.pop()
         return formstr
     else:
         return ''
def attachment_form(context, obj):
    """
    Renders a "upload attachment" form.

    The user must own ``attachments.add_attachment permission`` to add
    attachments.
    """
    if context['user'].has_perm('attachments.add_attachment'):
        return {
            'form': AttachmentForm(),
            'form_url': add_url_for_obj(obj),
            'next': context['request'].build_absolute_uri(),
        }
    else:
        return {
            'form': None,
        }
def attachment_form(context, obj):
    """
    Renders a "upload attachment" form.
    
    The user must own ``attachments.add_attachment permission`` to add
    attachments.
    """
    if context['user'].has_perm('attachments.add_attachment'):
        return {
            'form': AttachmentForm(),
            'form_url': add_url_for_obj(obj),
            'next': context['request'].build_absolute_uri(),
        }
    else:
        return {
            'form': None,
        }
def formcontext(context, obj, Form=AttachmentForm):
    """
    Renders an "upload attachment" form, with a configurable Form class.
    only renders the form if the user owns 
    ``attachments.add_attachment permission``

    args:
        Form: The form to render to the user.
        context: request context
        obj: the object that this attachment will be attached to.
    """
    if context['user'].has_perm('attachments.add_attachment'):
        return {
            'form': Form(),
            'form_url': add_url_for_obj(obj),
            'next': context['request'].build_absolute_uri(), }
    else:
        return {'form': None,}
Exemple #10
0
def formcontext(context, obj, Form=AttachmentDisplayNameForm):
    """
    Renders an "upload attachment" form, with a configurable Form class.
    only renders the form if the user owns 
    ``attachments.add_attachment permission``

    args:
        Form: The form to render to the user.
        context: request context
        obj: the object that this attachment will be attached to.
    """
    if context['user'].has_perm('attachments.add_attachment'):
        return {
            'form': Form(),
            'form_url': add_url_for_obj(obj),
            'next': context['request'].build_absolute_uri(), }
    else:
        return {'form': None,}
def attachment_form(context, obj, category=''):
    """
    Renders a "upload attachment" form.

    The user must own ``attachments.add_attachment permission`` to add
    attachments.
    """
    if context['user'].has_perm('attachments.add_attachment'):

        if category in categories:
            category = categories[category]
        else:
            category = Attachment.DEFAULT

        return {
            'form': AttachmentForm(initial={'category': category}),
            'form_url': add_url_for_obj(obj),
            'next': context.request.build_absolute_uri(),
        }
    else:
        return {
            'form': None,
        }
Exemple #12
0
def add_attachment(request, app_label, module_name, pk,
                   template_name='attachments/add.html', extra_context={}):

    next = request.POST.get('next', '/')
    model = get_model(app_label, module_name)
    if model is None:
        return HttpResponseRedirect(next)
    obj = get_object_or_404(model, pk=pk)
    form = AttachmentForm(request.POST, request.FILES)

    if form.is_valid():
        form.save(request, obj)
        messages.success(request, ugettext('Your attachment was uploaded.'))
        return HttpResponseRedirect(next)
    else:
        template_context = {
            'form': form,
            'form_url': add_url_for_obj(obj),
            'next': next,
        }
        template_context.update(extra_context)
        return render_to_response(template_name, template_context,
                                  RequestContext(request))
def attachment_form(context, obj):
    """
    Renders a "upload attachment" form.
    
    If "next" is set in the context will be used as redirect after upload.

    The user must own ``attachments.add_attachment permission`` to add
    attachments.
    """
    try:
        next = Variable('next').resolve(context)
    except VariableDoesNotExist:
        next = context['request'].build_absolute_uri(),
    if context['user'].has_perm('attachments.add_attachment'):
        return {
            'form': AttachmentForm(),
            'form_url': add_url_for_obj(obj),
            'next': next,
        }
    else:
        return {
            'form': None,
        }
Exemple #14
0
 def render(self, context):
     obj = self.get_object(context)
     context[self.as_varname] = self.get_form(context)
     context['form_url'] = add_url_for_obj(obj)
     context['object_id'] = obj.id
     return ''