示例#1
0
def newfolder(request, tplname="webmail/folder.html"):
    mbc = IMAPconnector(user=request.user.username,
                        password=request.session["password"])
    ctx = {
        "title": _("Create a new mailbox"),
        "formid": "mboxform",
        "action": reverse(newfolder),
        "action_label": _("Create"),
        "action_classes": "submit",
        "withunseen": False,
        "selectonly": True,
        "mboxes": mbc.getmboxes(request.user)
    }

    if request.method == "POST":
        form = FolderForm(request.POST)
        if form.is_valid():
            pf = request.POST.get("parent_folder", None)
            mbc.create_folder(form.cleaned_data["name"], pf)
            return ajax_simple_response(
                dict(status="ok",
                     respmsg=_("Mailbox created"),
                     newmb=form.cleaned_data["name"],
                     parent=pf))

        ctx["form"] = form
        ctx["selected"] = None
        return ajax_response(request, status="ko", template=tplname, **ctx)

    ctx["form"] = FolderForm()
    ctx["selected"] = None
    return _render(request, tplname, ctx)
示例#2
0
def newfolder(request, tplname="webmail/folder.html"):
    mbc = IMAPconnector(user=request.user.username,
                        password=request.session["password"])
    ctx = {"title": _("Create a new mailbox"),
           "formid": "mboxform",
           "action": reverse(newfolder),
           "action_label": _("Create"),
           "action_classes": "submit",
           "withunseen": False,
           "selectonly": True,
           "mboxes": mbc.getmboxes(request.user),
           "hdelimiter": mbc.hdelimiter}

    if request.method == "POST":
        form = FolderForm(request.POST)
        if form.is_valid():
            pf = request.POST.get("parent_folder", None)
            mbc.create_folder(form.cleaned_data["name"], pf)
            return ajax_simple_response(dict(
                    status="ok", respmsg=_("Mailbox created"), newmb=form.cleaned_data["name"], parent=pf
                    ))

        ctx["form"] = form
        ctx["selected"] = None
        return ajax_response(request, status="ko", template=tplname, **ctx)

    ctx["form"] = FolderForm()
    ctx["selected"] = None
    return _render(request, tplname, ctx)
示例#3
0
 def get_response(self, request, *args, **kwargs):
     form = FolderForm(request.POST, request=request)
     if form.is_valid():
         form.save()
         return {'result': 'success'}
     else:
         return {'result': 'error', 'errors': get_list_of_errors(form)}
示例#4
0
def create_folder(request, internal=False):
    folder_form = FolderForm(request.POST or None)
    if folder_form is not None and folder_form.is_valid():
        title = folder_form.cleaned_data['title']
        owner = Searcher.objects.filter(user_profile=request.user)[0]
        new_folder = Folder(title=title, owner=owner)
        new_folder.save()
    else:
        print "error"
    if internal:
        return new_folder
示例#5
0
def create_folder(request, share, subdir=None):
    form = FolderForm(request.POST)
    data = json_form_validate(form)
    if form.is_valid():
        folder_path = share.create_folder(form.cleaned_data['name'],subdir)
        (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(folder_path)
        data['objects']=[{'name':form.cleaned_data['name'],'modified':datetime.datetime.fromtimestamp(mtime).strftime("%m/%d/%Y %I:%M %p")}]
        ShareLog.create(share=share,user=request.user,action=ShareLog.ACTION_FOLDER_CREATED,paths=[form.cleaned_data['name']],subdir=subdir)
        return json_response(data)
    else:
        return json_error([error for name, error in form.errors.items()])
示例#6
0
def create_folder(request, share, subdir=None):
    form = FolderForm(request.POST)
    data = json_form_validate(form)
    if form.is_valid():
        folder_path = share.create_folder(form.cleaned_data['name'],subdir)
        (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(folder_path)
        data['objects']=[{'name':form.cleaned_data['name'],'modified':datetime.datetime.fromtimestamp(mtime).strftime("%m/%d/%Y %I:%M %p")}]
        ShareLog.create(share=share,user=request.user,action=ShareLog.ACTION_FOLDER_CREATED,paths=[form.cleaned_data['name']],subdir=subdir)
        return json_response(data)
    else:
        return json_error([error for name, error in form.errors.items()])
示例#7
0
文件: views.py 项目: qsnipp/dartcms
 def get_response(self, request, *args, **kwargs):
     form = FolderForm(request.POST, request=request)
     if form.is_valid():
         form.save()
         return {
             'result': 'success'
         }
     else:
         return {
             'result': 'error',
             'errors': get_list_of_errors(form)
         }
示例#8
0
    def get_response(self, request, *args, **kwargs):
        try:
            folder = Folder.objects.get(pk=request.POST.get('folder_id', 0))
        except Folder.DoesNotExist:
            raise Http404

        form = FolderForm(request.POST, request=request, instance=folder)
        if form.is_valid():
            form.save()
            return {'result': 'success'}
        else:
            return {'result': 'error', 'errors': get_list_of_errors(form)}
示例#9
0
文件: views.py 项目: 4416/hazel-cms
def add_folder(request):
    form = FolderForm(request.form)
    if request.method == 'POST' and form.validate():
        layout = Layout.add(name=form.name.data,
                            slug=slugify(form.name.data),
                            author=users.get_current_user(),
                            type=FOLDER)
        if form.save.data is True:
            return redirect(url_for('nut:layouts/list'), 301)
        if form.cont.data is True:
            return redirect(url_for('nut:layouts/edit', key=layout.get_key()), 301)
    return render_template('app:layouts/form.html', form=form)
示例#10
0
def create_fr(req):
    username = req.COOKIES.get('username', '')
    if req.method == "POST":
        ff = FolderForm(req.POST)
        if ff.is_valid():
            folder_name = ff.cleaned_data['folder_name']
            description = ff.cleaned_data['description']
            create_time = timezone.now()
            modify_time = timezone.now()
            #写入数据库
            f = User.objects.get(username=username)
            f.folder_set.create(folder_name=folder_name, create_time=create_time, modify_time=modify_time, description=description)
            return HttpResponseRedirect('/online/index/')
    else:
        ff = FolderForm()
    return render(req, 'create_folder_new.html', {'ff': ff})
示例#11
0
def editfolder(request, tplname="webmail/folder.html"):
    mbc = IMAPconnector(user=request.user.username,
                        password=request.session["password"])
    ctx = {
        "title": _("Edit mailbox"),
        "formid": "mboxform",
        "action": reverse(editfolder),
        "action_label": _("Update"),
        "action_classes": "submit",
        "withunseen": False,
        "selectonly": True
    }

    if request.method == "POST":
        form = FolderForm(request.POST)
        if form.is_valid():
            pf = request.POST.get("parent_folder", None)
            ctx["selected"] = pf
            oldname, oldparent = separate_mailbox(request.POST["oldname"])
            res = dict(status="ok", respmsg=_("Mailbox updated"))
            if form.cleaned_data["name"] != oldname \
                    or (pf != oldparent):
                newname = form.cleaned_data["name"] if pf is None \
                    else "%s.%s" % (pf, form.cleaned_data["name"])
                mbc.rename_folder(request.POST["oldname"], newname)
                res["oldmb"] = oldname
                res["newmb"] = form.cleaned_data["name"]
                res["oldparent"] = oldparent
                res["newparent"] = pf
                if "mbox" in request.session:
                    del request.session["mbox"]
            return ajax_simple_response(res)

        ctx["mboxes"] = mbc.getmboxes(request.user)
        ctx["form"] = form
        return ajax_response(request, status="ko", template=tplname, **ctx)

    name = request.GET.get("name", None)
    if name is None:
        raise WebmailError(_("Invalid request"))
    shortname, parent = separate_mailbox(name)
    ctx["mboxes"] = mbc.getmboxes(request.user, until_mailbox=parent)
    ctx["form"] = FolderForm()
    ctx["form"].fields["oldname"].initial = name
    ctx["form"].fields["name"].initial = shortname
    ctx["selected"] = parent
    return _render(request, tplname, ctx)
示例#12
0
def editfolder(request, tplname="webmail/folder.html"):
    mbc = IMAPconnector(user=request.user.username,
                        password=request.session["password"])
    ctx = {"title" : _("Edit mailbox"),
           "formid" : "mboxform",
           "action" : reverse(editfolder),
           "action_label" : _("Update"),
           "action_classes" : "submit",
           "withunseen" : False,
           "selectonly" : True,
           "hdelimiter": mbc.hdelimiter}

    if request.method == "POST":
        form = FolderForm(request.POST)
        if form.is_valid():
            pf = request.POST.get("parent_folder", None)
            ctx["selected"] = pf
            oldname, oldparent = separate_mailbox(request.POST["oldname"], sep=mbc.hdelimiter)
            res = dict(status="ok", respmsg=_("Mailbox updated"))
            if form.cleaned_data["name"] != oldname \
                    or (pf != oldparent):
                newname = form.cleaned_data["name"] if pf is None \
                    else "%s.%s" % (pf, form.cleaned_data["name"])
                mbc.rename_folder(request.POST["oldname"], newname)
                res["oldmb"] = oldname
                res["newmb"] = form.cleaned_data["name"]
                res["oldparent"] = oldparent
                res["newparent"] = pf
                if "mbox" in request.session:
                    del request.session["mbox"]
            return ajax_simple_response(res)

        ctx["mboxes"] = mbc.getmboxes(request.user)
        ctx["form"] = form
        return ajax_response(request, status="ko", template=tplname, **ctx)

    name = request.GET.get("name", None)
    if name is None:
        raise WebmailError(_("Invalid request"))
    shortname, parent = separate_mailbox(name, sep=mbc.hdelimiter)
    ctx["mboxes"] = mbc.getmboxes(request.user, until_mailbox=parent)
    ctx["form"] = FolderForm()
    ctx["form"].fields["oldname"].initial = name
    ctx["form"].fields["name"].initial = shortname
    ctx["selected"] = parent
    return _render(request, tplname, ctx)
示例#13
0
文件: views.py 项目: qsnipp/dartcms
    def get_response(self, request, *args, **kwargs):
        try:
            folder = Folder.objects.get(pk=request.POST.get('folder_id', 0))
        except Folder.DoesNotExist:
            raise Http404

        form = FolderForm(request.POST, request=request, instance=folder)
        if form.is_valid():
            form.save()
            return {
                'result': 'success'
            }
        else:
            return {
                'result': 'error',
                'errors': get_list_of_errors(form)
            }
示例#14
0
def add_folder(request):
    id = request.GET.get('id', None)
    if id is not None:
        folder = get_object_or_404(Folder, id=id)
    else:
        folder = None

    if request.method == 'POST':
        if request.POST.get('control') == 'delete':
            folder.delete()
            messages.add_message(request, messages.INFO, "Folder deleted")
            return HttpResponseRedirect(reverse('notes:index'))

        form = FolderForm(request.POST, instance=folder)
        if form.is_valid():
            form.save()
            messages.add_message(request, messages.INFO, "Folder added")
            return HttpResponseRedirect(reverse('notes:index'))
    else:
        form = FolderForm(instance=folder)

    return render(request, 'notes/addfolder.html', {
        'form': form,
        'folder': folder
    })
示例#15
0
文件: views.py 项目: wcl19940217/disk
def create_fr(req):
    username = req.COOKIES.get('username', '')
    if req.method == "POST":
        ff = FolderForm(req.POST)
        if ff.is_valid():
            folder_name = ff.cleaned_data['folder_name']
            description = ff.cleaned_data['description']
            create_time = timezone.now()
            modify_time = timezone.now()
            #写入数据库
            f = User.objects.get(username=username)
            f.folder_set.create(folder_name=folder_name,
                                create_time=create_time,
                                modify_time=modify_time,
                                description=description)
            return HttpResponseRedirect('/online/index/')
    else:
        ff = FolderForm()
    return render(req, 'create_folder_new.html', {'ff': ff})
示例#16
0
def folder_edit(request, folder_id, response_format='html'):
    "Folder edit page"

    folder = get_object_or_404(Folder, pk=folder_id)

    if not request.user.profile.has_permission(folder, mode='w'):
        return user_denied(request, message="You don't have access to this Folder")

    if request.POST:
        if 'cancel' not in request.POST:
            form = FolderForm(
                request.user.profile, folder_id, request.POST, instance=folder)
            if form.is_valid():
                folder = form.save()
                return HttpResponseRedirect(reverse('documents_folder_view', args=[folder.id]))
        else:
            return HttpResponseRedirect(reverse('documents_folder_view', args=[folder.id]))

    else:
        form = FolderForm(
            request.user.profile, folder_id, instance=folder)

    context = _get_default_context(request)
    context.update({'form': form,
                    'folder': folder})

    return render_to_response('documents/folder_edit', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#17
0
def folder_add_typed(request, folder_id=None, response_format='html'):
    "Folder add to preselected folder"

    folder = None
    if folder_id:
        folder = get_object_or_404(Folder, pk=folder_id)
        if not request.user.profile.has_permission(folder, mode='x'):
            folder = None

    if request.POST:
        if 'cancel' not in request.POST:
            folder = Folder()
            form = FolderForm(
                request.user.profile, folder_id, request.POST, instance=folder)
            if form.is_valid():
                folder = form.save()
                folder.set_user_from_request(request)
                return HttpResponseRedirect(reverse('documents_folder_view', args=[folder.id]))
        else:
            return HttpResponseRedirect(reverse('document_index'))
    else:
        form = FolderForm(request.user.profile, folder_id)

    context = _get_default_context(request)
    context.update({'form': form,
                    'folder': folder})

    return render_to_response('documents/folder_add_typed', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#18
0
def folder_add(request, response_format='html'):
    "New folder form"

    if request.POST:
        if 'cancel' not in request.POST:
            folder = Folder()
            form = FolderForm(
                request.user.profile, None, request.POST, instance=folder)
            if form.is_valid():
                folder = form.save()
                folder.set_user_from_request(request)
                return HttpResponseRedirect(reverse('documents_folder_view', args=[folder.id]))
        else:
            return HttpResponseRedirect(reverse('document_index'))
    else:
        form = FolderForm(request.user.profile, None)

    context = _get_default_context(request)
    context.update({'form': form})

    return render_to_response('documents/folder_add', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#19
0
def list_directory(request,share,subdir=None):
    if not share.check_path(subdir=subdir):
        return render(request,'error.html', {"message": "Unable to locate the files.  It is possible that the directory has been moved, renamed, or deleted.","share":share,"subdir":subdir})
    files,directories = list_share_dir(share,subdir=subdir,ajax=request.is_ajax())
    print files
    if request.is_ajax():
        return json_response({'files':files,'directories':directories.values()})
    #Find any shares that point at this directory
    for s in Share.user_queryset(request.user).filter(real_path__in=directories.keys()).exclude(id=share.id):
        directories[s.real_path]['share']=s
    share_perms = share.get_user_permissions(request.user)
    PATH = share.get_path()
    subshare = None
    if subdir is not None:
        PATH = os.path.join(PATH,subdir)
        subshare = Share.objects.filter(parent=share,sub_directory=subdir).first()
    owner = request.user == share.owner
    all_perms = share.get_permissions(user_specific=True)
    shared_users = all_perms['user_perms'].keys()
    shared_groups = [g['group']['name'] for g in all_perms['group_perms']]
    emails = sorted([u.email for u in share.get_users_with_permissions()])
    readme = None
    #The following block is for markdown rendering
    if os.path.isfile(os.path.join(PATH,'README.md')):
        import markdown
        input_file = codecs.open(os.path.join(PATH,'README.md'), mode="r", encoding="utf-8")
        text = input_file.read()
        readme = markdown.markdown(text,extensions=['fenced_code','tables','nl2br'])
        download_base = reverse('download_file',kwargs={'share':share.id,'subpath':subdir if subdir else ''})
        readme = re.sub(r'src="(?!http)',r'src="{0}'.format(download_base),readme)
    return render(request,'list.html', {"session_cookie":request.COOKIES.get('sessionid'),"files":files,"directories":directories.values(),"path":PATH,"share":share,"subshare":subshare,"subdir": subdir,'rsync_url':get_setting('RSYNC_URL',None),'HOST':get_setting('HOST',None),'SFTP_PORT':get_setting('SFTP_PORT',None),"folder_form":FolderForm(),"metadata_form":MetaDataForm(), "rename_form":RenameForm(),"request":request,"owner":owner,"share_perms":share_perms,"all_perms":all_perms,"share_perms_json":json.dumps(share_perms),"shared_users":shared_users,"shared_groups":shared_groups,"emails":emails, "readme":readme})