Created
February 4, 2014 11:42
-
-
Save mpampols/8802207 to your computer and use it in GitHub Desktop.
A Plone content type that creates a "minisite", this also creates new folders and contents to this new folderish content.
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
"""Definition of the minisite content type | |
""" | |
from zope.interface import implements | |
from Products.Archetypes import atapi | |
from Products.ATContentTypes.content import folder | |
from Products.ATContentTypes.content import schemata | |
from Products.PythonScripts.PythonScript import PythonScript | |
from Products.SmartColorWidget.Widget import SmartColorWidget | |
import transaction | |
minisiteSchema = folder.ATFolderSchema.copy() + atapi.Schema(( | |
atapi.StringField( | |
'TitolRegidoria', | |
storage=atapi.AnnotationStorage(), | |
widget=atapi.StringWidget( | |
label=_(u"Titol de la Regidoria"), | |
description=_(u"Introdueix el titol de la regidoria"), | |
), | |
required=False, | |
), | |
atapi.StringField( | |
'DescripcioRegidoria', | |
storage=atapi.AnnotationStorage(), | |
widget=atapi.StringWidget( | |
label=_(u"Descripcio de la Regidoria"), | |
description=_(u"Introdueix la descripcio de la regidoria"), | |
), | |
required=False, | |
), | |
atapi.TextField( | |
'TextRegidoria', | |
storage=atapi.AnnotationStorage(), | |
default_content_type = 'text/restructured', | |
default_output_type = 'text/x-html-safe', | |
allowable_content_types=('text/plain', 'text/restructured', 'text/html',), | |
widget=atapi.RichWidget( | |
label=_(u"Text de la Regidoria"), | |
description=_(u"Introdueix el text de la regidoria"), | |
), | |
required=False, | |
), | |
# Image field used for every minisite (logo regidoria) | |
atapi.ImageField( | |
'Image', | |
storage=atapi.AnnotationStorage(), | |
widget=atapi.ImageWidget( | |
label=_(u"Logotip de la regidoria"), | |
description=_(u"Selecciona la imatge principal del mini-site, el logotip de la regidoria. Tingues en compte que la imatge ha de ser un PNG transparent i tenir 144x144 pixels."), | |
), | |
required=True, | |
sizes={'standard': (144, 144)}, | |
), | |
# Social networks: Twitter | |
atapi.StringField( | |
'Twitter', | |
storage=atapi.AnnotationStorage(), | |
widget=atapi.StringWidget( | |
label=_(u"URL del perfil a Twitter"), | |
description=_(u"Introdueix la URL sencera del perfil a Twitter"), | |
), | |
required=False, | |
), | |
# Social networks: Twitter | |
atapi.StringField( | |
'Facebook', | |
storage=atapi.AnnotationStorage(), | |
widget=atapi.StringWidget( | |
label=_(u"URL del perfil a Facebook"), | |
description=_(u"Introdueix la URL sencera del perfil a Facebook"), | |
), | |
required=False, | |
), | |
# Social networks: LinkedIn | |
atapi.StringField( | |
'LinkedIn', | |
storage=atapi.AnnotationStorage(), | |
widget=atapi.StringWidget( | |
label=_(u"URL del perfil a LinedIn"), | |
description=_(u"Introdueix la URL sencera del perfil a LinkedIn"), | |
), | |
required=False, | |
), | |
# Social networks: Pinterest | |
atapi.StringField( | |
'Pinterest', | |
storage=atapi.AnnotationStorage(), | |
widget=atapi.StringWidget( | |
label=_(u"URL del perfil a Pinterest"), | |
description=_(u"Introdueix la URL sencera del perfil a Pinterest"), | |
), | |
required=False, | |
), | |
# Social networks: Instagram | |
atapi.StringField( | |
'Instagram', | |
storage=atapi.AnnotationStorage(), | |
widget=atapi.StringWidget( | |
label=_(u"URL del perfil a Instagram"), | |
description=_(u"Introdueix la URL sencera del perfil a Instagram"), | |
), | |
required=False, | |
), | |
# Social networks: Youtube | |
atapi.StringField( | |
'Youtube', | |
storage=atapi.AnnotationStorage(), | |
widget=atapi.StringWidget( | |
label=_(u"URL del perfil a Youtube"), | |
description=_(u"Introdueix la URL sencera del perfil a Youtube"), | |
), | |
required=False, | |
), | |
# Social networks: RSS | |
atapi.StringField( | |
'RSS', | |
storage=atapi.AnnotationStorage(), | |
widget=atapi.StringWidget( | |
label=_(u"URL del feed RSS"), | |
description=_(u"Introdueix la URL sencera del feed RSS"), | |
), | |
required=False, | |
), | |
# Google Analytics | |
atapi.StringField( | |
'GoogleAnalytics', | |
storage=atapi.AnnotationStorage(), | |
widget=atapi.StringWidget( | |
label=_(u"ID de Google Analytics"), | |
description=_(u"Introdueix l'identificador de GA, (Ull! No la totalitat del codi!)"), | |
), | |
required=False, | |
), | |
# Main color, a string that will be saved in hex format | |
atapi.StringField( | |
'MainColor', | |
storage=atapi.AnnotationStorage(), | |
widget=SmartColorWidget( | |
label=_(u"Color principal"), | |
description=_(u"El color principal del mini-site"), | |
), | |
required=True, | |
), | |
# Secunday color, a string that will be saved in hex format | |
atapi.StringField( | |
'SecundaryColor', | |
storage=atapi.AnnotationStorage(), | |
widget=SmartColorWidget( | |
label=_(u"Color secundari"), | |
description=_(u"El color secundari del mini-site"), | |
), | |
required=True, | |
), | |
)) | |
# Set storage on fields copied from ATFolderSchema, making sure | |
# they work well with the python bridge properties. | |
minisiteSchema['title'].storage = atapi.AnnotationStorage() | |
minisiteSchema['description'].storage = atapi.AnnotationStorage() | |
schemata.finalizeATCTSchema( | |
minisiteSchema, | |
folderish=True, | |
moveDiscussion=False | |
) | |
class minisite(folder.ATFolder): | |
"""Creates a minisite""" | |
def at_post_create_script(self, **kwargs): | |
self.setLayout("index_html") | |
# Creates a new folder for baners | |
self.invokeFactory("Folder", 'banners') | |
newObject = getattr(self, 'banners') | |
newObject.setTitle('Banners') | |
newObject.setConstrainTypesMode(1) | |
newObject.setLocallyAllowedTypes(['banner']) | |
newObject.setImmediatelyAddableTypes(['banner']) | |
newObject.setExcludeFromNav(True) | |
newObject.reindexObject() | |
transaction.commit() | |
# Header images folder | |
self.invokeFactory("Folder", 'capcaleres') | |
newObject = getattr(self, 'capcaleres') | |
newObject.setTitle('Capçaleres') | |
newObject.setConstrainTypesMode(1) | |
newObject.setLocallyAllowedTypes(['Image', 'File', 'Folder', 'banner']) | |
newObject.setImmediatelyAddableTypes(['Image', 'File', 'Folder', 'banner']) | |
newObject.setExcludeFromNav(True) | |
newObject.reindexObject() | |
transaction.commit() | |
# Folder for highlights, will contain banners | |
self.invokeFactory("Folder", 'destacats') | |
newObject = getattr(self, 'destacats') | |
newObject.setTitle('Destacats') | |
newObject.setConstrainTypesMode(1) | |
newObject.setLocallyAllowedTypes(['banner']) | |
newObject.setImmediatelyAddableTypes(['banner']) | |
newObject.setExcludeFromNav(True) | |
newObject.reindexObject() | |
transaction.commit() | |
# Folder for news items | |
self.invokeFactory("Folder", 'noticies') | |
newObject = getattr(self, 'noticies') | |
newObject.setTitle('Noticies') | |
newObject.setConstrainTypesMode(1) | |
newObject.setLocallyAllowedTypes(['Noticia', 'Image', 'File', 'Folder', 'Topic']) | |
newObject.setImmediatelyAddableTypes(['Noticia', 'Image', 'File', 'Folder', 'Topic']) | |
newObject.setLayout("folder_summary_view") | |
newObject.setExcludeFromNav(True) | |
newObject.reindexObject() | |
transaction.commit() | |
# Folder for direct links, will contain banners | |
self.invokeFactory("Folder", 'accessos') | |
newObject = getattr(self, 'accessos') | |
newObject.setTitle('Accessos') | |
newObject.setConstrainTypesMode(1) | |
newObject.setLocallyAllowedTypes(['banner']) | |
newObject.setImmediatelyAddableTypes(['banner']) | |
newObject.setExcludeFromNav(True) | |
newObject.reindexObject() | |
transaction.commit() | |
# Folder for serveis, will contain banners | |
self.invokeFactory("Folder", 'serveis') | |
newObject = getattr(self, 'serveis') | |
newObject.setTitle('Serveis') | |
newObject.setConstrainTypesMode(1) | |
newObject.setLocallyAllowedTypes(['banner']) | |
newObject.setImmediatelyAddableTypes(['banner']) | |
newObject.setExcludeFromNav(True) | |
newObject.reindexObject() | |
transaction.commit() | |
# Folder for events | |
self.invokeFactory("Folder", 'agenda') | |
newObject = getattr(self, 'agenda') | |
newObject.setTitle('Agenda') | |
newObject.setConstrainTypesMode(1) | |
newObject.setLocallyAllowedTypes(['esdeveniment', 'Image', 'File', 'Folder', 'Topic']) | |
newObject.setImmediatelyAddableTypes(['esdeveniment', 'Image', 'File', 'Folder', 'Topic']) | |
newObject.setExcludeFromNav(True) | |
newObject.reindexObject() | |
transaction.commit() | |
self.addGetRegidoriaId() | |
self.addMainColorScript() | |
self.addSecundaryColorScript() | |
self.addScript() | |
self.addStylesScript() | |
self.addAnalyticsScript() | |
def addGetRegidoriaId(self): | |
getRegidoriaIdScript = PythonScript('getRegidoriaId') | |
getRegidoriaIdScript.write("""## Script (Python) "getRegidoriaId" | |
##bind container=container | |
##bind context=context | |
##bind namespace= | |
##bind script=script | |
##bind subpath=traverse_subpath | |
##parameters= | |
##title= | |
## | |
return container.id""") | |
self._setObject("getRegidoriaId", getRegidoriaIdScript) | |
def addMainColorScript(self): | |
getRegidoriaMainColorScript = PythonScript('getRegidoriaMainColor') | |
getRegidoriaMainColorScript.write("""## Script (Python) "getRegidoriaMainColor" | |
##bind container=container | |
##bind context=context | |
##bind namespace= | |
##bind script=script | |
##bind subpath=traverse_subpath | |
##parameters= | |
##title= | |
## | |
return str('background-color:' + container.getMainColor() + ';')""") | |
self._setObject("getRegidoriaMainColor", getRegidoriaMainColorScript) | |
def addSecundaryColorScript(self): | |
getRegidoriaSecundaryColorScript = PythonScript('getRegidoriaSecundaryColor') | |
getRegidoriaSecundaryColorScript.write("""## Script (Python) "getRegidoriaSecundaryColor" | |
##bind container=container | |
##bind context=context | |
##bind namespace= | |
##bind script=script | |
##bind subpath=traverse_subpath | |
##parameters= | |
##title= | |
## | |
return str('border-' + zone + ': 7px solid ' + container.getSecundaryColor())""") | |
self._setObject("getRegidoriaSecundaryColor", getRegidoriaSecundaryColorScript) | |
def addScript(self): | |
isRegidoriaScript = PythonScript('isRegidoria') | |
isRegidoriaScript.write("""## Script (Python) "isRegidoria" | |
##bind container=container | |
##bind context=context | |
##bind namespace= | |
##bind script=script | |
##bind subpath=traverse_subpath | |
##parameters= | |
##title= | |
## | |
return True""") | |
self._setObject("isRegidoria", isRegidoriaScript) | |
def addAnalyticsScript(self): | |
getAnalyticsScript = PythonScript('getAnalyticsScript') | |
getAnalyticsScript.write("""## Script (Python) "getAnalyticsScript" | |
##bind container=container | |
##bind context=context | |
##bind namespace= | |
##bind script=script | |
##bind subpath=traverse_subpath | |
##parameters= | |
##title= | |
## | |
script = "" | |
script += "<script type='text/javascript'>" | |
script += " var _gaq = _gaq || [];" | |
script += " _gaq.push(['_setAccount', '" + container.getGoogleAnalytics() + "']);" | |
script += " _gaq.push(['_trackPageview']);" | |
script += " (function() {" | |
script += " var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;" | |
script += " ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';" | |
script += " var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);" | |
script += " })();" | |
script += "</script>" | |
return script""") | |
self._setObject("getAnalyticsScript", getAnalyticsScript) | |
def addStylesScript(self): | |
getStylesScript = PythonScript('printStyles') | |
getStylesScript.write("""## Script (Python) "printStyles" | |
##bind container=container | |
##bind context=context | |
##bind namespace= | |
##bind script=script | |
##bind subpath=traverse_subpath | |
##parameters= | |
##title= | |
## | |
styles = "<style>" | |
styles += ".your-class {}" | |
styles += "</style>" | |
return styles""") | |
self._setObject("printStyles", getStylesScript) | |
implements(Iminisite) | |
meta_type = "minisite" | |
schema = minisiteSchema | |
title = atapi.ATFieldProperty('title') | |
description = atapi.ATFieldProperty('description') | |
# -*- Your ATSchema to Python Property Bridges Here ... -*- | |
atapi.registerType(minisite, PROJECTNAME) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment