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}
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,}
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, }