Skip to content

Commit

Permalink
WEB-4134 : Manage timestamping in coordination with ia.deliberations'…
Browse files Browse the repository at this point in the history
… rest api
  • Loading branch information
boulch committed Aug 30, 2024
1 parent 46a9e42 commit ce9c699
Show file tree
Hide file tree
Showing 31 changed files with 863 additions and 24 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Changelog
1.2.67 (unreleased)
-------------------

- Nothing changed yet.
- WEB-4134 : Manage timestamping in coordination with ia.deliberations' rest api
[boulch]


1.2.66 (2024-08-27)
Expand Down
33 changes: 33 additions & 0 deletions src/imio/smartweb/core/browser/controlpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from collective.z3cform.datagridfield.datagridfield import DataGridFieldFactory
from collective.z3cform.datagridfield.registry import DictRow
from imio.smartweb.locales import SmartwebMessageFactory as _
from plone import api
from plone.app.registry.browser.controlpanel import ControlPanelFormWrapper
from plone.app.registry.browser.controlpanel import RegistryEditForm
from plone.autoform import directives
Expand Down Expand Up @@ -165,12 +166,44 @@ class ISmartwebControlPanel(Interface):
required=False,
)

iadeliberations_api_username = schema.TextLine(
title=_("Username to consume I.A. Deliberations API"),
required=False,
)

iadeliberation_api_password = schema.Password(
title=_("Password to consume I.A. Deliberations API"),
required=False,
)

iadeliberations_institution = schema.Choice(
title=_("I.A. Deliberations : Institutions"),
source="imio.smartweb.vocabulary.IADeliberationsInstitutions",
required=False,
)


class SmartwebControlPanelForm(RegistryEditForm):
schema = ISmartwebControlPanel
schema_prefix = "smartweb"
label = _("Smartweb Settings")

def applyChanges(self, data):
# Get current registry value for (controlpanel) passwords
iadeliberation_pwd = api.portal.get_registry_record(
"smartweb.iadeliberation_api_password"
)
secret_key_api = api.portal.get_registry_record("smartweb.secret_key_api")

# if data is None when we apply changes for password fields we keep password from registry
if not data.get("iadeliberation_api_password"):
data["iadeliberation_api_password"] = iadeliberation_pwd

if not data.get("secret_key_api"):
data["secret_key_api"] = secret_key_api

return super().applyChanges(data)


SmartwebControlPanelView = layout.wrap_form(
SmartwebControlPanelForm, ControlPanelFormWrapper
Expand Down
2 changes: 2 additions & 0 deletions src/imio/smartweb/core/contents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from .pages.portal_page.content import PortalPage # NOQA
from .pages.procedure.content import IProcedure # NOQA
from .pages.procedure.content import Procedure # NOQA
from .publication.content import Publication # NOQA
from .publication.content import IPublication # NOQA
from .rest.base import RestView # NOQA
from .rest.base import IRestView # NOQA
from .rest.directory.content import DirectoryView # NOQA
Expand Down
1 change: 1 addition & 0 deletions src/imio/smartweb/core/contents/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<include package=".blocks" />
<include package=".folder" />
<include package=".pages" />
<include package=".publication" />
<include package=".rest" />
<include package=".sections" />

Expand Down
Empty file.
5 changes: 5 additions & 0 deletions src/imio/smartweb/core/contents/publication/configure.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser">

</configure>
27 changes: 27 additions & 0 deletions src/imio/smartweb/core/contents/publication/content.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-

from imio.smartweb.locales import SmartwebMessageFactory as _
from plone.dexterity.content import Item
from zope import schema
from zope.interface import implementer
from zope.interface import Interface


class IPublication(Interface):
""" """

# title = schema.TextLine(title=_("Title"), required=True)

# description = schema.Text(title=_("Description"), required=False)

linked_publication = schema.Choice(
vocabulary="imio.smartweb.vocabulary.IADeliberationsPublications",
title=_("I.A. Deliberation publication"),
required=True,
default=None,
)


@implementer(IPublication)
class Publication(Item):
"""Publication class"""
16 changes: 13 additions & 3 deletions src/imio/smartweb/core/contents/sections/common_templates/table.pt
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@
show_lead_image python:getattr(context, 'show_items_lead_image', True);
portal context/@@plone_portal_state/portal;
open_in_new_tab item/open_in_new_tab | nothing;"
tal:attributes="class string:table_display ${item/container_id | nothing};"
tal:attributes="class string:table_display ${item/container_id | nothing} ${item/smartweb_type | nothing};"
>
<a tal:attributes="class python:'table_image no-image' if no_icon_no_image else 'table_image';
href item/url;
href python:view.retrieve_item_url(item);
target python:'_blank' if (open_in_new_tab and not can_edit_sections) else '';">
<tal:if tal:condition="show_lead_image">
<div class="image d-block is-icon w-100"
Expand All @@ -85,7 +85,7 @@
</div>

<div class="table_date"
tal:condition="context/show_items_date | nothing">
tal:condition="context/show_items_date | context/has_publications | nothing">
<tal:if tal:condition="item/effective | nothing">
<span i18n:translate="">Published</span>
<span class="pat-display-time"
Expand All @@ -97,6 +97,9 @@
<metal:macro use-macro="context/@@macros/event_date" />
</tal:def>
</tal:if>
<tal:if tal:condition="item/publication_datetime | nothing">
<span class="publication_datetime" tal:content="python:view.datetime_format(item,'publication_datetime')"/>
</tal:if>
</div>
<div tal:condition="view/display_container_title"
class="auth_source_container_title"
Expand All @@ -115,6 +118,13 @@
tal:condition="item/item_infos | nothing"
tal:content="item/item_infos"/>
</a>
<!-- publication : attached file-->
<a
tal:condition="item/publication_attached_file | nothing"
tal:attributes="href item/publication_attached_file/download"
tal:content="item/publication_attached_file/filename"
target="_blank" ></a>

</div>
</li>

Expand Down
8 changes: 7 additions & 1 deletion src/imio/smartweb/core/contents/sections/files/content.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-

from imio.smartweb.core.contents import IPublication
from imio.smartweb.core.contents.sections.base import ISection
from imio.smartweb.core.contents.sections.base import Section
from imio.smartweb.locales import SmartwebMessageFactory as _
Expand Down Expand Up @@ -30,3 +30,9 @@ class SectionFiles(Section):
"""SectionText class"""

manage_content = True

def has_publications(self):
for item in self.items():
if IPublication.providedBy(item[1]):
return True
return False
49 changes: 38 additions & 11 deletions src/imio/smartweb/core/contents/sections/files/view.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-

from imio.smartweb.core.contents import IPublication
from imio.smartweb.core.contents.sections.views import CarouselOrTableSectionView
from imio.smartweb.core.utils import batch_results
from imio.smartweb.core.utils import get_scale_url
from plone import api
from zope.component import queryMultiAdapter


Expand All @@ -12,7 +13,7 @@ class FilesView(CarouselOrTableSectionView):
def items(self):
orientation = self.context.orientation
image_scale = self.image_scale
items = self.context.listFolderContents()
items = super(FilesView, self).items()
results = []
for item in items:
url = item.absolute_url()
Expand All @@ -21,14 +22,40 @@ def items(self):
scale_url = get_scale_url(
item, self.request, "image", image_scale, orientation
)
results.append(
{
"title": item.title,
"description": item.description,
"url": url,
"image": scale_url,
"has_image": has_image,
"item_infos": file_view.human_readable_size(),
}
dict_item = {
"title": item.title,
"description": item.description,
"smartweb_type": item.smartweb_type,
"url": url,
"image": scale_url,
"has_image": has_image,
}
dict_item["item_infos"] = (
None if file_view is None else file_view.human_readable_size()
)
if IPublication.providedBy(item):
extra_properties = [
"linked_publication",
"publication_datetime",
"publication_url",
"publication_document_type",
"publication_attached_file",
]
dict_item = self.get_publication_extra_properties(
item, dict_item, extra_properties
)

results.append(dict_item)
return batch_results(results, self.context.nb_results_by_batch)

def retrieve_item_url(self, item):
if item.get("publication_url", None) is not None and api.user.is_anonymous():
# return "real" publication url in iadeliberation
return item.get("publication_url")
# return smartweb item url
return item.get("url")

def get_publication_extra_properties(self, item, dict_item, extra_properties):
for prop in extra_properties:
dict_item[prop] = getattr(item, prop, None)
return dict_item
25 changes: 19 additions & 6 deletions src/imio/smartweb/core/contents/sections/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ def save_size(self):
class CarouselOrTableSectionView(SectionView):
"""Section view that can display a carousel"""

def items(self):
items = self.context.listFolderContents()
for item in items:
item.smartweb_type = "Item"
item.container_id = ""
portal_type = getattr(item, "portal_type", None)
if portal_type:
item.smartweb_type = portal_type.split(".")[-1]
return items

@property
def image_scale(self):
layout = self.context.getLayout()
Expand All @@ -114,25 +124,28 @@ def image_scale(self):
else:
return getattr(self.context, "image_scale", "")

def datetime_format(self, item):
def datetime_format(self, item, datetime_field="effective"):
"""
item.get("effective", None)
=> DateTime('YYYY/MM/DD HH:mm:ss.000000 GMT+1')
convert to more conventional datetime format
and return its string representation
"""
effective = item.get("effective", None)
if effective is None:
datetime_field = item.get(datetime_field, None)
if datetime_field is None:
return ""
target_timezone = pytz.timezone("Europe/Paris")
if isinstance(effective, str):
return effective
dt = effective.asdatetime()
if isinstance(datetime_field, str):
return datetime_field
dt = datetime_field.asdatetime()
target_datetime = dt.astimezone(target_timezone)
output_format = "%Y-%m-%dT%H:%M:%S%z"
formatted_datetime_str = target_datetime.strftime(output_format)
return formatted_datetime_str

def retrieve_item_url(self, item):
return item.get("url")


class HashableJsonSectionView(SectionView):
json_data = None
Expand Down
2 changes: 1 addition & 1 deletion src/imio/smartweb/core/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<metadata>
<version>1059</version>
<version>1061</version>
<dependencies>
<dependency>profile-plone.app.dexterity:default</dependency>
<dependency>profile-plone.app.imagecropping:default</dependency>
Expand Down
1 change: 1 addition & 0 deletions src/imio/smartweb/core/profiles/default/types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<object meta_type="Dexterity FTI" name="imio.smartweb.Page"/>
<object meta_type="Dexterity FTI" name="imio.smartweb.PortalPage"/>
<object meta_type="Dexterity FTI" name="imio.smartweb.Procedure"/>
<object meta_type="Dexterity FTI" name="imio.smartweb.Publication"/>
<object meta_type="Dexterity FTI" name="imio.smartweb.SectionCollection"/>
<object meta_type="Dexterity FTI" name="imio.smartweb.SectionContact"/>
<object meta_type="Dexterity FTI" name="imio.smartweb.SectionEvents"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0"?>
<object xmlns:i18n="http://xml.zope.org/namespaces/i18n"
name="imio.smartweb.Publication"
meta_type="Dexterity FTI"
i18n:domain="imio.smartweb">

<!-- Basic properties -->
<property
i18n:translate=""
name="title">Publication</property>
<property
i18n:translate=""
name="description">IA.Deliberations : Publication</property>

<property name="icon_expr">string:bounding-box-circles</property>

<!-- Hierarchy control -->
<property name="global_allow">False</property>

<!-- Schema, class and security -->
<!-- if we can add a page, we can add a page section -->
<property name="add_permission">imio.smartweb.core.AddPage</property>
<property name="klass">imio.smartweb.core.contents.Publication</property>
<property name="schema">imio.smartweb.core.contents.IPublication</property>

<!-- Enabled behaviors -->
<property name="behaviors" purge="false">
<!--element value="plone.namefromtitle"/>
<element value="plone.shortname"/> -->
<element value="plone.imagecropping"/>
<element value="plone.locking"/>
<element value="solr.fields" />
</property>

# get

<!-- View information -->
<property name="default_view">link_redirect_view</property>
<property name="default_view_fallback">False</property>
<property name="immediate_view">view</property>
<property name="view_methods">
<element value="link_redirect_view"/>
</property>

</object>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<property name="filter_content_types">True</property>
<property name="allowed_content_types">
<element value="File" />
<element value="imio.smartweb.Publication" />
</property>
<!-- Schema, class and security -->
<!-- if we can add a page, we can add a page section -->
Expand Down
Loading

0 comments on commit ce9c699

Please sign in to comment.