示例#1
0
def tag(slug):
    """Retrieve items of the tag"""
    tag = Tag.get_item_by_slug(slug)
    items = TagRelation.get_items_by_tag_id(tag.id)
    tags = Tag.get_items()

    return render_template("tag/tag.html", tags=tags, tag=tag, items=items)
示例#2
0
def theme_single(slug):
    """Return an item"""
    item = db.session.query(Theme).filter_by(slug=slug).one()
    item_categories = db.session.query(CategoryRelation) \
        .filter_by(theme_id=item.id).all()
    item_tags = db.session.query(TagRelation) \
        .filter_by(theme_id=item.id).all()

    return render_template("theme/theme-single.html",
                           item=item,
                           categories=Category.get_items(),
                           item_categories=item_categories,
                           tags=Tag.get_items(),
                           item_tags=item_tags)
示例#3
0
def tag_edit(tag_id):
    """Edit Tag"""
    tag = Tag.get_item_by_id(tag_id)
    if tag is None:
        abort(404)
    else:
        if request.method == "POST":
            tag.name = request.form["name"]
            tag.slug = request.form["slug"]

            db.session.add(tag)
            db.session.commit()

        return render_template("tag/tag-edit.html",
                               tag=tag,
                               tags=Tag.get_items())
示例#4
0
def tag_add():
    """Register new tag"""

    if request.method == "POST":
        # Define variables
        name = request.form.get('name')
        slug = request.form.get('slug')
        if slug == "":
            slug = slugify(name)

        tag_exists = Tag.get_item_by_slug(slug) is not None
        if not tag_exists:
            # Add new item to database
            item = Tag.add(name, slug)
            # Redirect to add tag page
            return redirect(url_for("tag_add"))
        else:
            flash('Tag already exists.')

    # Render tag-add.html and serve page
    return render_template("tag/tag-add.html", tags=Tag.get_items())
示例#5
0
def theme_edit(item_id):
    """Edit an item"""
    item = db.session.query(Theme) \
        .filter_by(id=item_id).first_or_404()

    if request.method == "POST":
        # Edit item
        if item.title != request.form["title"]:
            item.title = request.form["title"]

        if item.slug != request.form["slug"]:
            # Rename theme image folder
            theme_author_folder = os.path.join(app.config['UPLOAD_FOLDER'],
                                               item.theme_author.slug)
            theme_upload_folder = os.path.join(theme_author_folder, item.slug)
            theme_upload_new_folder = os.path.join(theme_author_folder,
                                                   request.form["slug"])
            image_preview = os.path.join(theme_upload_new_folder,
                                         item.slug + '-preview.jpg')
            image_preview_new = os.path.join(
                theme_upload_new_folder, request.form["slug"] + '-preview.jpg')
            image_screenshot = os.path.join(theme_upload_new_folder,
                                            item.slug + '-screenshot.jpg')
            image_screenshot_new = os.path.join(
                theme_upload_new_folder,
                request.form["slug"] + '-screenshot.jpg')

            os.rename(theme_upload_folder, theme_upload_new_folder)
            os.rename(image_preview, image_preview_new)
            os.rename(image_screenshot, image_screenshot_new)

            item.slug = request.form["slug"]

        if item.description != request.form["description"]:
            item.description = request.form["description"]

        if item.content != request.form["content"]:
            item.content = request.form["content"]

        if item.features != request.form["features"]:
            item.features = request.form["features"]

        if item.meta_title != request.form.get('meta_title'):
            item.meta_title = request.form.get('meta_title')

        if item.meta_description != request.form.get('meta_description'):
            item.meta_description = request.form.get('meta_description')

        if item.slogan != request.form.get('slogan'):
            item.slogan = request.form.get('slogan')

        if item.preview_url != request.form.get('preview_url'):
            item.preview_url = request.form.get('preview_url')

        if item.download_url != request.form.get('download_url'):
            item.download_url = request.form.get('download_url')

        if item.github_url != request.form.get('github_url'):
            item.github_url = request.form.get('github_url')

        if item.license_url != request.form.get('license_url'):
            item.license_url = request.form.get('license_url')

        if item.license_type_id != request.form.get('license_type'):
            item.license_type_id = request.form.get('license_type')

        # if item.date != request.form.get('date'):
        # item.date = request.form.get('date')
        # item.date = datetime.datetime.utcnow()
        # if item.last_modified_at != request.form.get('last_modified_at'):
        # item.last_modified_at = datetime.datetime.utcnow()

        # if item.theme_author != request.form.get('theme_author'):
        #     item.theme_author_id = request.form.get('theme_author')
        # item.user_id = session["user_id"]

        db.session.add(item)
        db.session.commit()

        # Update Selected Theme's Count
        Theme.update_theme_author_count(item.theme_author_id)

        # Update Selected Licence Type's count
        Theme.update_license_type_count(item.license_type_id)

        # check if the post request has the file part
        if 'image_preview' in request.files:
            file = request.files['image_preview']
            if file and img.allowed_file(file.filename):
                img.upload_theme_image(item, file, 'preview')

        # check if the post request has the file part
        if 'image_screenshot' in request.files:
            file = request.files['image_screenshot']
            if file and img.allowed_file(file.filename):
                img.upload_theme_image(item, file, 'screenshot')

        Category.add_or_update_category(request.form.getlist('category'),
                                        item_id)
        Tag.add_or_update_tag(request.form.getlist('tag'), item_id)

    item_categories = db.session.query(CategoryRelation.category_id) \
        .filter_by(theme_id=item_id).all()
    item_tags = db.session.query(TagRelation.tag_id) \
        .filter_by(theme_id=item_id).all()

    return render_template(
        "theme/theme-edit.html",
        item=item,
        categories=Category.get_items(),
        item_categories=json.dumps(item_categories),
        tags=Tag.get_items(),
        item_tags=json.dumps(item_tags),
        theme_authors=ThemeAuthor.get_items(),
        license_types=LicenseType.get_items(),
        img_preview_exists=img.img_preview_exists(item),
        img_screenshot_exists=img.img_screenshot_exists(item))
示例#6
0
def theme_add():
    """Register new item"""
    if request.method == "POST":
        title = request.form.get('title')
        # Slugify the name if slug is empty
        slug = request.form.get('slug')
        if slug == "":
            slug = slugify(title)

        if db.session.query(Theme).filter_by(slug=slug).count() >= 1:
            flash('Please change slug. The same url exists!')

        if request.form.get('license_type') == "":
            flash('License type can not be empty')

        if request.form.get('theme_author') == "":
            flash('Theme author can not be empty')

        item = Theme.add(title=request.form.get('title'),
                         slug=slug,
                         description=request.form.get('description'),
                         content=request.form.get('content'),
                         features=request.form.get('features'),
                         meta_title=request.form.get('meta_title'),
                         meta_description=request.form.get('meta_description'),
                         slogan=request.form.get('slogan'),
                         preview_url=request.form.get('preview_url'),
                         download_url=request.form.get('download_url'),
                         github_url=request.form.get('github_url'),
                         license_url=request.form.get('license_url'),
                         license_type_id=request.form.get('license_type'),
                         theme_author_id=request.form.get('theme_author'),
                         user_id=session["user_id"])

        # Update Selected Theme's Count
        # Theme.update_theme_author_count(item.theme_author_id)

        # Update Selected Licence Type's count
        # Theme.update_license_type_count(item.license_type_id)

        # check if the post request has the file part
        if 'image_preview' in request.files:
            file = request.files['image_preview']
            if file != '' and img.allowed_file(file.filename):
                img.upload_theme_image(item, file, 'preview')

        # check if the post request has the file part
        if 'image_screenshot' in request.files:
            file = request.files['image_screenshot']
            if file != '' and img.allowed_file(file.filename):
                img.upload_theme_image(item, file, 'screenshot')

        Category.add_or_update_category(request.form.getlist('category'),
                                        item.id)
        Tag.add_or_update_tag(request.form.getlist('tag'), item.id)

    return render_template("theme/theme-add.html",
                           categories=Category.get_items(),
                           tags=Tag.get_items(),
                           license_types=LicenseType.get_items(),
                           theme_authors=ThemeAuthor.get_items())