Exemple #1
0
def postmessage(request):
    postname = request.POST['name']
    postcontext = request.POST['context']
    if postname.replace(' ', '').strip() == '':
        return render(request, 'message/index.html', {
            'error_message': 'You did not input your name',
        })
    elif postcontext.strip().replace(' ', '') == '':
        return render(request, 'message/index.html', {
            'error_message': 'You did not input context',
        })
    elif len(postname) >= 20:
        return render(request, 'message/index.html', {
            'error_message': 'you name is too long,please check!',
        })
    elif len(postcontext) >= 200:
        return render(
            request, 'message/index.html', {
                'error_message': 'you contenxt is too long,please check!',
            })
    else:
        m = Message(name=postname,
                    context=postcontext,
                    vote_date=timezone.now())
        m.save()
        return HttpResponseRedirect(reverse('index'))
Exemple #2
0
def postmessage(request):
    postname = request.POST['name']
    postcontext = request.POST['context']
    if postname == '':
        return render(request, 'message/index.html', {'error_message' : 'You did not input your name',})
    elif postcontext == '':
        return render(request, 'message/index.html', {'error_message' : 'You did not input context',})
    else:
        m = Message(name = postname, context = postcontext, vote_date = timezone.now())
        m.save()
        return HttpResponseRedirect(reverse('index'))
Exemple #3
0
def postmessage(request):
    postname = request.POST['name']
    postcontext = request.POST['context']
    if postname.replace(' ','').strip() == '':
        return render(request, 'message/index.html', {'error_message' : 'You did not input your name',})
    elif postcontext.strip().replace(' ','') == '':
        return render(request, 'message/index.html', {'error_message' : 'You did not input context',})
    elif len(postname) >= 20:
        return render(request,'message/index.html' , {'error_message' : 'you name is too long,please check!',})
    elif len(postcontext) >= 200:
        return render(request,'message/index.html' , {'error_message' : 'you contenxt is too long,please check!',})
    else:
        m = Message(name = postname, context = postcontext, vote_date = timezone.now())
        m.save()
        return HttpResponseRedirect(reverse('index'))
Exemple #4
0
def delete(id):
    query = Message.at(id).delete()
    if query.execute():
        flash(dict(type='success', content='Message %d dropped' % id))
    else:
        flash(dict(type='error', content='Failed to drop message %d' % id))
    return redirect(url_for('index'))
Exemple #5
0
def delete(id):
    query = Message.at(id).delete()
    if query.execute():
        flash(dict(type='success', content='Message %d dropped' % id))
    else:
        flash(dict(type='error', content='Failed to drop message %d' % id))
    return redirect(url_for('index'))
Exemple #6
0
def index():
    messages = Message.query.order_by(Message.timestamp.desc()).all()
    form = MessageForm()
    if form.validate_on_submit():
        name = form.name.data
        body = form.body.data
        message = Message(body=body, name=name)
        db.session.add(message)
        db.session.commit()
        flash('你的留言已经被发送')
        return redirect(url_for('index'))
    return render_template('index.html', form=form, messages=messages)
Exemple #7
0
def create():
    title = request.form['title']
    content = request.form['content']

    if title and content:
        message = Message.create(
            title=title, content=content, create_at=datetime.now())
        if message is not None:  # ok
            flash(dict(type='success', content='New message created'))
        else:  # create failed
            flash(dict(type='error', content='Failed to create new message'))
    else:  # invalid input
        flash(dict(type='warning', content='Empty input'))
    return redirect(url_for('index'))
Exemple #8
0
def create():
    title = request.form['title']
    content = request.form['content']

    if title and content:
        message = Message.create(title=title,
                                 content=content,
                                 create_at=datetime.now())
        if message is not None:  # ok
            flash(dict(type='success', content='New message created'))
        else:  # create failed
            flash(dict(type='error', content='Failed to create new message'))
    else:  # invalid input
        flash(dict(type='warning', content='Empty input'))
    return redirect(url_for('index'))
Exemple #9
0
def forge(count):
    from faker import Faker

    db.drop_all()
    db.create_all()

    faker = Faker()
    click.echo('Working...')

    for i in range(count):
        message = Message(name=faker.name(),
                          body=faker.sentence(),
                          timestamp=faker.date_time_this_year())
        db.session.add(message)
    db.session.commit()
    click.echo("Created %d fake messages" % count)
Exemple #10
0
def index():
    query = Message.orderby(
        Message.create_at, desc=True).select()  # sort by created time
    results = query.execute()
    messages = results.all()
    return render_template('template.html', messages=messages)
Exemple #11
0
def index():
    query = Message.orderby(Message.create_at,
                            desc=True).select()  # sort by created time
    results = query.execute()
    messages = results.all()
    return render_template('template.html', messages=messages)