-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Objects API client integration #793
Closed
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
cb0b4c0
Merge pull request #328 from maykinmedia/develop
alextreme 3489d34
Merge branch 'develop'
alextreme 7b66eb3
Merge pull request #400 from maykinmedia/develop
alextreme 52aa46a
Merge pull request #470 from maykinmedia/develop
alextreme 4c2dd06
Merge pull request #549 from maykinmedia/develop
alextreme 65343c1
Merge pull request #564 from maykinmedia/develop
alextreme a041ff7
Merge pull request #646 from maykinmedia/develop
alextreme 26339be
Merge pull request #696 from maykinmedia/develop
alextreme e38bd06
Merge branch 'main' of github.com:maykinmedia/open-inwoner
alextreme 8a88706
Merge branch 'develop'
alextreme e7a9f09
Merge pull request #721 from maykinmedia/develop
alextreme 1e89fbf
Merge pull request #757 from maykinmedia/develop
alextreme 2a9e24b
Merge pull request #761 from maykinmedia/develop
alextreme 5b6f10b
Merge pull request #805 from maykinmedia/develop
alextreme f5ac14f
Merge pull request #806 from maykinmedia/develop
alextreme 49a432f
Adding Objects API client integration
alextreme 9ab9676
:sparkles: [#1776] added task components
bart-maykin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
from cms.plugin_base import CMSPluginBase | ||
from cms.plugin_pool import plugin_pool | ||
|
||
from .models import ComponentChoices, ObjectsList | ||
|
||
|
||
@plugin_pool.register_plugin | ||
class ObjectsListPlugin(CMSPluginBase): | ||
model = ObjectsList | ||
name = _("Object List Plugin") | ||
render_template = "cms/objects/objects_list.html" | ||
cache = False | ||
|
||
def _get_render_template(self, context, instance, placeholder): | ||
default_template = super()._get_render_template(context, instance, placeholder) | ||
if component := instance.component: | ||
match component: | ||
case ComponentChoices.link: | ||
return "cms/objects/objects_list.html" | ||
case ComponentChoices.map: | ||
return "cms/objects/objects_map.html" | ||
|
||
return default_template | ||
|
||
def render(self, context, instance, placeholder): | ||
request = context["request"] | ||
context["instance"] = instance | ||
context["objects"] = [] | ||
|
||
if request.user.is_authenticated and (bsn := request.user.bsn): | ||
objects = instance.get_objects_by_bsn(bsn) | ||
match instance.component: | ||
case ComponentChoices.link: | ||
context["objects"] = instance.convert_objects_to_actiondata(objects) | ||
case ComponentChoices.map: | ||
context["objects"] = instance.convert_objects_to_geodata(objects) | ||
return context |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
from djchoices import ChoiceItem, DjangoChoices | ||
|
||
|
||
class StatusChoices(DjangoChoices): | ||
open = ChoiceItem("open", _("Open")) | ||
submitted = ChoiceItem("ingediend", _("Submitted")) | ||
processed = ChoiceItem("verwerkt", _("Processed")) | ||
closed = ChoiceItem("gesloten", _("Closed")) | ||
|
||
|
||
class DateOrderChoices(DjangoChoices): | ||
ascend = ChoiceItem("+", _("Ascend")) | ||
descent = ChoiceItem("-", _("Descent")) | ||
|
||
|
||
class ComponentChoices(DjangoChoices): | ||
link = ChoiceItem("link", _("Link")) | ||
map = ChoiceItem("map", _("Map")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Generated by Django 3.2.20 on 2023-09-17 20:14 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
import objectsapiclient.models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
("cms", "0022_auto_20180620_1551"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="ObjectsList", | ||
fields=[ | ||
( | ||
"cmsplugin_ptr", | ||
models.OneToOneField( | ||
auto_created=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
parent_link=True, | ||
primary_key=True, | ||
related_name="objects_objectslist", | ||
serialize=False, | ||
to="cms.cmsplugin", | ||
), | ||
), | ||
("title", models.CharField(max_length=250, verbose_name="Title")), | ||
( | ||
"object_type", | ||
objectsapiclient.models.ObjectTypeField( | ||
db_index=False, max_length=100 | ||
), | ||
), | ||
], | ||
options={ | ||
"abstract": False, | ||
}, | ||
bases=("cms.cmsplugin",), | ||
), | ||
] |
131 changes: 131 additions & 0 deletions
131
src/open_inwoner/cms/objects/migrations/0002_auto_20231006_1047.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
# Generated by Django 3.2.20 on 2023-10-06 08:47 | ||
|
||
import django.core.validators | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("objects", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="objectslist", | ||
name="bsn_path", | ||
field=models.CharField( | ||
blank=True, | ||
help_text="The path to the bsn value from data, for example: 'identificatie.value'", | ||
max_length=250, | ||
verbose_name="BSN Path", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="objectslist", | ||
name="component", | ||
field=models.CharField( | ||
choices=[("link", "Link"), ("map", "Map")], | ||
default="link", | ||
max_length=30, | ||
verbose_name="Component", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="objectslist", | ||
name="date_order", | ||
field=models.CharField( | ||
choices=[("+", "Ascend"), ("-", "Descent")], | ||
default="-", | ||
help_text="Order date on acending or decending.", | ||
max_length=1, | ||
verbose_name="Date Order", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="objectslist", | ||
name="map_lat", | ||
field=models.DecimalField( | ||
decimal_places=6, | ||
default=52.1326, | ||
max_digits=9, | ||
verbose_name="Map starting Latitude", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="objectslist", | ||
name="map_long", | ||
field=models.DecimalField( | ||
decimal_places=6, | ||
default=5.2913, | ||
max_digits=9, | ||
verbose_name="Map starting Longitude", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="objectslist", | ||
name="map_zoom_level", | ||
field=models.IntegerField( | ||
default=3, | ||
validators=[ | ||
django.core.validators.MaxValueValidator(18), | ||
django.core.validators.MinValueValidator(1), | ||
], | ||
verbose_name="Map starting Longitude", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="objectslist", | ||
name="no_results_message", | ||
field=models.TextField( | ||
default="no results found", | ||
help_text="Text message to tell the user that there are no results found", | ||
verbose_name="No results message", | ||
), | ||
preserve_default=False, | ||
), | ||
migrations.AddField( | ||
model_name="objectslist", | ||
name="object_date", | ||
field=models.CharField( | ||
default="start_at", | ||
help_text="The path to the date, for example: 'start_at'", | ||
max_length=250, | ||
verbose_name="Object Date", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="objectslist", | ||
name="object_link", | ||
field=models.CharField( | ||
default="data.formulier.value", | ||
help_text="The path to the url, for example: 'data.formulier.value'", | ||
max_length=250, | ||
verbose_name="Object Link", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="objectslist", | ||
name="object_title", | ||
field=models.CharField( | ||
default="data.title", | ||
help_text="The path to the title, for example: 'data.title'", | ||
max_length=250, | ||
verbose_name="Object Title", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="objectslist", | ||
name="status", | ||
field=models.CharField( | ||
blank=True, | ||
choices=[ | ||
("open", "Open"), | ||
("ingediend", "Submitted"), | ||
("verwerkt", "Processed"), | ||
("gesloten", "Closed"), | ||
], | ||
max_length=250, | ||
verbose_name="Status", | ||
), | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
import json | ||
|
||
from django.core.validators import MaxValueValidator, MinValueValidator | ||
from django.db import models | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
from cms.models import CMSPlugin | ||
from glom import glom | ||
from glom.core import PathAccessError, PathAssignError | ||
from objectsapiclient.models import Configuration, ObjectTypeField | ||
|
||
from .constants import ComponentChoices, DateOrderChoices, StatusChoices | ||
|
||
|
||
class ObjectsList(CMSPlugin): | ||
title = models.CharField(_("Title"), max_length=250) | ||
object_type = ObjectTypeField() # Stores the UUID of the selected object_type | ||
status = models.CharField( | ||
_("Status"), | ||
max_length=250, | ||
choices=StatusChoices.choices, | ||
blank=True, | ||
) | ||
component = models.CharField( | ||
_("Component"), | ||
max_length=30, | ||
choices=ComponentChoices.choices, | ||
default=ComponentChoices.link, | ||
) | ||
no_results_message = models.TextField( | ||
_("No results message"), | ||
help_text=_("Text message to tell the user that there are no results found"), | ||
) | ||
date_order = models.CharField( | ||
_("Date Order"), | ||
help_text=_("Order date on acending or decending."), | ||
max_length=1, | ||
choices=DateOrderChoices.choices, | ||
default=DateOrderChoices.descent, | ||
) | ||
map_lat = models.DecimalField( | ||
_("Map starting Latitude"), max_digits=9, decimal_places=6, default=52.1326 | ||
) | ||
map_long = models.DecimalField( | ||
_("Map starting Longitude"), max_digits=9, decimal_places=6, default=5.2913 | ||
) | ||
map_zoom_level = models.IntegerField( | ||
_("Map starting Longitude"), | ||
validators=[MaxValueValidator(18), MinValueValidator(1)], | ||
default=3, | ||
) | ||
bsn_path = models.CharField( | ||
_("BSN Path"), | ||
max_length=250, | ||
help_text=_( | ||
"The path to the bsn value from data, for example: 'identificatie.value'" | ||
), | ||
blank=True, | ||
) | ||
object_title = models.CharField( | ||
_("Object Title"), | ||
max_length=250, | ||
default="data.title", | ||
help_text=_("The path to the title, for example: 'data.title'"), | ||
) | ||
object_date = models.CharField( | ||
_("Object Date"), | ||
max_length=250, | ||
default="start_at", | ||
help_text=_("The path to the date, for example: 'start_at'"), | ||
) | ||
object_link = models.CharField( | ||
_("Object Link"), | ||
max_length=250, | ||
default="data.formulier.value", | ||
help_text=_("The path to the url, for example: 'data.formulier.value'"), | ||
) | ||
|
||
def _return_self(self): | ||
return f"{self.title}, {self.object_type}, {self.bsn_path}" | ||
|
||
def get_objects(self): | ||
return Configuration.get_solo().client.get_objects( | ||
object_type_uuid=self.object_type | ||
) | ||
|
||
def get_objects_by_bsn(self, bsn): | ||
data_attrs = [] | ||
if self.object_type and self.bsn_path: | ||
data_attrs.append( | ||
"__".join(self.bsn_path.split(".")) + "__exact__" + str(bsn) | ||
) | ||
if self.status: | ||
data_attrs.append("status__exact__" + self.status) | ||
|
||
return Configuration.get_solo().client.get_objects_by_bsn( | ||
object_type_uuid=self.object_type, | ||
ordering=self.date_order + "record__startAt", | ||
data_attrs=",".join(data_attrs), | ||
) | ||
|
||
def convert_objects_to_actiondata(self, objects): | ||
object_list = [] | ||
if objects: | ||
for object in objects: | ||
try: | ||
object_list.append( | ||
{ | ||
"title": glom(object.record, self.object_title), | ||
"date": glom(object.record, self.object_date), | ||
"link": glom(object.record, self.object_link), | ||
} | ||
) | ||
except (PathAccessError, PathAssignError): | ||
pass | ||
|
||
return object_list | ||
|
||
def convert_objects_to_geodata(self, objects): | ||
features = [] | ||
if objects: | ||
for object in objects: | ||
if geometry := object.record.get("geometry"): | ||
try: | ||
features.append( | ||
{ | ||
"type": "Feature", | ||
"geometry": geometry, | ||
"properties": { | ||
"name": glom(object.record, self.object_title), | ||
"date": glom(object.record, self.object_date), | ||
"link": glom(object.record, self.object_link), | ||
}, | ||
} | ||
) | ||
except (PathAccessError, PathAssignError): | ||
pass | ||
|
||
return json.dumps( | ||
{ | ||
"type": "FeatureCollection", | ||
"features": features, | ||
} | ||
) | ||
|
||
def __str__(self): | ||
return self.title |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The project uses python 3.9 so no pattern matching.