Пример #1
0
def theme_delete(item_id):
    """Remove an item"""

    if request.method == "POST":
        item = db.session.query(Theme).filter_by(id=item_id).one()
        if item is not None:
            item_id = item.id
            item_theme_author = item.theme_author_id
            item_license_type = item.license_type_id

            # Update category relations and counts
            Category.remove_category_relation(item_id)

            # Update tag relations and counts
            Tag.remove_tag_relation(item_id)

            # Remove Item
            db.session.delete(item)
            db.session.commit()

            # Update theme author items count
            Theme.update_theme_author_count(item_theme_author)

            # Update license types count
            Theme.update_license_type_count(item_license_type)

            return redirect(url_for("home"))

    return render_template("theme/theme-single.html",
                           term_id=term_id,
                           item_id=item_id,
                           item=item)
Пример #2
0
def get_complex_one(id):
	'''专题(Theme)详情接口
	:param id: 专题theme的id
	:return: 专题theme的详情
	'''
	theme_detail = Theme.get_theme_detail(id=id)
	return Success(theme_detail)
Пример #3
0
def get_simple_list():
    '''一组 ID 的专题(Theme)
	:arg /theme?ids=id1,id2,id3,...
	:return: 一组theme模型
	'''
    ids = IDCollection().validate_for_api().ids.data
    theme = Theme.get_themes(ids=ids)
    return Success(theme)
Пример #4
0
def get_complex_one(id):
    '''专题(Theme)详情接口
	:param id: 专题theme的id
	:return: 专题theme的详情
	'''
    id = IDMustBePositiveInt().validate_for_api().id.data
    theme_detail = Theme.get_theme_detail(id=id)
    return Success(theme_detail)
Пример #5
0
def get_complex_one(id):
	'''
	Theme详情接口
	:url /theme/:id
	:param id: 专题theme的id
	:return: 专题theme的详情
	'''
	id = IDMustBePositiveInt().validate_for_api().id.data
	theme_detail = Theme.get_theme_detail(id=id)
	return Success(theme_detail)
Пример #6
0
def get_simple_list():
	'''
	:url /theme
	:arg /theme?ids=id1,id2,id3,...
	:return: 一组theme模型
	'''
	# args = IDCollection().validate_for_api()
	ids = IDCollection().validate_for_api().ids.data
	theme = Theme.get_themes(ids=ids)
	return Success(theme)
Пример #7
0
def theme_author(slug):
    """Retrieve items of the theme_author"""
    theme_author = ThemeAuthor.get_item_or_404(slug)
    theme_authors = ThemeAuthor.get_items()
    items = Theme.get_items_by_theme_author_id(theme_author.id)

    return render_template("theme-author/theme-author.html",
                           theme_authors=theme_authors,
                           theme_author=theme_author,
                           items=items)
Пример #8
0
def license_type(slug):
    """Retrieve items of the license_type"""
    license_type = LicenseType.get_item_or_404(slug)
    license_types = LicenseType.get_items()
    items = Theme.get_items_by_license_type_id(license_type.id)

    return render_template("license-type/license-type.html",
                           license_types=license_types,
                           license_type=license_type,
                           items=items)
Пример #9
0
    def test_get_recent(self):
        with self.app.app_context():
            theme = Theme.create(name='1231',
                                 description='1231',
                                 topic_img_id=1,
                                 head_img_id=1)

        with self.client as client:
            rv = client.get('/v1/theme/1')
            json_data = rv.get_json()
            format_print(json_data)
Пример #10
0
def get_all():
    models = Theme.get_all_models(throw=True)
    for model in models:
        model._fields = ['id', 'name']
    return models
Пример #11
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))
Пример #12
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())
Пример #13
0
def hide(tid):
    Theme.hide_model(tid, throw=True)
    return Success('主题隐藏成功')
Пример #14
0
def show(tid):
    Theme.show_model(tid, throw=True)
    return Success('主题显示成功')
Пример #15
0
def delete(tid):
    Theme.remove_model(tid, throw=True)
    return Success('主题删除成功')
Пример #16
0
def update(tid):
    form = ThemeContent().validate_for_api()
    Theme.edit_model(tid, form.data, throw=True)
    return Success('主题更新成功')
Пример #17
0
def create():
    form = ThemeContent().validate_for_api()
    Theme.add_model(form.data, throw=True)
    return Success('主题新建成功')
Пример #18
0
def get(tid):
    model = Theme.get_model(tid, throw=True)
    return jsonify(model)
Пример #19
0
 def get_theme_detail(id):
     theme_detail = Theme.get_or_404(id=id, e=ThemeException)
     return theme_detail.append('products')
Пример #20
0
 def _check_relation_exist(t_id, p_id):
     theme = Theme.get_or_404(id=t_id, e=ThemeNotFound)
     product = Product.get_or_404(id=p_id, e=ProductNotFound)
     return theme, product
Пример #21
0
def get_paginate():
    start, count = paginate()
    q = request.args.get('q', None)
    models = Theme.get_paginate_models(start, count, q, soft=False, throw=True)
    return jsonify(models)