mirror of
https://github.com/lucaspalomodevelop/eventcally.git
synced 2026-03-13 00:07:22 +00:00
Event aus Vorschlag erzeugen
This commit is contained in:
parent
0426ed41af
commit
4c292ae402
@ -33,10 +33,10 @@ class CreateEventSuggestionForm(FlaskForm):
|
||||
for name, field in self._fields.items():
|
||||
if name == 'photo' and not obj.photo:
|
||||
obj.photo = Image()
|
||||
if name == 'event_place_id' and isinstance(self.event_place_id.data, str):
|
||||
if name == 'event_place_id' and self.event_place_id.is_free_text():
|
||||
obj.event_place_text = self.event_place_id.data
|
||||
obj.event_place_id = None
|
||||
elif name == 'organizer_id' and isinstance(self.organizer_id.data, str):
|
||||
elif name == 'organizer_id' and self.organizer_id.is_free_text():
|
||||
obj.organizer_text = self.organizer_id.data
|
||||
obj.organizer_id = None
|
||||
else:
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
from wtforms import DateTimeField, SelectMultipleField, SelectField
|
||||
from wtforms.widgets import html_params, HTMLString, ListWidget, CheckboxInput
|
||||
from wtforms.validators import StopValidation
|
||||
import pytz
|
||||
from datetime import datetime
|
||||
from flask_babelex import to_user_timezone
|
||||
from flask_babelex import to_user_timezone, gettext
|
||||
from dateutils import berlin_tz
|
||||
|
||||
class MultiCheckboxField(SelectMultipleField):
|
||||
@ -91,5 +92,15 @@ def try_to_int(value):
|
||||
|
||||
class TagSelectField(SelectField):
|
||||
|
||||
def __init__(self, label=None, validators=None, coerce=try_to_int, choices=None, validate_choice=False, **kwargs):
|
||||
def __init__(self, label=None, validators=None, coerce=try_to_int, choices=None, validate_choice=True, **kwargs):
|
||||
super(TagSelectField, self).__init__(label, validators, coerce, choices, validate_choice, **kwargs)
|
||||
|
||||
def pre_validate(self, form):
|
||||
if self.is_free_text():
|
||||
if not self.data or not self.data.strip():
|
||||
raise StopValidation(gettext('This field is required'))
|
||||
else:
|
||||
super(TagSelectField, self).pre_validate(form)
|
||||
|
||||
def is_free_text(self):
|
||||
return isinstance(self.data, str)
|
||||
|
||||
42
migrations/versions/00daa8c472ba_.py
Normal file
42
migrations/versions/00daa8c472ba_.py
Normal file
@ -0,0 +1,42 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 00daa8c472ba
|
||||
Revises: 50337ecd23db
|
||||
Create Date: 2020-10-27 20:58:57.392619
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
import sqlalchemy_utils
|
||||
import db
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '00daa8c472ba'
|
||||
down_revision = '50337ecd23db'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
#op.drop_table('spatial_ref_sys')
|
||||
op.drop_constraint('eventsuggestion_event_id_fkey', 'eventsuggestion', type_='foreignkey')
|
||||
op.create_foreign_key(None, 'eventsuggestion', 'event', ['event_id'], ['id'], ondelete='SET NULL')
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint(None, 'eventsuggestion', type_='foreignkey')
|
||||
op.create_foreign_key('eventsuggestion_event_id_fkey', 'eventsuggestion', 'event', ['event_id'], ['id'])
|
||||
op.create_table('spatial_ref_sys',
|
||||
sa.Column('srid', sa.INTEGER(), autoincrement=False, nullable=False),
|
||||
sa.Column('auth_name', sa.VARCHAR(length=256), autoincrement=False, nullable=True),
|
||||
sa.Column('auth_srid', sa.INTEGER(), autoincrement=False, nullable=True),
|
||||
sa.Column('srtext', sa.VARCHAR(length=2048), autoincrement=False, nullable=True),
|
||||
sa.Column('proj4text', sa.VARCHAR(length=2048), autoincrement=False, nullable=True),
|
||||
sa.CheckConstraint('(srid > 0) AND (srid <= 998999)', name='spatial_ref_sys_srid_check'),
|
||||
sa.PrimaryKeyConstraint('srid', name='spatial_ref_sys_pkey')
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
42
migrations/versions/50337ecd23db_.py
Normal file
42
migrations/versions/50337ecd23db_.py
Normal file
@ -0,0 +1,42 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 50337ecd23db
|
||||
Revises: 6be822396123
|
||||
Create Date: 2020-10-27 20:31:42.566357
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
import sqlalchemy_utils
|
||||
import db
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '50337ecd23db'
|
||||
down_revision = '6be822396123'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
#op.drop_table('spatial_ref_sys')
|
||||
op.add_column('eventsuggestion', sa.Column('event_id', sa.Integer(), nullable=True))
|
||||
op.create_foreign_key(None, 'eventsuggestion', 'event', ['event_id'], ['id'])
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint(None, 'eventsuggestion', type_='foreignkey')
|
||||
op.drop_column('eventsuggestion', 'event_id')
|
||||
op.create_table('spatial_ref_sys',
|
||||
sa.Column('srid', sa.INTEGER(), autoincrement=False, nullable=False),
|
||||
sa.Column('auth_name', sa.VARCHAR(length=256), autoincrement=False, nullable=True),
|
||||
sa.Column('auth_srid', sa.INTEGER(), autoincrement=False, nullable=True),
|
||||
sa.Column('srtext', sa.VARCHAR(length=2048), autoincrement=False, nullable=True),
|
||||
sa.Column('proj4text', sa.VARCHAR(length=2048), autoincrement=False, nullable=True),
|
||||
sa.CheckConstraint('(srid > 0) AND (srid <= 998999)', name='spatial_ref_sys_srid_check'),
|
||||
sa.PrimaryKeyConstraint('srid', name='spatial_ref_sys_pkey')
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
@ -295,6 +295,10 @@ class EventReferenceRequest(db.Model, TrackableMixin):
|
||||
|
||||
class EventSuggestion(db.Model, TrackableMixin):
|
||||
__tablename__ = 'eventsuggestion'
|
||||
__table_args__ = (
|
||||
CheckConstraint('NOT(event_place_id IS NULL AND event_place_text IS NULL)'),
|
||||
CheckConstraint('NOT(organizer_id IS NULL AND organizer_text IS NULL)'),
|
||||
)
|
||||
id = Column(Integer(), primary_key=True)
|
||||
|
||||
name = Column(Unicode(255), nullable=False)
|
||||
@ -323,6 +327,9 @@ class EventSuggestion(db.Model, TrackableMixin):
|
||||
photo_id = db.Column(db.Integer, db.ForeignKey('image.id'))
|
||||
photo = db.relationship('Image', uselist=False)
|
||||
|
||||
event_id = db.Column(db.Integer, db.ForeignKey('event.id', ondelete='SET NULL'), nullable=True)
|
||||
event = db.relationship('Event', uselist=False)
|
||||
|
||||
@hybrid_property
|
||||
def verified(self):
|
||||
return self.review_status == EventReviewStatus.verified
|
||||
|
||||
@ -236,8 +236,8 @@
|
||||
{% endmacro %}
|
||||
|
||||
{% macro render_event_review_status_pill(event) %}
|
||||
{% if event.review_status and event.review_status != 2 %}
|
||||
<span class="badge badge-pill {% if event.review_status == 1 %}badge-info{% else %}badge-danger{% endif %}">{{ event.review_status | loc_enum }}</span>
|
||||
{% if event.review_status %}
|
||||
<span class="badge badge-pill {% if event.review_status == 2 %}badge-success{% elif event.review_status == 1 %}badge-info{% else %}badge-danger{% endif %}">{{ event.review_status | loc_enum }}</span>
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
|
||||
@ -40,20 +40,26 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="my-4">
|
||||
<a class="btn btn-success" href="{{ url_for('event_create_for_admin_unit_id', id=event_suggestion.admin_unit_id, event_suggestion_id=event_suggestion.id) }}" role="button"><i class="fa fa-arrow-right"></i> {{ _('Create event from suggestion') }}</a>
|
||||
</div>
|
||||
{% if event_suggestion.verified and event_suggestion.event_id %}
|
||||
<div class="my-4">
|
||||
<a class="btn btn-success" href="{{ url_for('event', event_id=event_suggestion.event_id) }}" role="button"><i class="fa fa-arrow-right"></i> {{ _('View event') }}</a>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="my-4">
|
||||
<a class="btn btn-success" href="{{ url_for('event_create_for_admin_unit_id', id=event_suggestion.admin_unit_id, event_suggestion_id=event_suggestion.id) }}" role="button"><i class="fa fa-arrow-right"></i> {{ _('Create event from suggestion') }}</a>
|
||||
</div>
|
||||
|
||||
<div class="font-italic font-weight-bold my-4 text-uppercase">
|
||||
oder
|
||||
</div>
|
||||
<div class="font-italic font-weight-bold my-4 text-uppercase">
|
||||
oder
|
||||
</div>
|
||||
|
||||
<div class="my-4">
|
||||
<form action="" method="POST">
|
||||
{{ form.hidden_tag() }}
|
||||
{{ render_field_with_errors(form.rejection_resaon) }}
|
||||
<p>{{ form.submit(class="btn btn-danger")|safe }}</p>
|
||||
</form>
|
||||
</div>
|
||||
<div class="my-4">
|
||||
<form action="" method="POST">
|
||||
{{ form.hidden_tag() }}
|
||||
{{ render_field_with_errors(form.rejection_resaon) }}
|
||||
<p>{{ form.submit(class="btn btn-danger")|safe }}</p>
|
||||
</form>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
@ -7,9 +7,11 @@
|
||||
|
||||
<h1>{{ event_suggestion.name }}</h1>
|
||||
|
||||
{% if not event_suggestion.verified or not event_suggestion.event_id %}
|
||||
<div class="alert alert-info" role="alert">
|
||||
{{ _('You can visit this page again to check the status.') }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
@ -17,8 +19,10 @@
|
||||
</div>
|
||||
<div class="card-body">
|
||||
{{ render_event_review_status(event_suggestion) }}
|
||||
{% if event_suggestion.verified %}
|
||||
<a href="{{ url_for('event', event_id=event_suggestion.event_id) }}">{{ _('View') }}</a>
|
||||
{% if event_suggestion.verified and event_suggestion.event_id %}
|
||||
<div class="mt-4">
|
||||
<a class="btn btn-success" href="{{ url_for('event', event_id=event_suggestion.event_id) }}" role="button"><i class="fa fa-arrow-right"></i> {{ _('View event') }}</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -13,6 +13,7 @@ from services.event import upsert_event_category, update_event_dates_with_recurr
|
||||
from services.place import get_event_places
|
||||
from sqlalchemy.sql import asc, func
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from .event_suggestion import send_event_suggestion_review_status_mail
|
||||
|
||||
@app.route('/event/<int:event_id>')
|
||||
def event(event_id):
|
||||
@ -39,6 +40,10 @@ def event_create_for_admin_unit_id(id):
|
||||
if event_suggestion_id > 0:
|
||||
event_suggestion = EventSuggestion.query.get_or_404(event_suggestion_id)
|
||||
access_or_401(event_suggestion.admin_unit, 'event:verify')
|
||||
|
||||
if event_suggestion.verified and event_suggestion.event_id:
|
||||
return redirect(url_for('event_suggestion_review_status', event_suggestion_id=event_suggestion.id))
|
||||
|
||||
prepare_event_form_for_suggestion(form, event_suggestion)
|
||||
if form.is_submitted():
|
||||
form.process(request.form)
|
||||
@ -55,9 +60,17 @@ def event_create_for_admin_unit_id(id):
|
||||
event.organizer.admin_unit_id = event.admin_unit_id
|
||||
|
||||
try:
|
||||
if event_suggestion:
|
||||
event_suggestion.event = event
|
||||
event_suggestion.review_status = EventReviewStatus.verified
|
||||
event_suggestion.rejection_resaon = None
|
||||
|
||||
db.session.add(event)
|
||||
db.session.commit()
|
||||
|
||||
if event_suggestion:
|
||||
send_event_suggestion_review_status_mail(event_suggestion)
|
||||
|
||||
flash_message(gettext('Event successfully created'), url_for('event', event_id=event.id))
|
||||
return redirect(url_for('manage_admin_unit_events', id=event.admin_unit_id))
|
||||
except SQLAlchemyError as e:
|
||||
|
||||
@ -24,8 +24,8 @@ def event_suggestion_create_for_admin_unit(au_short_name):
|
||||
places = get_event_places(admin_unit.id)
|
||||
form.event_place_id.choices = [(p.id, p.name) for p in places]
|
||||
|
||||
form.organizer_id.choices.insert(0, (0, ''))
|
||||
form.event_place_id.choices.insert(0, (0, ''))
|
||||
form.organizer_id.choices.insert(0, ('', ''))
|
||||
form.event_place_id.choices.insert(0, ('', ''))
|
||||
|
||||
if form.validate_on_submit():
|
||||
event_suggestion = EventSuggestion()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user