def __call__(self): if self.request.form: form = self.request.form add = str2set(form.get('add', None)) remove = str2set(form.get('remove', None)) toggle = str2set(form.get('toggle', None)) reset = 'reset' in form self.modify(add, remove, toggle, reset) self.request.RESPONSE.redirect(self.context.absolute_url())
def bodyClass(self, template, view): """Returns the CSS class to be used on the body tag. """ body_class = LayoutPolicyOriginal.bodyClass(self, template, view) columns = [] if self.have_portlets('plone.leftcolumn', view): columns.append('-one') if self.have_portlets('plone.rightcolumn', view): columns.append('-two') column_class = columns and ' has-columns%s' % ''.join(columns) or ' has-no-columns' body_class += column_class context = aq_inner(self.context) context_state = getMultiAdapter( (self.context, self.request), name=u'plone_context_state') if context_state.is_default_page(): is_nav_root = INavigationRoot.providedBy(aq_base(aq_parent(context))) else: is_nav_root = INavigationRoot.providedBy(context) if is_nav_root: body_class += ' navigation-root' portal_state = getMultiAdapter( (context, self.request), name=u'plone_portal_state') if portal_state.anonymous(): body_class += ' is-anonymous' # add classes from the registry # we have global classes (redomino.css3theme.classes) # and user defined classes (cookies) registry = getUtility(IRegistry) classes = set(registry.get('redomino.css3theme.classes', [])) userclasses = str2set(self.request.cookies.get('redomino.css3theme.userclasses', None)) useraddableclasses = set(registry.get('redomino.css3theme.useraddableclasses', [])) userclasses = userclasses & useraddableclasses classes = classes | userclasses if classes: body_class += ' %s' % ' '.join(classes) # add contextual classes contextual_classes = context.css3theme_get_contextual_classes() if contextual_classes: body_class += " %s" % contextual_classes return body_class
def modify(self, add = None, remove = None, toggle = None, reset = False): registry = getUtility(IRegistry) useraddableclasses = set(registry.get('redomino.css3theme.useraddableclasses', [])) if not reset: userclasses = str2set(self.request.cookies.get('redomino.css3theme.userclasses', None)) else: userclasses = set() def addfunc(userclasses, classes): userclasses |= classes def removefunc(userclasses, classes): userclasses -= classes def togglefunc(userclasses, classes): for c in classes: if c in userclasses: userclasses.remove(c) else: userclasses.add(c) for func in ['add', 'remove', 'toggle']: classes = locals()[func] if not classes: continue classes = classes & useraddableclasses locals()['%sfunc' % func](userclasses, classes) if userclasses: self.request.response.setCookie('redomino.css3theme.userclasses', set2str(userclasses), path="/") else: # import time # from email.Utils import formatdate # expiration_seconds = time.time()# + (5*60*60) # 5 hours from now # expires = formatdate(expiration_seconds, usegmt=True) # self.request.response.setCookie('redomino.css3theme.userclasses', '', expires=expires) # self.request.response.setCookie('redomino.css3theme.userclasses', None, path = '/', max_age = 0) self.request.response.setCookie('redomino.css3theme.userclasses', "None", path="/")