Beispiel #1
0
 def get_info(self):
     return {
         'name': self.name,
         'url': component_url_for('index', 'main', category=self.slug),
         'url_params': {
             'category': self.slug
         }
     }
Beispiel #2
0
def navbar_item():
    pages = Page.query.all()
    more = []
    for page in pages:
        more.append({
            'type': 'item',
            'name': page.title,
            'link': component_url_for('show_page', 'main', slug=page.slug)
        })
    dynamic_pages = Signal.send('dynamic_page')
    for page in dynamic_pages:
        more.append({
            'type': 'item',
            'name': page['title'],
            'link': component_url_for('show_page', 'main', slug=page['slug'])
        })
    return {
        'more': more
    }
Beispiel #3
0
def get_navbar_item():
    return {
        'type':
        'brand',
        'brand':
        get_setting('site_name').value,
        'more': [{
            'type': 'item',
            'name': '首页',
            'link': component_url_for('index')
        }]
    }
Beispiel #4
0
def admin_sidebar_item():
    return {
        'name':
        current_component.name,
        'slug':
        current_component.slug,
        'items': [{
            'type': 'link',
            'name': '通用',
            'url': component_url_for('main_settings', 'admin')
        }]
    }
Beispiel #5
0
def upload():
    if 'files[]' not in request.files:
        return jsonify({'code': 1, 'message': '上传文件不存在'})
    file = request.files['files[]']
    if file.filename == '':
        return jsonify({'code': 2, 'message': '未选择上传文件'})
    filename = file.filename
    if '.' not in filename or filename.rsplit('.', 1)[1].lower(
    ) not in get_setting('allowed_upload_file_extensions').value:
        return jsonify({'code': 3, 'message': '禁止上传的文件类型'})
    extension = filename.rsplit('.', 1)[1].lower()
    random_filename = uuid.uuid4().hex + '.' + extension
    abs_file_path = os.path.join(current_app.config['TEMP_FOLDER'],
                                 random_filename)
    os.makedirs(os.path.dirname(abs_file_path), exist_ok=True)
    file.save(abs_file_path)
    attachment = Attachment.create(abs_file_path,
                                   original_filename=filename,
                                   file_extension=extension,
                                   mime=file.mimetype)
    db.session.add(attachment)
    db.session.commit()
    meta = json.loads(request.form.get('meta', type=str))
    if 'article_id' in meta:
        article = Signal.send('get_article',
                              'article',
                              article_id=meta['article_id'])
        article.attachments.append(attachment)
        db.session.commit()
    if 'page_id' in meta:
        page = Signal.send('get_page', 'page', page_id=meta['page_id'])
        page.attachments.append(attachment)
        db.session.commit()
    return jsonify({
        'code':
        0,
        'message':
        '上传成功',
        'file_size':
        attachment.file_size,
        'relative_path':
        random_filename,
        'delete_url':
        component_url_for('.upload_delete', 'admin', id=attachment.id)
    })
Beispiel #6
0
def article_url(article, anchor, **kwargs):
    return component_url_for('show_article',
                             'main',
                             number=article.number,
                             _anchor=anchor,
                             **kwargs)
Beispiel #7
0
def page_url(page, anchor):
    return component_url_for('show_page', 'main', slug=page.slug, _anchor=anchor)