当前位置: 首页>>代码示例>>Python>>正文


Python File.slug方法代码示例

本文整理汇总了Python中models.File.slug方法的典型用法代码示例。如果您正苦于以下问题:Python File.slug方法的具体用法?Python File.slug怎么用?Python File.slug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.File的用法示例。


在下文中一共展示了File.slug方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: files

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import slug [as 别名]
def files():
    if request.method == "POST" and g.site.domain == g.user:
        reqfile = request.files["file"]
        f = File()
        f.site = g.site.domain
        f.name = reqfile.filename
        f.slug = secure_filename(f.name)
        f.content_type = reqfile.mimetype
        f.slug, f.content_length = save_file(reqfile, app.config["UPLOAD_FOLDER"])
        f.save()

    files = File.objects(site=g.site.domain)
    return render_template("files.html", files=files)
开发者ID:sigurdga,项目名称:samklang,代码行数:15,代码来源:app.py

示例2: edit_post

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import slug [as 别名]
def edit_post(year, month, day, slug):
    try:
        p = Post.objects.get(site=g.site.domain, year=year, month=month, day=day, slug=slug)
    except Post.DoesNotExist:
        abort(404)

    if not g.site.domain == g.user:
        abort(403)

    if request.method == "POST":
        reqfile = request.files.get("file")
        if reqfile:
            f = File()
            f.site = g.site.domain
            f.name = reqfile.filename
            f.content_type = reqfile.mimetype
            f.slug, f.content_length = save_file(reqfile, current_app.config["UPLOAD_FOLDER"])
            f.save()

        p.name = request.form.get("name")
        p.text = request.form.get("text")
        if reqfile:
            p.image_slug = f.slug
        p.save()
        return redirect(url_for("post", year=p.year, month=p.month, day=p.day, slug=p.slug))

    return render_template("edit_post.html", post=p)
开发者ID:sigurdga,项目名称:samklang,代码行数:29,代码来源:blog.py

示例3: edit_person

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import slug [as 别名]
def edit_person(slug):
    try:
        p = Person.objects.get(site=g.site.domain, slug=slug)
    except Person.DoesNotExist:
        abort(404)

    if not g.site.domain == g.user:
        abort(403)

    if request.method == "POST":
        reqfile = request.files.get('file')
        if reqfile:
            f = File()
            f.site = g.site.domain
            f.name = reqfile.filename
            f.content_type = reqfile.mimetype
            f.slug, f.content_length = save_file(reqfile, request.config["UPLOAD_FOLDER"])
            f.save()

        p.name = request.form.get("name")
        p.title = request.form.get("title")
        p.phone = request.form.get("phone")
        p.email = request.form.get("email")
        p.twitter = request.form.get("twitter")
        p.description = request.form.get("description")
        if reqfile:
            p.image_slug = f.slug
        p.save()
        return redirect(url_for(".show_person", slug=p.slug))

    return render_template("edit_person.html", person=p)
开发者ID:abal09,项目名称:samklang,代码行数:33,代码来源:personnel.py

示例4: new_person

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import slug [as 别名]
def new_person():
    if not g.site.domain == g.user:
        abort(403)

    p = Person()
    if request.method == "POST":
        reqfile = request.files.get('file')
        if reqfile:
            f = File()
            f.site = g.site.domain
            f.name = reqfile.filename
            f.content_type = reqfile.mimetype
            f.slug, f.content_length = save_file(reqfile, current_app.config["UPLOAD_FOLDER"])
            f.save()

        p.site = g.site.domain
        p.name = request.form.get("name")
        p.title = request.form.get("title")
        p.phone = request.form.get("phone")
        p.email = request.form.get("email")
        p.twitter = request.form.get("twitter")
        p.description = request.form.get("description")
        slugs = [ __p.slug for __p in Person.objects.filter(site=g.site.domain) ]
        slug = slugify(p.name)
        counter = 1
        __slug = slug
        while __slug in slugs:
            counter += 1
            __slug = "%s_%d" % (slug, counter)
        p.slug = __slug

        if reqfile:
            p.image_slug = f.slug
        p.save()

        pl = Personnel.objects.get(site=g.site.domain)
        pl.people.append(p.slug)
        pl.save()

        return redirect(url_for(".show_personnel"))
    return render_template("edit_person.html", person=p)
开发者ID:abal09,项目名称:samklang,代码行数:43,代码来源:personnel.py

示例5: new_post

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import slug [as 别名]
def new_post():
    if not g.site.domain == g.user:
        abort(403)

    p = Post()
    if request.method == "POST":
        reqfile = request.files.get("file")
        if reqfile:
            f = File()
            f.site = g.site.domain
            f.name = reqfile.filename
            f.content_type = reqfile.mimetype
            f.slug, f.content_length = save_file(reqfile, blog.config["UPLOAD_FOLDER"])
            f.save()

        import datetime

        p.site = g.site.domain
        p.name = request.form.get("name")
        p.created = datetime.datetime.utcnow()
        p.year = p.created.year
        p.month = p.created.month
        p.day = p.created.day
        slugs = [
            __j.slug
            for __j in Post.objects.filter(site=g.site.domain, year=p.year, month=p.month, day=p.day, slug=p.slug)
        ]
        counter = 1
        slug = slugify(p.name)
        __slug = slug
        while __slug in slugs:
            counter += 1
            __slug = "%s_%d" % (slug, counter)
        p.slug = __slug
        p.text = request.form.get("text")
        if reqfile:
            p.image_slug = f.slug
        p.save()
        return redirect(url_for("post", year=p.year, month=p.month, day=p.day, slug=p.slug))
    return render_template("edit_post.html", post=p)
开发者ID:sigurdga,项目名称:samklang,代码行数:42,代码来源:blog.py

示例6: upload

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import slug [as 别名]
def upload(request, name):
    if request.method == 'POST':
        if request.FILES is None:
            return HttpResponseBadRequest('No file[] found')

        file = request.FILES[u'files[]']
        wrapped_file = UploadedFile(file)
        filename = wrapped_file.name
        file_size = wrapped_file.file.size

        entry = File()
        entry.filename = unicode(filename)
        entry.username = unicode(name)
        entry.size = file_size
        entry.slug = generate_slug(8)
        entry.data = file
        entry.save()

        uploaded = [{'name': filename, 'size': filesizeformat(file_size), 'slug': entry.slug,
                     'date': entry.created.date().isoformat()}]

        return HttpResponse(json.dumps({'files': uploaded}))
    else:
        raise Http404
开发者ID:antofik,项目名称:meimew,代码行数:26,代码来源:views.py


注:本文中的models.File.slug方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。