Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
    def post(self):
        fil = self.request.POST["file"]
        if not fil.value:
            self.redirect("/")
            return
        logging.getLogger().info("selected val %s" % self.request.POST["compression-type"])
        if self.request.POST["compression-type"] == "NONE":
            data = fil.value
        else:

            params = urllib.urlencode(
                [
                    ("js_code", fil.value),
                    ("compilation_level", self.request.POST["compression-type"]),
                    ("output_format", "text"),
                    ("output_info", "compiled_code"),
                ]
            )

            headers = {"Content-type": "application/x-www-form-urlencoded"}
            conn = httplib.HTTPConnection("closure-compiler.appspot.com")
            conn.request("POST", "/compile", params, headers)
            response = conn.getresponse()
            data = response.read()
            conn.close

        file = File()
        file.name = fil.filename
        file.file = db.Blob(data)
        file.content_type = fil.type
        file.user = users.get_current_user()
        file.put()

        self.redirect("/")
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
    def post(self):
        fil = self.request.POST["file"]
        if not fil.value:
            self.redirect("/")
            return

        file = File()
        file.name = fil.filename
        file.file = db.Blob(cssmin.cssmin(fil.value))
        file.original = db.Blob(fil.value)
        file.content_type = fil.type
        file.user = users.get_current_user()
        file.put()
        self.redirect("/")
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
0
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)
Ejemplo n.º 11
0
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)
Ejemplo n.º 12
0
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)