Beispiel #1
0
def attachments(request, tplname="webmail/attachments.html"):
    if request.method == "POST":
        csuploader = AttachmentUploadHandler()
        request.upload_handlers.insert(0, csuploader)
        error = None
        form = AttachmentForm(request.POST, request.FILES)
        if form.is_valid():
            try:
                fobj = request.FILES["attachment"]
                tmpname = save_attachment(fobj)
                request.session["compose_mail"]["attachments"] \
                    += [{"fname" : str(fobj),
                         "content-type" : fobj.content_type,
                         "size" : fobj.size,
                         "tmpname" : os.path.basename(tmpname)}]
                request.session.modified = True
                return _render(
                    request, "webmail/upload_done.html", {
                        "status": "ok",
                        "fname": request.FILES["attachment"],
                        "tmpname": os.path.basename(tmpname)
                    })
            except WebmailError, inst:
                error = _("Failed to save attachment: ") + str(inst)

        if csuploader.toobig:
            error = _("Attachment is too big (limit: %s)" \
                          % parameters.get_admin("MAX_ATTACHMENT_SIZE"))
        return _render(request, "webmail/upload_done.html", {
            "status": "ko",
            "error": error
        })
Beispiel #2
0
def _do_ajax_upload(request):
    data = {'valid': False, 'errors': ugettext('no file')}
    attachment_form = AttachmentForm(user=request.user)
    if request.method == "POST":
        attachment_form = AttachmentForm(request.POST, request.FILES, user=request.user, \
                actived=False)
        #TODO improve validate
        if attachment_form.is_valid():
            attachment = attachment_form.save()
            data['valid'] = True
            data.pop('errors')
            data['attachment'] = {'id': attachment.id, \
                    'fn': attachment.org_filename, 'url': attachment.file.url, 'descn': ''}
        else:
            #attachment_form.errors
            pass
    return data
def list_attachments(request, storyID):
    story = mdl_story.get_story(storyID)
    attachments = mdl_attachment.get_attachments_for_story(story)
    form = AttachmentForm()
    context = {
        'attachments': attachments,
        'newform': form,
        'story': story
    }
    return render(request, 'AttachmentForm.html', context)
Beispiel #4
0
def new_attachment(request,
                   attach_to=None,
                   template_name='uploads/new_upload.html',
                   extra_context={},
                   success_url=None):
    if attach_to is None: attach_to = request.user
    if request.method == 'POST':
        form = AttachmentForm(request.POST, request.FILES)
        if form.is_valid():
            success = form.save(request, attach_to)
            if success_url is not None:
                return HttpResponseRedirect(success_url)
            return HttpResponseRedirect(attach_to.get_absolute_url())
    else:
        form = AttachmentForm()

    data = {'form': form}
    data.update(extra_context)
    return render_to_response(template_name,
                              data,
                              context_instance=RequestContext(request))
Beispiel #5
0
            except WebmailError, inst:
                error = _("Failed to save attachment: ") + str(inst)

        if csuploader.toobig:
            error = _("Attachment is too big (limit: %s)" \
                          % parameters.get_admin("MAX_ATTACHMENT_SIZE"))
        return _render(request, "webmail/upload_done.html", {
            "status": "ko",
            "error": error
        })
    ctx = {
        "title": _("Attachments"),
        "formid": "uploadfile",
        "target": "upload_target",
        "enctype": "multipart/form-data",
        "form": AttachmentForm(),
        "action": reverse(attachments),
        "attachments": request.session["compose_mail"]["attachments"]
    }
    return _render(request, tplname, ctx)


@login_required
@needs_mailbox()
def delattachment(request):
    if not request.session.has_key("compose_mail") \
            or not request.GET.has_key("name") \
            or not request.GET["name"]:
        return ajax_response(request, "ko", respmsg=_("Bad query"))

    error = None