diff --git a/messages.pot b/messages.pot index 5108d9c..5057df0 100644 --- a/messages.pot +++ b/messages.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2021-11-14 16:26+0100\n" +"POT-Creation-Date: 2021-11-17 01:07+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -204,7 +204,7 @@ msgstr "" msgid "Legal notice" msgstr "" -#: project/forms/admin.py:12 project/templates/_macros.html:1383 +#: project/forms/admin.py:12 project/templates/_macros.html:1392 #: project/templates/layout.html:317 #: project/templates/widget/event_suggestion/create.html:204 #: project/views/admin_unit.py:73 project/views/root.py:53 @@ -326,7 +326,7 @@ msgstr "" msgid "The short name is used to create a unique identifier for your events" msgstr "" -#: project/forms/admin_unit.py:41 project/templates/_macros.html:1519 +#: project/forms/admin_unit.py:41 project/templates/_macros.html:1528 msgid "Short name must contain only letters numbers or underscore" msgstr "" @@ -339,19 +339,19 @@ msgstr "" #: project/forms/admin_unit.py:48 project/forms/admin_unit_member.py:11 #: project/forms/admin_unit_member.py:23 project/forms/admin_unit_member.py:28 #: project/forms/event.py:107 project/forms/event_suggestion.py:38 -#: project/forms/organizer.py:27 project/templates/_macros.html:226 -#: project/templates/_macros.html:1479 project/templates/admin/users.html:19 +#: project/forms/organizer.py:27 project/templates/_macros.html:235 +#: project/templates/_macros.html:1488 project/templates/admin/users.html:19 msgid "Email" msgstr "" #: project/forms/admin_unit.py:49 project/forms/event.py:108 #: project/forms/event_suggestion.py:31 project/forms/organizer.py:28 -#: project/templates/_macros.html:279 +#: project/templates/_macros.html:288 msgid "Phone" msgstr "" #: project/forms/admin_unit.py:50 project/forms/event.py:109 -#: project/forms/organizer.py:29 project/templates/_macros.html:287 +#: project/forms/organizer.py:29 project/templates/_macros.html:296 msgid "Fax" msgstr "" @@ -531,16 +531,16 @@ msgstr "" msgid "All-day" msgstr "" -#: project/forms/event.py:54 project/templates/_macros.html:1699 +#: project/forms/event.py:54 project/templates/_macros.html:1708 #: project/templates/widget/event_suggestion/create.html:240 msgid "Recurring event" msgstr "" -#: project/forms/event.py:61 project/templates/_macros.html:1240 +#: project/forms/event.py:61 project/templates/_macros.html:1249 msgid "The start must be before the end." msgstr "" -#: project/forms/event.py:67 project/templates/_macros.html:1257 +#: project/forms/event.py:67 project/templates/_macros.html:1266 msgid "An event can last a maximum of 14 days." msgstr "" @@ -574,7 +574,7 @@ msgstr "" msgid "Enter a link where tickets can be purchased." msgstr "" -#: project/forms/event.py:136 project/templates/_macros.html:208 +#: project/forms/event.py:136 project/templates/_macros.html:217 msgid "Tags" msgstr "" @@ -624,7 +624,7 @@ msgstr "" msgid "If the participants needs to register for the event." msgstr "" -#: project/forms/event.py:170 project/templates/_macros.html:240 +#: project/forms/event.py:170 project/templates/_macros.html:249 #: project/templates/layout.html:128 msgid "Booked up" msgstr "" @@ -704,8 +704,8 @@ msgid "" " course it works without it." msgstr "" -#: project/forms/event.py:242 project/templates/_macros.html:387 -#: project/templates/_macros.html:550 +#: project/forms/event.py:242 project/templates/_macros.html:396 +#: project/templates/_macros.html:559 msgid "Previous start date" msgstr "" @@ -751,7 +751,7 @@ msgstr "" #: project/forms/event.py:286 project/forms/event.py:295 #: project/forms/event.py:368 project/forms/event_suggestion.py:50 -#: project/templates/_macros.html:427 project/templates/_macros.html:587 +#: project/templates/_macros.html:436 project/templates/_macros.html:596 #: project/templates/event/create.html:304 #: project/templates/event/update.html:185 #: project/templates/event_place/create.html:31 @@ -770,8 +770,8 @@ msgstr "" #: project/forms/event.py:302 project/forms/event.py:311 #: project/forms/event.py:376 project/forms/event.py:439 -#: project/forms/event_suggestion.py:60 project/templates/_macros.html:464 -#: project/templates/_macros.html:624 project/templates/event/create.html:273 +#: project/forms/event_suggestion.py:60 project/templates/_macros.html:473 +#: project/templates/_macros.html:633 project/templates/event/create.html:273 #: project/templates/event/update.html:175 #: project/templates/organizer/create.html:27 #: project/templates/organizer/delete.html:13 @@ -856,7 +856,7 @@ msgstr "" msgid "PublicStatus.published" msgstr "" -#: project/forms/event.py:402 project/templates/_macros.html:246 +#: project/forms/event.py:402 project/templates/_macros.html:255 msgid "PublicStatus.draft" msgstr "" @@ -869,7 +869,7 @@ msgstr "" msgid "Update event" msgstr "" -#: project/forms/event.py:423 project/templates/_macros.html:1212 +#: project/forms/event.py:423 project/templates/_macros.html:1221 #: project/templates/event/actions.html:47 #: project/templates/event/delete.html:6 msgid "Delete event" @@ -890,7 +890,7 @@ msgid "Keyword" msgstr "" #: project/forms/event.py:436 project/forms/event_date.py:21 -#: project/forms/planing.py:19 project/templates/_macros.html:360 +#: project/forms/planing.py:19 project/templates/_macros.html:369 msgid "Category" msgstr "" @@ -899,7 +899,7 @@ msgid "Find events" msgstr "" #: project/forms/event_date.py:24 project/forms/planing.py:22 -#: project/templates/_macros.html:294 +#: project/templates/_macros.html:303 #: project/templates/admin_unit/create.html:38 #: project/templates/admin_unit/update.html:39 #: project/templates/event_place/create.html:40 @@ -1042,7 +1042,7 @@ msgid "Weekdays" msgstr "" #: project/forms/reference.py:11 project/forms/reference_request.py:16 -#: project/templates/_macros.html:480 project/templates/_macros.html:640 +#: project/templates/_macros.html:489 project/templates/_macros.html:649 #: project/templates/admin_unit/create.html:28 #: project/templates/admin_unit/update.html:29 #: project/templates/layout.html:258 @@ -1070,7 +1070,7 @@ msgstr "" msgid "Delete request" msgstr "" -#: project/forms/reference_request.py:28 project/templates/_macros.html:1395 +#: project/forms/reference_request.py:28 project/templates/_macros.html:1404 #: project/templates/event_suggestion/review_status.html:18 #: project/templates/reference_request/review_status.html:12 msgid "Review status" @@ -1132,39 +1132,39 @@ msgstr "" msgid "This field is required." msgstr "" -#: project/templates/_macros.html:138 +#: project/templates/_macros.html:147 msgid "Show on Google Maps" msgstr "" -#: project/templates/_macros.html:217 +#: project/templates/_macros.html:226 msgid "Link" msgstr "" -#: project/templates/_macros.html:273 +#: project/templates/_macros.html:282 msgid "Verified" msgstr "" -#: project/templates/_macros.html:337 -#, python-format -msgid "Created at %(created_at)s by %(created_by)s." -msgstr "" - -#: project/templates/_macros.html:339 -#, python-format -msgid "Created at %(created_at)s." -msgstr "" - -#: project/templates/_macros.html:344 -#, python-format -msgid "Last updated at %(updated_at)s by %(updated_by)s." -msgstr "" - #: project/templates/_macros.html:346 #, python-format +msgid "Created at %(created_at)s by %(created_by)s." +msgstr "" + +#: project/templates/_macros.html:348 +#, python-format +msgid "Created at %(created_at)s." +msgstr "" + +#: project/templates/_macros.html:353 +#, python-format +msgid "Last updated at %(updated_at)s by %(updated_by)s." +msgstr "" + +#: project/templates/_macros.html:355 +#, python-format msgid "Last updated at %(updated_at)s." msgstr "" -#: project/templates/_macros.html:376 project/templates/_macros.html:546 +#: project/templates/_macros.html:385 project/templates/_macros.html:555 #: project/templates/event/actions.html:12 #: project/templates/event/create.html:250 #: project/templates/event/update.html:141 @@ -1172,58 +1172,58 @@ msgstr "" msgid "Event" msgstr "" -#: project/templates/_macros.html:382 project/templates/_macros.html:908 +#: project/templates/_macros.html:391 project/templates/_macros.html:917 msgid "Date" msgstr "" -#: project/templates/_macros.html:409 project/templates/_macros.html:568 -#: project/templates/_macros.html:1464 project/templates/event/actions.html:32 +#: project/templates/_macros.html:418 project/templates/_macros.html:577 +#: project/templates/_macros.html:1473 project/templates/event/actions.html:32 msgid "Share" msgstr "" -#: project/templates/_macros.html:413 project/templates/_macros.html:572 -#: project/templates/_macros.html:1494 +#: project/templates/_macros.html:422 project/templates/_macros.html:581 +#: project/templates/_macros.html:1503 msgid "Add to calendar" msgstr "" -#: project/templates/_macros.html:421 project/templates/_macros.html:580 +#: project/templates/_macros.html:430 project/templates/_macros.html:589 #: project/templates/event/report.html:4 msgid "Report event" msgstr "" -#: project/templates/_macros.html:448 project/templates/_macros.html:606 +#: project/templates/_macros.html:457 project/templates/_macros.html:615 msgid "Show directions" msgstr "" -#: project/templates/_macros.html:453 project/templates/_macros.html:611 +#: project/templates/_macros.html:462 project/templates/_macros.html:620 msgid "The event takes place online." msgstr "" -#: project/templates/_macros.html:455 project/templates/_macros.html:613 +#: project/templates/_macros.html:464 project/templates/_macros.html:622 msgid "The event takes place both offline and online." msgstr "" -#: project/templates/_macros.html:667 project/templates/event_date/list.html:5 -#: project/templates/event_date/list.html:300 +#: project/templates/_macros.html:676 project/templates/event_date/list.html:5 +#: project/templates/event_date/list.html:299 #: project/templates/reference_request/review.html:32 msgid "Event Dates" msgstr "" -#: project/templates/_macros.html:759 +#: project/templates/_macros.html:768 msgid "Search location on Google" msgstr "" -#: project/templates/_macros.html:825 +#: project/templates/_macros.html:834 #, python-format msgid "%(count)d event dates" msgstr "" -#: project/templates/_macros.html:848 project/templates/_macros.html:850 +#: project/templates/_macros.html:857 project/templates/_macros.html:859 #: project/templates/event_date/list.html:321 msgid "First" msgstr "" -#: project/templates/_macros.html:853 project/templates/_macros.html:855 +#: project/templates/_macros.html:862 project/templates/_macros.html:864 #: project/templates/event_date/list.html:322 #: project/templates/widget/event_suggestion/create.html:193 #: project/templates/widget/event_suggestion/create.html:218 @@ -1234,12 +1234,12 @@ msgstr "" msgid "Previous" msgstr "" -#: project/templates/_macros.html:857 +#: project/templates/_macros.html:866 #, python-format msgid "Page %(page)d of %(pages)d (%(total)d total)" msgstr "" -#: project/templates/_macros.html:859 project/templates/_macros.html:861 +#: project/templates/_macros.html:868 project/templates/_macros.html:870 #: project/templates/event_date/list.html:324 #: project/templates/widget/event_suggestion/create.html:194 #: project/templates/widget/event_suggestion/create.html:219 @@ -1249,77 +1249,77 @@ msgstr "" msgid "Next" msgstr "" -#: project/templates/_macros.html:864 project/templates/_macros.html:866 +#: project/templates/_macros.html:873 project/templates/_macros.html:875 #: project/templates/event_date/list.html:325 msgid "Last" msgstr "" -#: project/templates/_macros.html:931 +#: project/templates/_macros.html:940 msgid "Radius" msgstr "" -#: project/templates/_macros.html:1141 +#: project/templates/_macros.html:1150 msgid "Edit image" msgstr "" -#: project/templates/_macros.html:1162 +#: project/templates/_macros.html:1171 msgid "Close" msgstr "" -#: project/templates/_macros.html:1163 +#: project/templates/_macros.html:1172 msgid "Okay" msgstr "" -#: project/templates/_macros.html:1175 +#: project/templates/_macros.html:1184 msgid "Choose image file" msgstr "" -#: project/templates/_macros.html:1211 project/templates/event/actions.html:46 +#: project/templates/_macros.html:1220 project/templates/event/actions.html:46 msgid "Edit event" msgstr "" -#: project/templates/_macros.html:1214 project/templates/manage/events.html:45 +#: project/templates/_macros.html:1223 project/templates/manage/events.html:45 msgid "More" msgstr "" -#: project/templates/_macros.html:1261 +#: project/templates/_macros.html:1270 msgid "Please enter a valid time, between 00:00 and 23:59." msgstr "" -#: project/templates/_macros.html:1289 +#: project/templates/_macros.html:1298 #, python-format msgid "Just use %(term)s" msgstr "" -#: project/templates/_macros.html:1355 +#: project/templates/_macros.html:1364 msgid "Event suggestion" msgstr "" -#: project/templates/_macros.html:1473 +#: project/templates/_macros.html:1482 msgid "Link copied" msgstr "" -#: project/templates/_macros.html:1473 +#: project/templates/_macros.html:1482 msgid "Copy link" msgstr "" -#: project/templates/_macros.html:1502 +#: project/templates/_macros.html:1511 msgid "Google calendar" msgstr "" -#: project/templates/_macros.html:1503 +#: project/templates/_macros.html:1512 msgid "Apple calendar" msgstr "" -#: project/templates/_macros.html:1504 +#: project/templates/_macros.html:1513 msgid "Yahoo calendar" msgstr "" -#: project/templates/_macros.html:1505 +#: project/templates/_macros.html:1514 msgid "Other calendar" msgstr "" -#: project/templates/_macros.html:1700 +#: project/templates/_macros.html:1709 msgid "Remove event date" msgstr "" @@ -1687,6 +1687,14 @@ msgstr "" msgid "Request reference for event \"%(name)s\"" msgstr "" +#: project/templates/event_date/list.html:301 +msgid "Search" +msgstr "" + +#: project/templates/event_date/list.html:302 +msgid "Map view" +msgstr "" + #: project/templates/event_suggestion/review.html:20 #: project/templates/manage/reviews.html:19 msgid "Review event suggestion" @@ -1974,27 +1982,27 @@ msgstr "" msgid "Invitation successfully deleted" msgstr "" -#: project/views/event.py:177 +#: project/views/event.py:178 msgid "Event successfully published" msgstr "" -#: project/views/event.py:179 +#: project/views/event.py:180 msgid "Draft successfully saved" msgstr "" -#: project/views/event.py:222 +#: project/views/event.py:223 msgid "Event successfully updated" msgstr "" -#: project/views/event.py:248 +#: project/views/event.py:249 msgid "Event successfully deleted" msgstr "" -#: project/views/event.py:403 +#: project/views/event.py:408 msgid "Referenced event changed" msgstr "" -#: project/views/event.py:426 +#: project/views/event.py:431 msgid "New event report" msgstr "" diff --git a/migrations/versions/12aac790ed5e_.py b/migrations/versions/12aac790ed5e_.py new file mode 100644 index 0000000..2519c6a --- /dev/null +++ b/migrations/versions/12aac790ed5e_.py @@ -0,0 +1,39 @@ +"""empty message + +Revision ID: 12aac790ed5e +Revises: f350153a5691 +Create Date: 2021-11-16 09:01:00.569170 + +""" +import sqlalchemy as sa +import sqlalchemy_utils +from alembic import op + +from project import dbtypes + +# revision identifiers, used by Alembic. +revision = "12aac790ed5e" +down_revision = "f350153a5691" +branch_labels = None +depends_on = None + + +def upgrade(): + op.create_index( + "idx_event_fulltext", + "event", + [ + sa.text( + """( + (setweight(to_tsvector('german', coalesce(name, '')), 'A')) || + (setweight(to_tsvector('german', coalesce(tags, '')), 'B')) || + (setweight(to_tsvector('german', coalesce(description, '')), 'C')) + )""" + ) + ], + postgresql_using="gin", + ) + + +def downgrade(): + op.drop_index("idx_event_fulltext") diff --git a/project/models.py b/project/models.py index 00833c1..f1d770c 100644 --- a/project/models.py +++ b/project/models.py @@ -33,6 +33,7 @@ from sqlalchemy.ext.hybrid import hybrid_property from sqlalchemy.orm import aliased, backref, deferred, object_session, relationship from sqlalchemy.orm.relationships import remote from sqlalchemy.schema import CheckConstraint +from sqlalchemy.sql.operators import op from sqlalchemy_utils import ColorType from project import db @@ -43,6 +44,20 @@ from project.utils import make_check_violation # Base +def create_tsvector(*args): + field, weight = args[0] + exp = func.setweight(func.to_tsvector("german", func.coalesce(field, "")), weight) + for field, weight in args[1:]: + exp = op( + exp, + "||", + func.setweight( + func.to_tsvector("german", func.coalesce(field, "")), weight + ), + ) + return exp + + def _current_user_id_or_none(): if current_user and current_user.is_authenticated: return current_user.id @@ -779,6 +794,10 @@ class EventMixin(object): expected_participants = Column(Integer()) price_info = Column(UnicodeText()) + @declared_attr + def __ts_vector__(cls): + return create_tsvector((cls.name, "A"), (cls.tags, "B"), (cls.description, "C")) + @declared_attr def photo_id(cls): return Column("photo_id", ForeignKey("image.id")) diff --git a/project/services/event.py b/project/services/event.py index 0d882a5..025afdd 100644 --- a/project/services/event.py +++ b/project/services/event.py @@ -52,14 +52,10 @@ def upsert_event_category(category_name): def fill_event_filter(event_filter, params): if params.keyword: - like_keyword = "%" + params.keyword + "%" + tq = func.websearch_to_tsquery("german", params.keyword) event_filter = and_( event_filter, - or_( - Event.name.ilike(like_keyword), - Event.description.ilike(like_keyword), - Event.tags.ilike(like_keyword), - ), + Event.__ts_vector__.op("@@")(tq), ) if params.category_id: diff --git a/project/templates/_macros.html b/project/templates/_macros.html index 1ed4324..46eef2d 100644 --- a/project/templates/_macros.html +++ b/project/templates/_macros.html @@ -9,10 +9,15 @@ {% set is_required = kwargs['is_required'] if 'is_required' in kwargs else field.flags.required %} {% set label_text = field.label.text + ' *' if is_required else field.label.text %} -
+
{% if 'label_hidden' in kwargs or ('ri' in kwargs and kwargs['ri'] == 'checkbox') %} {% else %} - {{ field.label(text=label_text, class="mb-0") }} + {% set label_class = "col-sm-2 col-form-label" if 'formrow' in kwargs else "mb-0" %} + {{ field.label(text=label_text, class=label_class) }} + {% endif %} + + {% if 'formrow' in kwargs %} +
{% endif %} {% if field.description %} @@ -90,6 +95,10 @@ {% endfor %}
{% endif %} + + {% if 'formrow' in kwargs %} +
+ {% endif %}
{% if is_collapsible %} @@ -959,21 +968,21 @@ {{ form.hidden_tag() }} {% if form.keyword %} - {{ render_field_with_errors(form.keyword) }} + {{ render_field_with_errors(form.keyword, formrow="1") }} {% endif %} {% if form.category_id %} - {{ render_field_with_errors(form.category_id) }} + {{ render_field_with_errors(form.category_id, formrow="1") }} {% endif %} {% if form.organizer_id %} - {{ render_field_with_errors(form.organizer_id) }} + {{ render_field_with_errors(form.organizer_id, formrow="1") }} {% endif %} {{ render_event_dates_date_field(form.date_from, form.date_to) }} {% if form.weekday and form.weekday.choices|length > 0 %} - {{ render_field_with_errors(form.weekday, ri="multicheckbox") }} + {{ render_field_with_errors(form.weekday, ri="multicheckbox", formrow="1") }} {% endif %} {{ render_event_dates_location_field(form.location, form.distance) }} diff --git a/project/templates/event_date/list.html b/project/templates/event_date/list.html index 36712ea..8aeea77 100644 --- a/project/templates/event_date/list.html +++ b/project/templates/event_date/list.html @@ -296,11 +296,11 @@ {% block content %} -

- {{ _('Event Dates') }} - - -

+

{{ _('Event Dates') }}

+
+ + +