Add event creation
This commit is contained in:
parent
a25e869eca
commit
4668089901
1
Pipfile
1
Pipfile
@ -12,6 +12,7 @@ flask-security = "*"
|
||||
sqlalchemy-utils = "*"
|
||||
bcrypt = "*"
|
||||
flask-babel = "*"
|
||||
python-dateutil = "*"
|
||||
|
||||
[dev-packages]
|
||||
|
||||
|
14
Pipfile.lock
generated
14
Pipfile.lock
generated
@ -1,7 +1,7 @@
|
||||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "7b27ffb5793ae5ba81455690332b1c9896038d93557e681992752466aaf87a1c"
|
||||
"sha256": "c71655288783b8802460a7706e1fede0917e345fd286f9aeb89d42dceb950e49"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
@ -214,6 +214,14 @@
|
||||
],
|
||||
"version": "==2.18"
|
||||
},
|
||||
"python-dateutil": {
|
||||
"hashes": [
|
||||
"sha256:1adb80e7a782c12e52ef9a8182bebeb73f1d7e24e374397af06fb4956c8dc5c0",
|
||||
"sha256:e27001de32f627c22380a688bcc43ce83504a7bc5da472209b4c70f02829f0b8"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==2.7.3"
|
||||
},
|
||||
"python-dotenv": {
|
||||
"hashes": [
|
||||
"sha256:4965ed170bf51c347a89820e8050655e9c25db3837db6602e906b6d850fad85c",
|
||||
@ -244,9 +252,9 @@
|
||||
},
|
||||
"sqlalchemy": {
|
||||
"hashes": [
|
||||
"sha256:2d5f08f714a886a1382c18be501e614bce50d362384dc089474019ce0768151c"
|
||||
"sha256:e21e5561a85dcdf16b8520ae4daec7401c5c24558e0ce004f9b60be75c4b6957"
|
||||
],
|
||||
"version": "==1.2.8"
|
||||
"version": "==1.2.9"
|
||||
},
|
||||
"sqlalchemy-utils": {
|
||||
"hashes": [
|
||||
|
@ -19,7 +19,7 @@ import os
|
||||
|
||||
from flask import Flask, current_app, redirect, render_template, url_for
|
||||
from flask_babel import Babel, get_locale as babel_get_locale
|
||||
from flask_security import SQLAlchemyUserDatastore, current_user
|
||||
from flask_security import SQLAlchemyUserDatastore, current_user, login_required
|
||||
|
||||
|
||||
def get_locale():
|
||||
@ -103,5 +103,25 @@ def register():
|
||||
return render_template('registration.html', form=form)
|
||||
|
||||
|
||||
@app.route('/new-event', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def new_event():
|
||||
from app.forms import EventForm
|
||||
from app.models import db, Event
|
||||
|
||||
form = EventForm()
|
||||
|
||||
if form.validate_on_submit():
|
||||
event = Event(user=current_user)
|
||||
form.populate_obj(event)
|
||||
|
||||
db.session.add(event)
|
||||
db.session.commit()
|
||||
|
||||
return redirect(url_for('hello'))
|
||||
|
||||
return render_template('event-edit.html', form=form)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
|
17
app/forms.py
17
app/forms.py
@ -1,7 +1,9 @@
|
||||
from flask_babel import lazy_gettext as _
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import PasswordField, StringField
|
||||
from wtforms import PasswordField, StringField, BooleanField
|
||||
from wtforms.ext.dateutil.fields import DateTimeField
|
||||
from wtforms.validators import DataRequired, Email, ValidationError
|
||||
from wtforms.widgets import TextArea
|
||||
|
||||
|
||||
class RegistrationForm(FlaskForm):
|
||||
@ -13,3 +15,16 @@ class RegistrationForm(FlaskForm):
|
||||
def validate_password_retype(self, field):
|
||||
if field.data != self.password.data:
|
||||
raise ValidationError(_('The two passwords must match!'))
|
||||
|
||||
|
||||
class EventForm(FlaskForm):
|
||||
title = StringField(_('Title'), validators=[DataRequired()])
|
||||
time_zone = StringField(_('Time zone'), validators=[DataRequired()])
|
||||
start_time = DateTimeField(_('Start time'), validators=[DataRequired()])
|
||||
end_time = DateTimeField(_('End time'), validators=[DataRequired()])
|
||||
all_day = BooleanField(_('All day'))
|
||||
description = StringField(_('Description'), widget=TextArea())
|
||||
|
||||
def validate_end_time(self, field):
|
||||
if field.data < self.start_time.data:
|
||||
raise ValidationError(_('End time must be later than start time!'))
|
||||
|
@ -25,6 +25,7 @@
|
||||
<li><a href="{{ url_for('security.login') }}">{% trans %}Login{% endtrans %}</a></li>
|
||||
{% else %}
|
||||
<li><a href="{{ url_for('security.logout') }}">{% trans %}Logout{% endtrans %}</a></li>
|
||||
<li><a href="{{ url_for('hello') }}">{% trans %}Calendar view{% endtrans %}</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</nav>
|
||||
|
43
app/templates/event-edit.html
Normal file
43
app/templates/event-edit.html
Normal file
@ -0,0 +1,43 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<form method="post">
|
||||
{{ form.hidden_tag() }}
|
||||
|
||||
{{ form.errors }}
|
||||
<br>
|
||||
|
||||
{{ form.title.errors }}
|
||||
{{ form.title.label }}
|
||||
{{ form.title }}
|
||||
<br>
|
||||
|
||||
{{ form.time_zone.errors }}
|
||||
{{ form.time_zone.label }}
|
||||
{{ form.time_zone }}
|
||||
<br>
|
||||
|
||||
{{ form.start_time.errors }}
|
||||
{{ form.start_time.label }}
|
||||
{{ form.start_time }}
|
||||
<br>
|
||||
|
||||
{{ form.end_time.errors }}
|
||||
{{ form.end_time.label }}
|
||||
{{ form.end_time }}
|
||||
<br>
|
||||
|
||||
{{ form.all_day.errors }}
|
||||
{{ form.all_day.label }}
|
||||
{{ form.all_day }}
|
||||
<br>
|
||||
|
||||
{{ form.description.errors }}
|
||||
{{ form.description.label }}
|
||||
{{ form.description }}
|
||||
<br>
|
||||
|
||||
<button type="submit">{% trans %}Save{% endtrans %}</button>
|
||||
<a href="{{ url_for('hello') }}">Cancel</a>
|
||||
</form>
|
||||
{% endblock content %}
|
@ -4,4 +4,6 @@
|
||||
{{ _('Welcome to Calendar.social, %(username)s!', username=current_user.username) }}
|
||||
|
||||
{% include 'month-view.html' %}
|
||||
|
||||
<a href="{{ url_for('new_event') }}">{% trans %}Add event{% endtrans %}</a>
|
||||
{% endblock content %}
|
||||
|
Loading…
Reference in New Issue
Block a user