Example #1
0
 def update():
     custom_print(27)
     """Update all languages."""
     if os.system('pybabel extract -F babel.cfg -k _l -o messages.pot .'):
         raise RuntimeError('extract command failed')
     if os.system('pybabel update -i messages.pot -d app/translations'):
         raise RuntimeError('update command failed')
     os.remove('messages.pot')
Example #2
0
def error_response(status_code, message=None):
    custom_print(HTTP_STATUS_CODES)
    payload = {'error': HTTP_STATUS_CODES.get(status_code, 'Unknown error')}
    if message:
        payload['message'] = message
    response = jsonify(payload)
    response.status_code = status_code
    return response
Example #3
0
 def init(lang):
     """Initialize a new language."""
     custom_print(17)
     if os.system('pybabel extract -F babel.cfg -k _l -o messages.pot .'):
         raise RuntimeError('extract command failed')
     if os.system(
             'pybabel init -i messages.pot -d app/translations -l ' + lang):
         raise RuntimeError('init command failed')
     os.remove('messages.pot')
Example #4
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user is None or not user.check_password(form.password.data):
            flash(_('error username or password'))
            return redirect(url_for('auth.login'))
        custom_print(form.remember_me.data)
        login_user(user, remember=form.remember_me.data)
        next_page = request.args.get('next')
        custom_print(next_page)
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for('main.index')
        return redirect(next_page)
    return render_template('auth/login.html', title=_('login'), form=form)
Example #5
0
def search():
    if not g.search_form.validate():
        return redirect(url_for('main.explore'))
    page = request.args.get('page', 1, type=int)
    custom_print(g.search_form.q.data)
    posts, total = Post.search(g.search_form.q.data, page,
                               current_app.config['POSTS_PER_PAGE'])
    custom_print(posts, total)
    next_url = url_for('main.search', q=g.search_form.q.data, page=page + 1) \
        if total > page * current_app.config['POSTS_PER_PAGE'] else None
    prev_url = url_for('main.search', q=g.search_form.q.data, page=page - 1) \
        if page > 1 else None
    return render_template('search.html',
                           title=_('Search'),
                           posts=posts,
                           next_url=next_url,
                           prev_url=prev_url)
Example #6
0
def before_request():
    if request.path != '/notifications':
        s = Statistics.query.filter_by(id=1).first()
        if s == None:
            post = Statistics(total_visit_number=1)
            g.total_visit_number = 1
            db.session.add(post)
        else:
            s.total_visit_number += 1
            g.total_visit_number = s.total_visit_number
        db.session.commit()

        custom_print(s.total_visit_number)
    if current_user.is_authenticated:
        current_user.last_seen = datetime.utcnow()
        db.session.commit()
        g.search_form = SearchForm()
    g.locale = str(get_locale())
Example #7
0
def wants_json_response():
    custom_print(request.accept_mimetypes['application/json'])
    return request.accept_mimetypes['application/json'] >= \
        request.accept_mimetypes['text/html']
Example #8
0
 def compile():
     custom_print(37)
     """Compile all languages."""
     if os.system('pybabel compile -d app/translations'):
         raise RuntimeError('compile command failed')