コード例 #1
0
def delete(article_id):
    article = Article.query.get_or_404(article_id)
    db.session.delete(article)
    db.session.commit()
    flash('Item deleted.')
    cache.delete(key='view//')
    return redirect(url_for('index'))
コード例 #2
0
ファイル: admin.py プロジェクト: zhigoo/youflog
def deleteLink(request):
    action = request.POST.get('action','')
    checks = request.POST.getlist('checks')
    idstring = ','.join(checks)  
    Link.objects.extra(where=['id IN ('+ idstring +')']).delete()  
    cache.delete('sidebar:links')
    return HttpResponseRedirect('/admin/links')
コード例 #3
0
def edit(article_id):
    article = Article.query.get_or_404(article_id)

    if request.method == 'POST':
        if not current_user.is_authenticated:
            return redirect(url_for('index'))

        title = request.form['title']
        date = request.form['date']
        text = request.form['text']

        if not title or not re.fullmatch("[0-9]{2}-[0-9]{2}-[0-9]{2}",
                                         date) or len(title) > 60:
            flash('Invalid input.')
            return redirect(url_for('edit', article_id=article_id))

        article.title = title
        article.date = date
        article.text = text
        db.session.commit()
        flash('Item updated.')
        cache.delete(key='view//')
        return redirect(url_for('index'))

    return render_template('edit.html', article=article)
コード例 #4
0
ファイル: request_func.py プロジェクト: BAGGK/lzk_blog
def before_redis_cache():
    """API:fitness:url:argc"""
    redis_cache: Redis = cache

    if request.method == 'GET':
        key_name = request.path
        ret_val = redis_cache.get(key_name)
        if ret_val:
            g.is_redis_cache = True
            return ret_val
    elif request.method == 'POST':
        for i in cache.keys('*'):
            cache.delete(i)

    g.is_redis_cache = False
コード例 #5
0
def settings():
    if request.method == 'POST':
        name = request.form['name']

        if not name or len(name) > 20:
            flash('Invalid input.')
            return redirect(url_for('settings'))

        user = User.query.first()
        user.name = name
        db.session.commit()
        flash('Settings updated.')
        cache.delete(key='view//')
        return redirect(url_for('index'))

    return render_template('settings.html')
コード例 #6
0
ファイル: models.py プロジェクト: zhigoo/youflog
 def save(self,pub):
     if not self.date:
         self.date=datetime.now()
     else:
         self.date=datetime.strptime(str(self.date)[0:19],"%Y-%m-%d %H:%M:%S")
     if pub: 
         self.__update_link()
         
     self.published=pub
     super(Entry,self).save()
    
     cache.delete('index_posts')
     cache.delete('recent_posts')
     cache.delete('random_posts')
     cache.delete('sidebar:categories')
     cache.delete('sidebar:archives')
     
     if self.published:
         send_pingback.send(sender=self.__class__,instance=self)
コード例 #7
0
def index():
    if request.method == 'POST':
        if not current_user.is_authenticated:
            return redirect(url_for('index'))

        title = request.form['title']
        date = request.form['date']
        text = request.form['text']

        if not title or not re.fullmatch("[0-9]{2}-[0-9]{2}-[0-9]{2}",
                                         date) or len(title) > 60:
            flash('Invalid input.')
            return redirect(url_for('index'))

        article = Article(title=title, date=date, text=text)
        db.session.add(article)
        db.session.commit()
        flash('Item created.')
        cache.delete(key='view//')
        return redirect(url_for('index'))

    articles = Article.query.all()
    return render_template('index.html', articles=articles)
コード例 #8
0
def login():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        code = request.form['code']

        if not username or not password or not code:
            flash('Invalid input.')
            return redirect(url_for('login'))

        user = User.query.first()

        if username == user.username and user.validate_password(
                password) and session.get('code') == code:
            login_user(user)
            flash('Login success.')
            cache.delete(key='view//')
            return redirect(url_for('index'))

        flash('Invalid username, password or validation code.')
        return redirect(url_for('login'))

    return render_template('login.html')
コード例 #9
0
ファイル: admin.py プロジェクト: zhigoo/youflog
def deleteCategory(request):
    ids = request.POST.getlist('checks')
    idstring = ','.join(ids)
    Category.objects.extra(where=['id IN ('+ idstring +')']).delete()
    cache.delete('sidebar:categories')
    return HttpResponseRedirect('/admin/categories')
コード例 #10
0
def logout():
    logout_user()
    flash('Goodbye.')
    cache.delete(key='view//')
    return redirect(url_for('index'))
コード例 #11
0
ファイル: models.py プロジェクト: zhigoo/youflog
 def save(self):
     super(Link,self).save()
     cache.delete('sidebar:links')