-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of github.com:maykinmedia/open-inwoner into de…
…velop
- Loading branch information
Showing
47 changed files
with
809 additions
and
218 deletions.
There are no files selected for viewing
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
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
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
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
from .appointments import UserAppointmentsPlugin | ||
from .userfeed import UserFeedPlugin | ||
from .videoplayer import VideoPlayerPlugin | ||
|
||
__all__ = [ | ||
"UserAppointmentsPlugin", | ||
"UserFeedPlugin", | ||
"VideoPlayerPlugin", | ||
] |
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,41 @@ | ||
import logging | ||
|
||
from django.utils.translation import gettext as _ | ||
|
||
from cms.plugin_base import CMSPluginBase | ||
from cms.plugin_pool import plugin_pool | ||
|
||
from open_inwoner.cms.plugins.models.appointments import UserAppointments | ||
from open_inwoner.qmatic.client import NoServiceConfigured, QmaticClient | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@plugin_pool.register_plugin | ||
class UserAppointmentsPlugin(CMSPluginBase): | ||
model = UserAppointments | ||
module = _("General") | ||
name = _("My appointments") | ||
render_template = "cms/plugins/appointments/appointments.html" | ||
|
||
def render(self, context, instance, placeholder): | ||
request = context["request"] | ||
# TODO email should be verified | ||
if not request.user.is_authenticated: | ||
return context | ||
|
||
try: | ||
client = QmaticClient() | ||
except NoServiceConfigured: | ||
logger.exception("Error occurred while creating Qmatic client") | ||
appointments = [] | ||
else: | ||
appointments = client.list_appointments_for_customer(request.user.email) | ||
|
||
context.update( | ||
{ | ||
"instance": instance, | ||
"appointments": appointments, | ||
} | ||
) | ||
return context |
45 changes: 45 additions & 0 deletions
45
src/open_inwoner/cms/plugins/migrations/0005_userappointments.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,45 @@ | ||
# Generated by Django 4.2.10 on 2024-03-28 10:07 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("cms", "0022_auto_20180620_1551"), | ||
("plugins", "0004_alter_userfeed_cmsplugin_ptr_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="UserAppointments", | ||
fields=[ | ||
( | ||
"cmsplugin_ptr", | ||
models.OneToOneField( | ||
auto_created=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
parent_link=True, | ||
primary_key=True, | ||
related_name="%(app_label)s_%(class)s", | ||
serialize=False, | ||
to="cms.cmsplugin", | ||
), | ||
), | ||
( | ||
"title", | ||
models.CharField( | ||
default="Geplande balie-afspraken", | ||
help_text="The title of the plugin block", | ||
max_length=250, | ||
verbose_name="Title", | ||
), | ||
), | ||
], | ||
options={ | ||
"abstract": False, | ||
}, | ||
bases=("cms.cmsplugin",), | ||
), | ||
] |
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
from .appointments import UserAppointments | ||
from .userfeed import UserFeed | ||
from .videoplayer import VideoPlayer | ||
|
||
__all__ = [ | ||
"UserAppointments", | ||
"UserFeed", | ||
"VideoPlayer", | ||
] |
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,16 @@ | ||
from django.db import models | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from cms.models import CMSPlugin | ||
|
||
|
||
class UserAppointments(CMSPlugin): | ||
title = models.CharField( | ||
_("Title"), | ||
max_length=250, | ||
help_text=_("The title of the plugin block"), | ||
default=_("Geplande balie-afspraken"), | ||
) | ||
|
||
def __str__(self): | ||
return self.title or super().__str__() |
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,48 @@ | ||
from django.test import TestCase, override_settings | ||
from django.urls import reverse | ||
|
||
import requests_mock | ||
from pyquery import PyQuery as PQ | ||
|
||
from open_inwoner.cms.tests import cms_tools | ||
from open_inwoner.qmatic.tests.data import QmaticMockData | ||
|
||
from ..cms_plugins import UserAppointmentsPlugin | ||
|
||
|
||
@requests_mock.Mocker() | ||
@override_settings(ROOT_URLCONF="open_inwoner.cms.tests.urls") | ||
class TestUserAppointmentsPlugin(TestCase): | ||
def test_plugin(self, m): | ||
data = QmaticMockData() | ||
data.setUpMocks(m) | ||
|
||
html, context = cms_tools.render_plugin( | ||
UserAppointmentsPlugin, plugin_data={}, user=data.user | ||
) | ||
|
||
appointments = context["appointments"] | ||
|
||
self.assertEqual(len(appointments), 2) | ||
|
||
self.assertIn("Aanvraag paspoort", html) | ||
self.assertIn("Aanvraag ID kaart", html) | ||
|
||
pyquery = PQ(html) | ||
|
||
# test item | ||
items = pyquery.find(".card-container .card") | ||
self.assertEqual(len(items), 2) | ||
|
||
aanvraag_paspoort_date = PQ(items.find("p.tabled__value")[0]).text() | ||
aanvraag_paspoort_title = PQ(items.find(".plugin-card__heading")[0]).text() | ||
aanvraag_id_kaart_date = PQ(items.find("p.tabled__value")[1]).text() | ||
aanvraag_id_kaart_title = PQ(items.find(".plugin-card__heading")[1]).text() | ||
|
||
self.assertEqual(aanvraag_paspoort_date, "1 januari 2020 om 13:00 uur") | ||
self.assertEqual(aanvraag_paspoort_title, "Aanvraag paspoort") | ||
self.assertEqual(aanvraag_id_kaart_date, "6 maart 2020 om 11:30 uur") | ||
self.assertEqual(aanvraag_id_kaart_title, "Aanvraag ID kaart") | ||
|
||
action_url = items[0].attrib["href"] | ||
self.assertEqual(action_url, reverse("profile:appointments")) |
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
Oops, something went wrong.