Skip to content

Commit

Permalink
Merge pull request #3625 from GeotrekCE/feat_add_organizer_touristice…
Browse files Browse the repository at this point in the history
…vent

Feat add organizer touristicevent
  • Loading branch information
Chatewgne authored Aug 29, 2023
2 parents dd07ee6 + 5a5a2c9 commit aa007e1
Show file tree
Hide file tree
Showing 34 changed files with 297 additions and 37 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ CHANGELOG
- Add a multiselect to filter the Blades by more than one manager
- Filter by begin date by default on touristic events in APIv2 (#3597)
- Add model LinePictogram for each line (#3327)
- Create Organizer model for touristic events, configurable in admin site (#3625)

**Documentation**

Expand Down
3 changes: 3 additions & 0 deletions geotrek/api/locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ msgstr ""
msgid "Filter by one or more Place id, comma-separated."
msgstr ""

msgid "Filter events on organizers"
msgstr ""

msgid "Filter events on bookable boolean : true/false expected"
msgstr ""

Expand Down
3 changes: 3 additions & 0 deletions geotrek/api/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ msgstr ""
msgid "Filter by one or more Place id, comma-separated."
msgstr ""

msgid "Filter events on organizers"
msgstr ""

msgid "Filter events on bookable boolean : true/false expected"
msgstr ""

Expand Down
3 changes: 3 additions & 0 deletions geotrek/api/locale/es/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ msgstr ""
msgid "Filter by one or more Place id, comma-separated."
msgstr ""

msgid "Filter events on organizers"
msgstr ""

msgid "Filter events on bookable boolean : true/false expected"
msgstr ""

Expand Down
5 changes: 5 additions & 0 deletions geotrek/api/locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,11 @@ msgid "Filter by one or more Place id, comma-separated."
msgstr ""
"Filtrer par un ou plusieurs id de lieu d'évènement, séparés par des virgules."

msgid "Filter by one or more organizer, comma-separated."
msgstr ""
"Filtrer par un ou plusieurs id d'organisateur d'évènements, "
"séparés par des virgules."

msgid "Filter events on bookable boolean : true/false expected"
msgstr "Filtre les évènements réservables : true/false attendu"

Expand Down
3 changes: 3 additions & 0 deletions geotrek/api/locale/it/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ msgstr ""
msgid "Filter by one or more Place id, comma-separated."
msgstr ""

msgid "Filter events on organizers"
msgstr ""

msgid "Filter events on bookable boolean : true/false expected"
msgstr ""

Expand Down
3 changes: 3 additions & 0 deletions geotrek/api/locale/nl/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ msgstr ""
msgid "Filter by one or more Place id, comma-separated."
msgstr ""

msgid "Filter events on organizers"
msgstr ""

msgid "Filter events on bookable boolean : true/false expected"
msgstr ""

Expand Down
32 changes: 30 additions & 2 deletions geotrek/api/tests/test_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@
'id', 'name', 'geometry'
])

TOURISTIC_EVENT_ORGANIZER_DETAIL_JSON_STRUCTURE = sorted([
'id', 'label'
])

TOURISTIC_EVENT_TYPE_DETAIL_JSON_STRUCTURE = sorted([
'id', 'pictogram', 'type'
])
Expand Down Expand Up @@ -711,6 +715,12 @@ def get_touristiceventplace_list(self, params=None):
def get_touristiceventplace_detail(self, id_touristiceventplace, params=None):
return self.client.get(reverse('apiv2:touristiceventplace-detail', args=(id_touristiceventplace,)), params)

def get_touristiceventorganizer_list(self, params=None):
return self.client.get(reverse('apiv2:touristiceventorganizer-list'), params)

def get_touristiceventorganizer_detail(self, id_touristiceventorganizer, params=None):
return self.client.get(reverse('apiv2:touristiceventorganizer-detail', args=(id_touristiceventorganizer,)), params)

def get_servicetype_list(self, params=None):
return self.client.get(reverse('apiv2:servicetype-list'), params)

Expand Down Expand Up @@ -3160,6 +3170,7 @@ def setUpTestData(cls):
cls.touristic_event4 = tourism_factory.TouristicEventFactory(
deleted=True
)
cls.organizer = tourism_factory.TouristicEventOrganizerFactory(label='OrganizerA')
cls.place_unpublished = tourism_factory.TouristicEventPlaceFactory(name="There")
cls.touristic_event5 = tourism_factory.TouristicEventFactory(
end_date=None,
Expand All @@ -3169,7 +3180,8 @@ def setUpTestData(cls):
start_time="12:34",
capacity=12,
bookable=False,
place=cls.place
place=cls.place,
organizer=cls.organizer
)
cls.touristic_content = tourism_factory.TouristicContentFactory(geom=Point(0.77802, 43.047482, srid=4326))

Expand Down Expand Up @@ -3210,6 +3222,15 @@ def test_touristic_event_dates_filters_4(self):
# Event 1 finishes on 3rd of july
self.assertEqual(response.json().get("count"), 2)

def test_touristic_event_organizer_filters_1(self):
response = self.get_touristicevent_list({'organizer': 'tt'})
self.assertEqual(response.json()['organizer'][0],
'“tt” is not a valid value.')

def test_touristic_event_organizer_filters_2(self):
response = self.get_touristicevent_list({'organizer': f'{self.organizer.pk}'})
self.assertEqual(response.json().get("count"), 1)

def test_touristic_event_cancelled_filter(self):
response = self.get_touristicevent_list({'cancelled': 'True'})
self.assertEqual(response.json().get("count"), 1)
Expand All @@ -3227,6 +3248,10 @@ def test_touristic_event_place_detail(self):
response = self.get_touristiceventplace_detail(self.place.pk)
self.check_structure_response(response, TOURISTIC_EVENT_PLACE_DETAIL_JSON_STRUCTURE)

def test_touristic_event_organizer_detail(self):
response = self.get_touristiceventorganizer_detail(self.organizer.pk)
self.check_structure_response(response, TOURISTIC_EVENT_ORGANIZER_DETAIL_JSON_STRUCTURE)

def test_touristicevent_near_trek(self):
response = self.get_touristicevent_list({'near_trek': self.trek.pk})
# Event 1 appears but not Event 2
Expand Down Expand Up @@ -3260,6 +3285,10 @@ def test_touristic_event_place_filter(self):
response = self.get_touristicevent_list({'place': f"{self.place.pk},{self.other_place.pk}"})
self.assertEqual(response.json().get("count"), 2)

def test_touristic_event_place_not_valid_filter(self):
response = self.get_touristicevent_list({'place': "100000"})
self.assertEqual(response.json()['place'][0], "Select a valid choice. 100000 is not one of the available choices.")

def test_touristic_event_place_list(self):
response = self.get_touristiceventplace_list()
self.assertEqual(response.json().get("count"), 2)
Expand Down Expand Up @@ -3830,7 +3859,6 @@ def test_sites_labels_exclude_filter(self):
{self.site1.pk, self.site2.pk, self.site3.pk, site_a.pk})

def test_sites_label_filter_published(self):
all_labels = []
response = self.get_site_list()
self.assertEqual(response.status_code, 200)
results = response.json()['results']
Expand Down
12 changes: 9 additions & 3 deletions geotrek/api/v2/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from rest_framework.filters import BaseFilterBackend
from rest_framework_gis.filters import DistanceToPointFilter, InBBOXFilter

from geotrek.tourism.models import TouristicContent, TouristicContentType, TouristicEvent, TouristicEventPlace, \
TouristicEventType
from geotrek.tourism.models import TouristicEventOrganizer, TouristicContent, TouristicContentType, TouristicEvent, \
TouristicEventPlace, TouristicEventType
from geotrek.trekking.models import ServiceType, Trek, POI
from geotrek.zoning.models import City, District

Expand Down Expand Up @@ -502,6 +502,12 @@ class TouristicEventFilterSet(filters.FilterSet):
queryset=TouristicEventPlace.objects.all(),
help_text=_("Filter by one or more Place id, comma-separated.")
)
organizer = filters.ModelMultipleChoiceFilter(
widget=CSVWidget(),
queryset=TouristicEventOrganizer.objects.all(),
help_text=_("Filter by one or more organizer, comma-separated."),
)

help_texts = {
'bookable': _("Filter events on bookable boolean : true/false expected"),
'cancelled': _("Filter events on cancelled boolean : true/false expected")
Expand All @@ -515,7 +521,7 @@ def filter_for_field(cls, f, name, lookup_expr):

class Meta:
model = TouristicEvent
fields = ['cancelled', 'bookable', 'place']
fields = ['cancelled', 'bookable', 'place', 'organizer']


class GeotrekTouristicEventFilter(GeotrekZoningAndThemeFilter):
Expand Down
9 changes: 9 additions & 0 deletions geotrek/api/v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,10 @@ def get_departure_city(self, obj):
return city.code if city else None

class TouristicEventSerializer(TouristicModelSerializer):
organizer = serializers.SlugRelatedField(
read_only=True,
slug_field='label'
)
attachments = AttachmentSerializer(many=True, source='sorted_attachments')
url = HyperlinkedIdentityField(view_name='apiv2:touristicevent-detail')
begin_date = serializers.DateField()
Expand Down Expand Up @@ -556,6 +560,11 @@ class Meta:
model = tourism_models.TouristicEventPlace
fields = ('id', 'geometry', 'name')

class TouristicEventOrganizerSerializer(serializers.ModelSerializer):
class Meta:
model = tourism_models.TouristicEventOrganizer
fields = ('id', 'label')

class InformationDeskTypeSerializer(DynamicFieldsMixin, serializers.ModelSerializer):
label = serializers.SerializerMethodField()

Expand Down
1 change: 1 addition & 0 deletions geotrek/api/v2/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
router.register('touristicevent', api_views.TouristicEventViewSet, basename='touristicevent')
router.register('touristicevent_type', api_views.TouristicEventTypeViewSet, basename='touristiceventtype')
router.register('touristicevent_place', api_views.TouristicEventPlaceViewSet, basename='touristiceventplace')
router.register('touristicevent_organizer', api_views.TouristicEventOrganizerViewSet, basename='touristiceventorganizer')
router.register('informationdesk', api_views.InformationDeskViewSet, basename='informationdesk')
router.register('informationdesk_type', api_views.InformationDeskTypeViewSet, basename='informationdesktype')
router.register('label_accessibility', api_views.LabelAccessibilityViewSet, basename='labelaccessibility')
Expand Down
3 changes: 2 additions & 1 deletion geotrek/api/v2/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
from .sensitivity import SportPracticeViewSet # noqa
from .sensitivity import SpeciesViewSet # noqa
if 'geotrek.tourism' in settings.INSTALLED_APPS:
from .tourism import TouristicContentViewSet, TouristicEventViewSet, TouristicEventTypeViewSet, InformationDeskViewSet, InformationDeskTypeViewSet, TouristicContentCategoryViewSet, LabelAccessibilityViewSet, TouristicEventPlaceViewSet # noqa
from .tourism import (TouristicContentViewSet, TouristicEventViewSet, TouristicEventTypeViewSet, InformationDeskViewSet, InformationDeskTypeViewSet, # noqa
TouristicContentCategoryViewSet, LabelAccessibilityViewSet, TouristicEventPlaceViewSet, TouristicEventOrganizerViewSet) # noqa
if 'geotrek.zoning' in settings.INSTALLED_APPS:
from .zoning import CityViewSet, DistrictViewSet # noqa
if 'geotrek.outdoor' in settings.INSTALLED_APPS:
Expand Down
9 changes: 9 additions & 0 deletions geotrek/api/v2/views/tourism.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,12 @@ def get_queryset(self):
return tourism_models.TouristicEventPlace.objects.prefetch_related('touristicevents').annotate(
geom_transformed=Transform('geom', settings.API_SRID)
).order_by('name')


class TouristicEventOrganizerViewSet(api_viewsets.GeotrekGeometricViewset):
filter_backends = api_viewsets.GeotrekViewSet.filter_backends + (
api_filters.UpdateOrCreateDateFilter,
api_filters.TouristicEventRelatedPortalFilter
)
serializer_class = api_serializers.TouristicEventOrganizerSerializer
queryset = tourism_models.TouristicEventOrganizer.objects.order_by('label')
7 changes: 7 additions & 0 deletions geotrek/tourism/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,16 @@ class TouristicEventPlaceAdmin(LeafletGeoAdmin):
search_fields = ('name',)


class TouristicEventOrganizerAdmin(admin.ModelAdmin):
list_display = ('label',)
list_filter = ('label',)
search_fields = ('label',)


if settings.TOURISM_ENABLED:
admin.site.register(tourism_models.TouristicContentCategory, TouristicContentCategoryAdmin)
admin.site.register(tourism_models.TouristicEventType, TouristicEventTypeAdmin)
admin.site.register(tourism_models.TouristicEventParticipantCategory, TouristicEventParticipantCategoryAdmin)
admin.site.register(tourism_models.CancellationReason, CancellationReasonAdmin)
admin.site.register(tourism_models.TouristicEventPlace, TouristicEventPlaceAdmin)
admin.site.register(tourism_models.TouristicEventOrganizer, TouristicEventOrganizerAdmin)
11 changes: 7 additions & 4 deletions geotrek/tourism/locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-12-16 09:52+0000\n"
"POT-Creation-Date: 2023-08-24 11:13+0000\n"
"PO-Revision-Date: 2015-10-22 14:33+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
Expand Down Expand Up @@ -274,6 +274,12 @@ msgstr ""
msgid "Event places"
msgstr ""

msgid "Organizer"
msgstr "Organisator"

msgid "Organizers"
msgstr "Organisatoren"

msgid "Begin date"
msgstr "Startdatum"

Expand Down Expand Up @@ -301,9 +307,6 @@ msgstr "11:00, 23:30"
msgid "End time"
msgstr ""

msgid "Organizer"
msgstr "Organisator"

msgid "Speaker"
msgstr "Lautsprecher"

Expand Down
11 changes: 7 additions & 4 deletions geotrek/tourism/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-12-16 09:52+0000\n"
"POT-Creation-Date: 2023-08-24 11:13+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -273,6 +273,12 @@ msgstr ""
msgid "Event places"
msgstr ""

msgid "Organizer"
msgstr ""

msgid "Organizers"
msgstr ""

msgid "Begin date"
msgstr ""

Expand Down Expand Up @@ -300,9 +306,6 @@ msgstr ""
msgid "End time"
msgstr ""

msgid "Organizer"
msgstr ""

msgid "Speaker"
msgstr ""

Expand Down
11 changes: 7 additions & 4 deletions geotrek/tourism/locale/es/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-12-16 09:52+0000\n"
"POT-Creation-Date: 2023-08-24 11:13+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -273,6 +273,12 @@ msgstr ""
msgid "Event places"
msgstr ""

msgid "Organizer"
msgstr ""

msgid "Organizers"
msgstr ""

msgid "Begin date"
msgstr ""

Expand Down Expand Up @@ -300,9 +306,6 @@ msgstr ""
msgid "End time"
msgstr ""

msgid "Organizer"
msgstr ""

msgid "Speaker"
msgstr ""

Expand Down
11 changes: 7 additions & 4 deletions geotrek/tourism/locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-12-16 09:52+0000\n"
"POT-Creation-Date: 2023-08-24 11:13+0000\n"
"PO-Revision-Date: 2020-04-22 07:36+0000\n"
"Last-Translator: Emmanuelle Helly <[email protected]>\n"
"Language-Team: French <https://weblate.makina-corpus.net/projects/geotrek-"
Expand Down Expand Up @@ -277,6 +277,12 @@ msgstr "Lieu d'évènement"
msgid "Event places"
msgstr "Lieux d'évènements"

msgid "Organizer"
msgstr "Organisateur"

msgid "Organizers"
msgstr "Organisateurs"

msgid "Begin date"
msgstr "Date de début"

Expand Down Expand Up @@ -304,9 +310,6 @@ msgstr "11:00, 23:30"
msgid "End time"
msgstr "Heure de fin"

msgid "Organizer"
msgstr "Organisateur"

msgid "Speaker"
msgstr "Intervenant"

Expand Down
Loading

0 comments on commit aa007e1

Please sign in to comment.