# HG changeset patch # User Thierry Florac # Date 1547662246 -3600 # Node ID b6d9396beffdf4710f74ba3b75567cdb7d40d883 # Parent 6c23614804f2efa2840361822ae82b234b9b1900 Added social network connection interface and adapters diff -r 6c23614804f2 -r b6d9396beffd src/pyams_content/features/share/container.py --- a/src/pyams_content/features/share/container.py Wed Jan 16 15:55:23 2019 +0100 +++ b/src/pyams_content/features/share/container.py Wed Jan 16 19:10:46 2019 +0100 @@ -12,22 +12,39 @@ __docformat__ = 'restructuredtext' +from persistent import Persistent +from zope.container.contained import Contained from zope.container.ordered import OrderedContainer -from zope.interface import implementer from zope.location import locate from zope.location.interfaces import ISublocations +from zope.schema.fieldproperty import FieldProperty from zope.traversing.interfaces import ITraversable from pyams_catalog.utils import index_object from pyams_content.features.share import ISocialShareItem -from pyams_content.features.share.interfaces import ISocialShareManager, ISocialShareManagerTarget, \ - SOCIAL_SHARE_MANAGER_KEY +from pyams_content.features.share.interfaces import ISocialShareInfo, ISocialShareManager, ISocialShareManagerTarget, \ + SOCIAL_SHARE_INFO_KEY, SOCIAL_SHARE_MANAGER_KEY from pyams_utils.adapter import ContextAdapter, adapter_config, get_annotation_adapter +from pyams_utils.factory import factory_config -@implementer(ISocialShareManager) +@factory_config(ISocialShareInfo) +class SocialShareInfo(Persistent, Contained): + """Social network share general info""" + + twitter_account = FieldProperty(ISocialShareInfo['twitter_account']) + twitter_creator_account = FieldProperty(ISocialShareInfo['twitter_creator_account']) + + +@adapter_config(context=ISocialShareManagerTarget, provides=ISocialShareInfo) +def social_share_info_factory(context): + """Social network general info factory""" + return get_annotation_adapter(context, SOCIAL_SHARE_INFO_KEY, ISocialShareInfo) + + +@factory_config(ISocialShareManager) class SocialShareManager(OrderedContainer): - """Social network share manager""" + """Social network share links manager""" last_id = 1 @@ -49,7 +66,8 @@ @adapter_config(context=ISocialShareManagerTarget, provides=ISocialShareManager) def social_share_manager_factory(context): """Social network share manager factory""" - return get_annotation_adapter(context, SOCIAL_SHARE_MANAGER_KEY, SocialShareManager, name='++social-share++') + return get_annotation_adapter(context, SOCIAL_SHARE_MANAGER_KEY, ISocialShareManager, + name='++social-share++') @adapter_config(name='social-share', context=ISocialShareManagerTarget, provides=ITraversable) diff -r 6c23614804f2 -r b6d9396beffd src/pyams_content/features/share/interfaces.py --- a/src/pyams_content/features/share/interfaces.py Wed Jan 16 15:55:23 2019 +0100 +++ b/src/pyams_content/features/share/interfaces.py Wed Jan 16 19:10:46 2019 +0100 @@ -14,16 +14,31 @@ from zope.container.constraints import containers, contains from zope.interface import Attribute, Interface -from zope.schema import Bool, Choice +from zope.schema import Bool, Choice, TextLine +from pyams_content import _ from pyams_content.interfaces.container import IOrderedContainer from pyams_content.reference.pictograms.interfaces import SELECTED_PICTOGRAM_VOCABULARY from pyams_i18n.schema import I18nTextLineField -from pyams_content import _ + +SOCIAL_SHARE_INFO_KEY = 'pyams_content.social_share.info' +SOCIAL_SHARE_MANAGER_KEY = 'pyams_content.social_share' -SOCIAL_SHARE_MANAGER_KEY = 'pyams_content.social_share' +class ISocialShareInfo(Interface): + """General social share information interface""" + + twitter_account = TextLine(title=_("Twitter account"), + description=_("Name of Twitter account (including leading '@') to use for website " + "attribution"), + required=False) + + twitter_creator_account = TextLine(title=_("Contents creator account"), + description=_("You can use another Twitter account (including leading '@') " + "for contents attribution; if empty, general Twitter account " + "will be used"), + required=False) class ISocialShareItem(Interface): diff -r 6c23614804f2 -r b6d9396beffd src/pyams_content/features/share/zmi/container.py --- a/src/pyams_content/features/share/zmi/container.py Wed Jan 16 15:55:23 2019 +0100 +++ b/src/pyams_content/features/share/zmi/container.py Wed Jan 16 19:10:46 2019 +0100 @@ -17,11 +17,18 @@ from pyramid.decorator import reify from pyramid.exceptions import NotFound from pyramid.view import view_config +from z3c.form import field from z3c.table.interfaces import IColumn, IValues +from zope.interface import implementer +from zope.schema import getFieldNamesInOrder -from pyams_content.features.share.interfaces import ISocialShareManager, ISocialShareManagerTarget +from pyams_content import _ +from pyams_content.features.share.interfaces import ISocialShareInfo, ISocialShareManager, ISocialShareManagerTarget +from pyams_content.features.share.zmi.interfaces import ISocialShareMenu from pyams_content.interfaces import MANAGE_SITE_ROOT_PERMISSION from pyams_content.zmi import pyams_content +from pyams_form.form import ajax_config +from pyams_form.group import NamedWidgetsGroup from pyams_pagelet.pagelet import pagelet_config from pyams_skin.help import ContentHelp from pyams_skin.interfaces import IContentHelp, IPageHeader @@ -33,15 +40,15 @@ from pyams_utils.fanstatic import get_resource_path from pyams_utils.url import absolute_url from pyams_viewlet.viewlet import viewlet_config -from pyams_zmi.interfaces.menu import IPropertiesMenu +from pyams_zmi.form import AdminDialogEditForm +from pyams_zmi.interfaces.menu import ISiteManagementMenu from pyams_zmi.layer import IAdminLayer from pyams_zmi.view import ContainerAdminView -from pyams_content import _ - @viewlet_config(name='social-share.menu', context=ISocialShareManagerTarget, layer=IPyAMSLayer, - manager=IPropertiesMenu, permission=MANAGE_SITE_ROOT_PERMISSION, weight=25) + manager=ISiteManagementMenu, permission=MANAGE_SITE_ROOT_PERMISSION, weight=25) +@implementer(ISocialShareMenu) class SocialShareMenu(MenuItem): """Social network share menu""" @@ -184,3 +191,39 @@ **WARNING**: don't forget to include a toolbox in your presentation template to display social networks shares!! """) message_format = 'rest' + + +# +# General social share info +# + +@viewlet_config(name='social-share-info.menu', context=ISocialShareManagerTarget, layer=IPyAMSLayer, + manager=ISocialShareMenu, permission=MANAGE_SITE_ROOT_PERMISSION, weight=10) +class SocialShareInfoMenu(MenuItem): + """Social share info menu""" + + label = _("Social networks info...") + icon_class = 'fa-twitter' + url = 'social-share-info.html' + modal_target = True + + +@pagelet_config(name='social-share-info.html', context=ISocialShareManagerTarget, layer=IPyAMSLayer, + permission=MANAGE_SITE_ROOT_PERMISSION) +@ajax_config(name='social-share-info.json', context=ISocialShareManagerTarget, layer=IPyAMSLayer) +class SocialShareInfoEditForm(AdminDialogEditForm): + """Social share info properties edit form""" + + legend = _("Edit social networks properties") + + fields = field.Fields(ISocialShareInfo) + + label_css_class = 'control-label col-md-4' + input_css_class = 'col-md-8' + + def updateGroups(self): + self.add_group(NamedWidgetsGroup(self, 'twitter', self.widgets, + getFieldNamesInOrder(ISocialShareInfo), + legend=_("Twitter account"), + css_class='inner')) + super(SocialShareInfoEditForm, self).updateGroups() diff -r 6c23614804f2 -r b6d9396beffd src/pyams_content/features/share/zmi/interfaces.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_content/features/share/zmi/interfaces.py Wed Jan 16 19:10:46 2019 +0100 @@ -0,0 +1,19 @@ +# +# Copyright (c) 2008-2019 Thierry Florac +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# + +__docformat__ = 'restructuredtext' + +from pyams_skin.interfaces.viewlet import IMenu + + +class ISocialShareMenu(IMenu): + """Social share menu marker interface""" diff -r 6c23614804f2 -r b6d9396beffd src/pyams_content/locales/fr/LC_MESSAGES/pyams_content.mo Binary file src/pyams_content/locales/fr/LC_MESSAGES/pyams_content.mo has changed diff -r 6c23614804f2 -r b6d9396beffd src/pyams_content/locales/fr/LC_MESSAGES/pyams_content.po --- a/src/pyams_content/locales/fr/LC_MESSAGES/pyams_content.po Wed Jan 16 15:55:23 2019 +0100 +++ b/src/pyams_content/locales/fr/LC_MESSAGES/pyams_content.po Wed Jan 16 19:10:46 2019 +0100 @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE 1.0\n" -"POT-Creation-Date: 2019-01-16 15:45+0100\n" +"POT-Creation-Date: 2019-01-16 19:01+0100\n" "PO-Revision-Date: 2015-09-10 10:42+0200\n" "Last-Translator: Thierry Florac \n" "Language-Team: French\n" @@ -908,7 +908,7 @@ #: src/pyams_content/component/links/interfaces.py:43 #: src/pyams_content/component/paragraph/interfaces/pictogram.py:46 -#: src/pyams_content/features/share/interfaces.py:52 +#: src/pyams_content/features/share/interfaces.py:68 #: src/pyams_content/features/menu/interfaces.py:81 #: src/pyams_content/shared/common/interfaces/types.py:59 msgid "Pictogram" @@ -2260,16 +2260,42 @@ msgid "Modification date" msgstr "Dernière modification apportée" +#: src/pyams_content/features/share/interfaces.py:33 +#: src/pyams_content/features/share/zmi/container.py:228 +msgid "Twitter account" +msgstr "Compte Twitter" + #: src/pyams_content/features/share/interfaces.py:34 +msgid "" +"Name of Twitter account (including leading '@') to use for website " +"attribution" +msgstr "" +"Nom du compte Twitter (en intégrant le '@' en tête) utilisé pour " +"l'attribution du site" + +#: src/pyams_content/features/share/interfaces.py:38 +msgid "Contents creator account" +msgstr "Compte créateur des contenus" + +#: src/pyams_content/features/share/interfaces.py:39 +msgid "" +"You can use another Twitter account (including leading '@') for contents " +"attribution; if empty, general Twitter account will be used" +msgstr "" +"Vous pouvez utiliser un autre compte Twitter (en intégrant le '@' en tête) " +"utilisé pour l'attribution des contenus ; si aucun compte n'est indiqué, c'est " +"le compte général qui sera utilisé" + +#: src/pyams_content/features/share/interfaces.py:50 msgid "Active item?" msgstr "Partage actif ?" -#: src/pyams_content/features/share/interfaces.py:35 +#: src/pyams_content/features/share/interfaces.py:51 msgid "If 'no', selected item is inactive" msgstr "Si 'non', ce mode de partage est désactivé" -#: src/pyams_content/features/share/interfaces.py:39 -#: src/pyams_content/features/share/zmi/container.py:148 +#: src/pyams_content/features/share/interfaces.py:55 +#: src/pyams_content/features/share/zmi/container.py:156 #: src/pyams_content/features/menu/zmi/__init__.py:218 #: src/pyams_content/shared/form/interfaces.py:60 #: src/pyams_content/shared/form/zmi/field.py:167 @@ -2277,15 +2303,15 @@ msgid "Label" msgstr "Libellé" -#: src/pyams_content/features/share/interfaces.py:40 +#: src/pyams_content/features/share/interfaces.py:56 msgid "This label will be associated to share link" msgstr "Ce libellé sera associé au lien de partage" -#: src/pyams_content/features/share/interfaces.py:43 +#: src/pyams_content/features/share/interfaces.py:59 msgid "Content share URL" msgstr "URL de partage" -#: src/pyams_content/features/share/interfaces.py:44 +#: src/pyams_content/features/share/interfaces.py:60 #, python-format msgid "" "URL used to share this content on given network; {url} string will be " @@ -2296,7 +2322,7 @@ "remplacée automatiquement par l'URL canonique du contenu, et la chaîne " "« {title} » (si elle est indiquée) par son titre" -#: src/pyams_content/features/share/interfaces.py:53 +#: src/pyams_content/features/share/interfaces.py:69 msgid "Name of pictogram associated with this social network" msgstr "Pictogramme à associer à ce mode de partage" @@ -2324,20 +2350,20 @@ msgid "Allow sharing" msgstr "Autoriser le partage" -#: src/pyams_content/features/share/zmi/container.py:48 +#: src/pyams_content/features/share/zmi/container.py:56 msgid "Network shares..." msgstr "Partage des contenus" -#: src/pyams_content/features/share/zmi/container.py:126 +#: src/pyams_content/features/share/zmi/container.py:134 msgid "Enable/disable item" msgstr "Activer/désactiver le partage" -#: src/pyams_content/features/share/zmi/container.py:166 -#: src/pyams_content/features/share/zmi/container.py:181 +#: src/pyams_content/features/share/zmi/container.py:174 +#: src/pyams_content/features/share/zmi/container.py:189 msgid "Social networks share" msgstr "Partage des contenus" -#: src/pyams_content/features/share/zmi/container.py:182 +#: src/pyams_content/features/share/zmi/container.py:190 msgid "" "Social networks share items are used to define share options available on " "your contents.\n" @@ -2352,7 +2378,15 @@ "**ATTENTION** : n'oubliez pas d'inclure un composant \"Boîte à outils\" dans " "vos modèles de présentation pour afficher ces liens de partage !!\n" -#: src/pyams_content/features/share/zmi/container.py:88 +#: src/pyams_content/features/share/zmi/container.py:206 +msgid "Social networks info..." +msgstr "Réseaux sociaux" + +#: src/pyams_content/features/share/zmi/container.py:218 +msgid "Edit social networks properties" +msgstr "Connexions aux réseaux sociaux" + +#: src/pyams_content/features/share/zmi/container.py:96 msgid "No currently defined social network share item." msgstr "Aucun mode de partage n'est actuellement défini." @@ -3136,10 +3170,11 @@ "first publication date for contents which have been retired and re-published " "with a different publication date" msgstr "" -"Propriété utilisée pour trier les résultats ; la date de publication d'une version peut être " -"différente de sa première date de publication lorsque cette version a été retirée puis re-publiée " -"avec une date de publication différente (la première date de publication est dans ce cas égale à " -"la date la plus en arrière dans le temps des deux)" +"Propriété utilisée pour trier les résultats ; la date de publication d'une " +"version peut être différente de sa première date de publication lorsque " +"cette version a été retirée puis re-publiée avec une date de publication " +"différente (la première date de publication est dans ce cas égale à la date " +"la plus en arrière dans le temps des deux)" #: src/pyams_content/features/search/interfaces.py:62 #: src/pyams_content/shared/site/interfaces.py:95 diff -r 6c23614804f2 -r b6d9396beffd src/pyams_content/locales/pyams_content.pot --- a/src/pyams_content/locales/pyams_content.pot Wed Jan 16 15:55:23 2019 +0100 +++ b/src/pyams_content/locales/pyams_content.pot Wed Jan 16 19:10:46 2019 +0100 @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE 1.0\n" -"POT-Creation-Date: 2019-01-16 15:45+0100\n" +"POT-Creation-Date: 2019-01-16 19:01+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" @@ -864,7 +864,7 @@ #: ./src/pyams_content/component/links/interfaces.py:43 #: ./src/pyams_content/component/paragraph/interfaces/pictogram.py:46 -#: ./src/pyams_content/features/share/interfaces.py:52 +#: ./src/pyams_content/features/share/interfaces.py:68 #: ./src/pyams_content/features/menu/interfaces.py:81 #: ./src/pyams_content/shared/common/interfaces/types.py:59 msgid "Pictogram" @@ -2132,16 +2132,37 @@ msgid "Modification date" msgstr "" +#: ./src/pyams_content/features/share/interfaces.py:33 +#: ./src/pyams_content/features/share/zmi/container.py:228 +msgid "Twitter account" +msgstr "" + #: ./src/pyams_content/features/share/interfaces.py:34 -msgid "Active item?" -msgstr "" - -#: ./src/pyams_content/features/share/interfaces.py:35 -msgid "If 'no', selected item is inactive" +msgid "" +"Name of Twitter account (including leading '@') to use for website " +"attribution" +msgstr "" + +#: ./src/pyams_content/features/share/interfaces.py:38 +msgid "Contents creator account" msgstr "" #: ./src/pyams_content/features/share/interfaces.py:39 -#: ./src/pyams_content/features/share/zmi/container.py:148 +msgid "" +"You can use another Twitter account (including leading '@') for contents " +"attribution; if empty, general Twitter account will be used" +msgstr "" + +#: ./src/pyams_content/features/share/interfaces.py:50 +msgid "Active item?" +msgstr "" + +#: ./src/pyams_content/features/share/interfaces.py:51 +msgid "If 'no', selected item is inactive" +msgstr "" + +#: ./src/pyams_content/features/share/interfaces.py:55 +#: ./src/pyams_content/features/share/zmi/container.py:156 #: ./src/pyams_content/features/menu/zmi/__init__.py:218 #: ./src/pyams_content/shared/form/interfaces.py:60 #: ./src/pyams_content/shared/form/zmi/field.py:167 @@ -2149,15 +2170,15 @@ msgid "Label" msgstr "" -#: ./src/pyams_content/features/share/interfaces.py:40 +#: ./src/pyams_content/features/share/interfaces.py:56 msgid "This label will be associated to share link" msgstr "" -#: ./src/pyams_content/features/share/interfaces.py:43 +#: ./src/pyams_content/features/share/interfaces.py:59 msgid "Content share URL" msgstr "" -#: ./src/pyams_content/features/share/interfaces.py:44 +#: ./src/pyams_content/features/share/interfaces.py:60 #, python-format msgid "" "URL used to share this content on given network; {url} string will be " @@ -2165,7 +2186,7 @@ " (if required)" msgstr "" -#: ./src/pyams_content/features/share/interfaces.py:53 +#: ./src/pyams_content/features/share/interfaces.py:69 msgid "Name of pictogram associated with this social network" msgstr "" @@ -2193,27 +2214,35 @@ msgid "Allow sharing" msgstr "" -#: ./src/pyams_content/features/share/zmi/container.py:48 +#: ./src/pyams_content/features/share/zmi/container.py:56 msgid "Network shares..." msgstr "" -#: ./src/pyams_content/features/share/zmi/container.py:126 +#: ./src/pyams_content/features/share/zmi/container.py:134 msgid "Enable/disable item" msgstr "" -#: ./src/pyams_content/features/share/zmi/container.py:166 -#: ./src/pyams_content/features/share/zmi/container.py:181 +#: ./src/pyams_content/features/share/zmi/container.py:174 +#: ./src/pyams_content/features/share/zmi/container.py:189 msgid "Social networks share" msgstr "" -#: ./src/pyams_content/features/share/zmi/container.py:182 +#: ./src/pyams_content/features/share/zmi/container.py:190 msgid "" "Social networks share items are used to define share options available on your contents.\n" " \n" "**WARNING**: don't forget to include a toolbox in your presentation template to display social networks shares!!\n" msgstr "" -#: ./src/pyams_content/features/share/zmi/container.py:88 +#: ./src/pyams_content/features/share/zmi/container.py:206 +msgid "Social networks info..." +msgstr "" + +#: ./src/pyams_content/features/share/zmi/container.py:218 +msgid "Edit social networks properties" +msgstr "" + +#: ./src/pyams_content/features/share/zmi/container.py:96 msgid "No currently defined social network share item." msgstr ""