diff --git a/Pipfile b/Pipfile index c3c6062..1f96643 100644 --- a/Pipfile +++ b/Pipfile @@ -12,6 +12,7 @@ flask-security = "*" sqlalchemy-utils = "*" bcrypt = "*" flask-babel = "*" +python-dateutil = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index 8530d85..0b6ab05 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -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": [ diff --git a/app/__init__.py b/app/__init__.py index 51c440b..27d511b 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -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() diff --git a/app/forms.py b/app/forms.py index dd5e3d8..eeeaaf2 100644 --- a/app/forms.py +++ b/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!')) diff --git a/app/templates/base.html b/app/templates/base.html index 79b7d2c..e13c603 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -25,6 +25,7 @@