예제 #1
0
    def post(self, request, page=1):
        # POST通信の場合

        print("MessageView_post")

        form = MessageForm(request.POST, instance=Message())
        form.save()

        self.do_common_exec(page)
        return render(request, "hello/message.html", self.param)
예제 #2
0
파일: views.py 프로젝트: ishikawa407/hello
def index():
    messages = Message.query.order_by(Message.timestamp.desc()).all()
    form = HelloForm()
    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('Your message have been sent to the world!')
        return redirect(url_for('index'))
    return render_template('index.html', form=form, messages=messages)
예제 #3
0
def message(request, page=1):
    if request.method == 'POST':
        obj = Message()
        form = MessageForm(request.POST, instance=obj)
        form.save()
    data = Message.objects.all().reverse()
    paginator = Paginator(data, 5)
    params = {
        'title': 'Messagee',
        'form': MessageForm(),
        'data': paginator.get_page(page),
    }
    return render(request, 'hello/message.html', params)
예제 #4
0
def forge(count):
    ''' generate fake messages'''
    db.drop_all()
    db.create_all()
    click.echo("working...")

    for i in range(count):
        message = Message(name=fake.name(),
                          body=fake.sentence(),
                          age=fake.age(),
                          score=fake.score(),
                          timestamp=fake.date_time_this_year())
        db.session.add(message)
    db.session.commit()
    click.echo('created %d fake messages' % count)
예제 #5
0
def forge(count):
    """Generate fake messages."""
    from faker import Faker

    db.drop_all()
    db.create_all()

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

    for i in range(count):
        message = Message(
            name=fake.name(),
            body=fake.sentence(),
            timestamp=fake.date_time_this_year()
        )
        db.session.add(message)

    db.session.commit()
    click.echo('Created %d fake messages.' % count)
예제 #6
0
def save_message(message):
    try:
        Message(**message).save()
        return True
    except IntegrityError:
        return False
예제 #7
0
def save_reddit_articles(messages):
    for link in messages:
        try:
            Message(**link).save()
        except IntegrityError:
            pass