From 38c7fd90b3df85dbd6ecfa9bd5e1169bdf7c1482 Mon Sep 17 00:00:00 2001 From: Mara Karagianni Date: Tue, 3 Sep 2024 15:09:55 +0100 Subject: [PATCH] projects: add location component in dashboard --- adhocracy-plus/config/settings/dev.py | 5 + adhocracy-plus/config/settings/polygons.py | 195 ++++++++++++++++++ adhocracy-plus/config/settings/production.py | 5 + .../includes/project_location_form.html | 2 + apps/projects/dashboard.py | 29 +++ apps/projects/forms.py | 14 ++ apps/projects/serializers.py | 1 + changelog/8304.md | 3 + 8 files changed, 254 insertions(+) create mode 100644 adhocracy-plus/config/settings/polygons.py create mode 100644 adhocracy-plus/templates/a4dashboard/includes/project_location_form.html create mode 100644 changelog/8304.md diff --git a/adhocracy-plus/config/settings/dev.py b/adhocracy-plus/config/settings/dev.py index 26937e16c..2d47b9ed5 100644 --- a/adhocracy-plus/config/settings/dev.py +++ b/adhocracy-plus/config/settings/dev.py @@ -51,6 +51,11 @@ except ImportError: pass +try: + from .polygons import * +except ImportError: + pass + try: INSTALLED_APPS += tuple(ADDITIONAL_APPS) except NameError: diff --git a/adhocracy-plus/config/settings/polygons.py b/adhocracy-plus/config/settings/polygons.py new file mode 100644 index 000000000..301e5de71 --- /dev/null +++ b/adhocracy-plus/config/settings/polygons.py @@ -0,0 +1,195 @@ +BERLIN_POLYGON = { + "features": [ + { + "geometry": { + "coordinates": [ + [ + [13.47551254985644, 52.66878186412850], + [13.4756476943205, 52.6662806556946], + [13.48821932203047, 52.6705511650083], + [13.4852948383627, 52.6591313184541], + [13.49083140972433, 52.6547287329975], + [13.51278152919391, 52.6455619490685], + [13.51887316955025, 52.64747079290455], + [13.52310012320358, 52.645430194070], + [13.51769865735421, 52.6296359183979], + [13.50581735115305, 52.6258283812089], + [13.49675228461664, 52.6050935381621], + [13.50815361527170, 52.5921832557480], + [13.52243021204765, 52.5928525016777], + [13.54711209986707, 52.58788476538483], + [13.56756949831588, 52.5737401267818], + [13.58153970188728, 52.57088194177744], + [13.58749430855951, 52.55526701776870], + [13.58538711774429, 52.54847164183179], + [13.63535874890461, 52.54162879240169], + [13.62673238446994, 52.5377485708105], + [13.62590681405656, 52.5301463739158], + [13.65689556728097, 52.5298695113785], + [13.6585724640499, 52.5258111515478], + [13.63331882981516, 52.51182618683948], + [13.62467074769431, 52.4951842623379], + [13.6308004349988, 52.4941200504789], + [13.61501081462424, 52.4808250554547], + [13.61639738431556, 52.47489352940948], + [13.61151729313924, 52.4706273335476], + [13.62550862642468, 52.4683565075655], + [13.62580803771906, 52.4737133550199], + [13.64061312353399, 52.4794846317953], + [13.64821500984158, 52.478781959103], + [13.67066101945844, 52.47306199022395], + [13.68259937930192, 52.46618484991720], + [13.69682492987295, 52.46416044582899], + [13.6984327010084, 52.45508021843881], + [13.70536529411957, 52.4557664271711], + [13.70132413255186, 52.4681454816044], + [13.71644765434718, 52.4621942886764], + [13.72911216028255, 52.4505968229147], + [13.75321991093874, 52.44759765857591], + [13.75410720984658, 52.4431717430295], + [13.75902864393226, 52.442579364583], + [13.7595872183079, 52.4362718823468], + [13.75229608809821, 52.4370814607238], + [13.75421510289298, 52.4416114987071], + [13.75053611761034, 52.4414589552040], + [13.74311812998032, 52.43399868867271], + [13.73795859513104, 52.4341377584145], + [13.7413845258278, 52.4269159630436], + [13.7295135359784, 52.4173934664772], + [13.73874910747478, 52.4073217759860], + [13.73453774624779, 52.4019760684248], + [13.72334480404065, 52.3985861140822], + [13.71643662892613, 52.3995274363320], + [13.6875617731858, 52.3858235159905], + [13.68806198613023, 52.38291036570609], + [13.69863315287863, 52.381585040138], + [13.69999728320836, 52.3751213401578], + [13.6905641034697, 52.3673787101830], + [13.68031876604502, 52.3693159137457], + [13.67108036066419, 52.3663556565990], + [13.64840072050701, 52.33824183487645], + [13.63629107105115, 52.34703792463357], + [13.63863753231862, 52.36016167822242], + [13.64710542789269, 52.36687546722088], + [13.6468060908087, 52.3701605262758], + [13.64169695514917, 52.37095394202865], + [13.64336463289718, 52.3773909255589], + [13.63339138644673, 52.3762838889605], + [13.62794992360012, 52.381790668872], + [13.60695908735289, 52.37498143220593], + [13.59276211655155, 52.3941696868763], + [13.56490528578061, 52.3882858396881], + [13.5356636132792, 52.3890104545449], + [13.53837936718677, 52.4006790639424], + [13.52826323784186, 52.3983962153520], + [13.5151650860563, 52.4014349123701], + [13.479884997689, 52.3959966333453], + [13.46833747586563, 52.41943196644863], + [13.46232160238298, 52.4206244356477], + [13.41877268561141, 52.4099174058766], + [13.42758536517431, 52.38682399172477], + [13.42098487585958, 52.37624714140610], + [13.38852078167641, 52.3779684655105], + [13.38721684118924, 52.3885841633282], + [13.37045423085531, 52.3884638993464], + [13.37213521590491, 52.39382382438767], + [13.3430284778419, 52.4076741688992], + [13.34324865284548, 52.4116199383708], + [13.31192609725129, 52.3991854713994], + [13.29613013160132, 52.41645128482860], + [13.27509994793896, 52.4052931496972], + [13.24984400348291, 52.4049647890518], + [13.24579729139539, 52.4208011454616], + [13.2222879821333, 52.4203566808027], + [13.19556683949282, 52.4150948270754], + [13.15934575071114, 52.4028799475076], + [13.15782747598388, 52.3963621565525], + [13.17135668854137, 52.3977629612759], + [13.17152155560021, 52.395833461317], + [13.15888870350185, 52.3939088980181], + [13.14261228774228, 52.3965447877649], + [13.130989522373, 52.3872248516327], + [13.1274649015897, 52.39159455243857], + [13.13811666925351, 52.3953927103099], + [13.13620177012171, 52.3986114129578], + [13.12487568418023, 52.3968795906346], + [13.11163576548908, 52.4042232789888], + [13.1079318136284, 52.409477522881], + [13.11259639288390, 52.410019075076], + [13.1115705749854, 52.4131366188073], + [13.10322506469197, 52.41022242158841], + [13.0972215065827, 52.41245465527027], + [13.09729425606538, 52.4093844819044], + [13.09063599683758, 52.4118138830970], + [13.08833321786777, 52.4196114349798], + [13.0995968844625, 52.4253047519153], + [13.10461862576225, 52.4240532166838], + [13.12317654263721, 52.4393645461878], + [13.10922327610247, 52.4506195082119], + [13.11079867671213, 52.46606301139516], + [13.1177982999609, 52.47896793572678], + [13.12528457323742, 52.48021768041821], + [13.16645760602601, 52.5101242888099], + [13.14301019275782, 52.5196755246799], + [13.11739292015149, 52.5169953257302], + [13.13061743831494, 52.55635396849858], + [13.13629581365867, 52.5527476324541], + [13.14566477898211, 52.5529113573032], + [13.15295308528006, 52.5727814253755], + [13.1496032657000, 52.58331095442416], + [13.13209246513323, 52.5796990415934], + [13.12898729114535, 52.5874421028372], + [13.14685169737853, 52.5907408192208], + [13.16426315719952, 52.5989003294822], + [13.2066263079647, 52.58674246166060], + [13.21733644150834, 52.5874555915398], + [13.21781950137233, 52.5932217092928], + [13.20160648894926, 52.60638132766547], + [13.21698464925872, 52.62011856103034], + [13.22068327203508, 52.62817871973826], + [13.26427472703923, 52.6269279691694], + [13.26215627531724, 52.64075298743773], + [13.28244070899102, 52.64129535697439], + [13.28288465178745, 52.6607846665979], + [13.31003389218788, 52.65737600751500], + [13.30037755511819, 52.65346984054808], + [13.3092574211162, 52.6431403899200], + [13.30786040925631, 52.6376207425922], + [13.30311183621051, 52.63666918729149], + [13.308309029455, 52.6296915325797], + [13.30242260293777, 52.6275606009507], + [13.31312183825852, 52.6283827130697], + [13.33648052125503, 52.6226710873883], + [13.3446134210686, 52.6247654938213], + [13.35729605679328, 52.6231746725358], + [13.3759929298861, 52.6292925936467], + [13.37437534740554, 52.63152159871212], + [13.38868271166368, 52.6376138925285], + [13.3967120928858, 52.6483013954878], + [13.40699743969849, 52.6424209979265], + [13.41282815283099, 52.6435854249661], + [13.42436518479456, 52.6356304596162], + [13.43268299132920, 52.6375076188812], + [13.43410410919631, 52.6442854870769], + [13.43989854561689, 52.6453325216004], + [13.44093207234682, 52.64912301922096], + [13.45984841933212, 52.6481031759245], + [13.47354518426134, 52.65403940079648], + [13.47389406063868, 52.6566136126278], + [13.46233317034646, 52.6574644975699], + [13.45084091655469, 52.662722173439], + [13.45951142627063, 52.66893558707466], + [13.46596538109960, 52.6671485583023], + [13.47539391700665, 52.6749171487583], + [13.47878997721379, 52.67345251981177], + [13.47551254985644, 52.66878186412850], + ] + ], + "type": "Polygon", + }, + "type": "Feature", + } + ], + "type": "FeatureCollection", + "source": "\u00a9 GeoBasis-DE / BKG 2013 (Daten ver\u00e4ndert)", +} diff --git a/adhocracy-plus/config/settings/production.py b/adhocracy-plus/config/settings/production.py index 222288b43..d61e3a066 100644 --- a/adhocracy-plus/config/settings/production.py +++ b/adhocracy-plus/config/settings/production.py @@ -16,6 +16,11 @@ except ImportError: pass +try: + from .polygons import * +except ImportError: + pass + try: INSTALLED_APPS += tuple(ADDITIONAL_APPS) except NameError: diff --git a/adhocracy-plus/templates/a4dashboard/includes/project_location_form.html b/adhocracy-plus/templates/a4dashboard/includes/project_location_form.html new file mode 100644 index 000000000..6da8eeb7d --- /dev/null +++ b/adhocracy-plus/templates/a4dashboard/includes/project_location_form.html @@ -0,0 +1,2 @@ +{% include "a4dashboard/includes/form_field.html" with field=form.administrative_district %} +{% include "a4dashboard/includes/form_field.html" with field=form.point %} diff --git a/apps/projects/dashboard.py b/apps/projects/dashboard.py index 2d314db08..263a2bc9f 100644 --- a/apps/projects/dashboard.py +++ b/apps/projects/dashboard.py @@ -7,6 +7,7 @@ from adhocracy4.dashboard.components.forms import ProjectFormComponent from adhocracy4.dashboard.forms import ProjectResultForm +from . import forms from . import views from .models import ProjectInsight from .views import ProjectResultInsightComponentFormView @@ -107,6 +108,34 @@ def get_urls(self): ] +class ProjectLocationComponent(ProjectFormComponent): + identifier = "location" + weight = 34 + label = _("Location") + + form_title = _("Edit location") + form_class = forms.PointForm + form_template_name = "a4dashboard/includes/project_location_form.html" + + def get_urls(self): + view = ProjectResultInsightComponentFormView.as_view( + component=self, + title=self.form_title, + form_class=self.form_class, + form_template_name=self.form_template_name, + ) + return [ + ( + r"^projects/(?P[-\w_]+)/{identifier}/$".format( + identifier=self.identifier + ), + view, + "dashboard-{identifier}-edit".format(identifier=self.identifier), + ) + ] + + components.register_project(ModeratorsComponent()) components.register_project(ParticipantsComponent()) components.replace_project(ProjectResultComponent()) +components.replace_project(ProjectLocationComponent()) diff --git a/apps/projects/forms.py b/apps/projects/forms.py index 3c2c6ba57..c46289a21 100644 --- a/apps/projects/forms.py +++ b/apps/projects/forms.py @@ -1,8 +1,12 @@ from django import forms +from django.conf import settings from django.contrib.auth import get_user_model from django.core.exceptions import ValidationError from django.utils.translation import gettext_lazy as _ +from adhocracy4.dashboard.forms import ProjectDashboardForm +from adhocracy4.maps import widgets as maps_widgets +from adhocracy4.projects.models import Project from apps.users import fields as user_fields from .models import ModeratorInvite @@ -64,3 +68,13 @@ def clean(self): if not self.errors and not add_users and not add_users_upload: raise ValidationError(_("Please enter email addresses or upload a file")) return cleaned_data + + +class PointForm(ProjectDashboardForm): + class Meta: + model = Project + fields = ["administrative_district", "point"] + required_for_project_publish = [] + widgets = { + "point": maps_widgets.MapChoosePointWidget(polygon=settings.BERLIN_POLYGON), + } diff --git a/apps/projects/serializers.py b/apps/projects/serializers.py index 385cb0e73..88a6cf569 100644 --- a/apps/projects/serializers.py +++ b/apps/projects/serializers.py @@ -33,6 +33,7 @@ class Meta: fields = ( "pk", "slug", + "point", "name", "description", "information", diff --git a/changelog/8304.md b/changelog/8304.md new file mode 100644 index 000000000..dd2260b06 --- /dev/null +++ b/changelog/8304.md @@ -0,0 +1,3 @@ +### Added + +- create project dashboard component for editing location