class UserRelation(UserMember): instantiable = False groups_order = UserMember.groups_order member_class = schema.RelationMember member_related_key = schema.String(listed_by_default=False, text_search=False, member_group="definition") member_bidirectional = schema.Boolean(required=True, default=False, listed_by_default=False, member_group="definition") member_integral = schema.Boolean(required=True, default=False, listed_by_default=False, member_group="definition") member_cascade_delete = schema.Boolean(required=True, default=False, listed_by_default=False, member_group="definition") member_text_search = schema.Boolean(required=True, default=True, listed_by_default=False, member_group="behavior")
class MenuBlock(Block): instantiable = True view_class = "woost.views.Menu" root = schema.Reference(type=Document, related_end=schema.Collection(), member_group="content") root_visible = schema.Boolean(required=True, default=False, member_group="content") max_depth = schema.Integer(member_group="content") expanded = schema.Boolean(required=True, default=False, member_group="content") def init_view(self, view): Block.init_view(self, view) view.root = self.root view.root_visible = self.root_visible view.max_depth = self.max_depth view.expanded = self.expanded
class UserString(UserMember): instantiable = True groups_order = UserMember.groups_order member_class = schema.String edit_controls = [ "cocktail.html.TextBox", "cocktail.html.PasswordBox", "cocktail.html.TextArea", "woost.views.RichTextEditor" ] search_controls = ["cocktail.html.TextBox"] member_min = schema.Integer(listed_by_default=False, member_group="constraints") member_max = schema.Integer(min=member_min, listed_by_default=False, member_group="constraints") member_format = schema.String(listed_by_default=False, text_search=False, member_group="constraints") member_text_search = schema.Boolean(required=True, default=True, listed_by_default=False, member_group="behavior") member_normalized_index = schema.Boolean(required=True, default=True, listed_by_default=False, member_group="definition")
def form_model(self): from woost.extensions.staticsite import StaticSiteExtension extension = StaticSiteExtension.instance site_languages = Configuration.instance.languages def allowed_destinations(): return [ destination for destination in extension.destinations if get_current_user().has_permission( ExportationPermission, destination = destination ) ] return schema.Schema("ExportStaticSite", members = [ schema.Reference( "snapshoter", type = "woost.extensions.staticsite.staticsitesnapshoter." "StaticSiteSnapShoter", required = True, enumeration = lambda ctx: extension.snapshoters, edit_control = "cocktail.html.RadioSelector" if len(allowed_destinations()) > 1 else "cocktail.html.HiddenInput", default = schema.DynamicDefault(lambda: extension.snapshoters[0]) ), schema.Reference( "destination", type = "woost.extensions.staticsite.staticsitedestination." "StaticSiteDestination", required = True, enumeration = lambda ctx: allowed_destinations(), edit_control = "cocktail.html.RadioSelector" if len(allowed_destinations()) > 1 else "cocktail.html.HiddenInput", default = schema.DynamicDefault(lambda: allowed_destinations()[0]) ), schema.Boolean( "update_only", required = True, default = True ), schema.Boolean( "follow_links", required = True, default = True ) ])
class VideoPlayerSettings(Item): instantiable = True visible_from_root = False player_initialization = TypeMapping() members_order = [ "title", "width", "height", "autoplay", "show_player_controls" ] title = schema.String( listed_by_default = False, required = True, unique = True, indexed = True, normalized_index = True, full_text_indexed = True, descriptive = True, translated = True ) width = schema.Integer( required = True, default = 480, listed_by_default = False ) height = schema.Integer( required = True, default = 385, listed_by_default = False ) autoplay = schema.Boolean( required = True, default = False, listed_by_default = False ) show_player_controls = schema.Boolean( required = True, default = True, listed_by_default = False ) def create_player(self, video): player = templates.new(video.video_player) player_initialization = self.player_initialization.get(video.__class__) if player_initialization: player_initialization(player, self, video) return player
class UserReference(UserRelation): instantiable = True groups_order = UserMember.groups_order member_class = schema.Reference edit_controls = [ "cocktail.html.DropdownSelector", "cocktail.html.RadioSelector", "woost.views.ItemSelector" ] search_controls = [ "cocktail.html.DropdownSelector", "cocktail.html.RadioSelector", "woost.views.ItemSelector" ] member_type = schema.Reference(class_family=Item, member_group="definition") member_class_family = schema.Reference(class_family=Item, member_group="definition") member_type.exclusive = member_class_family.not_() member_class_family = member_type.not_() member_cycles_allowed = schema.Boolean(required=True, default=True, listed_by_default=False, member_group="definition")
class Permission(Item): type_group = "access" instantiable = False visible_from_root = False authorized = schema.Boolean(required=True, default=True) role = schema.Reference(type="woost.models.Role", bidirectional=True, min=1) def match(self, verbose=False): """Indicates if the permission matches the given context. @return: True if the permission matches, False otherwise. @rtype: bool """ return True def __translate__(self, language, **kwargs): return translations(self.__class__.full_name + "-instance", language, instance=self, **kwargs) or Item.__translate__( self, language, **kwargs) @classmethod def permission_not_found(cls, user, verbose=False, **context): if verbose: print unauthorized_style("unauthorized") return False
def form_schema(self): form_schema = EditNode.form_schema(self) password_member = form_schema.get_member("synchronization_password") if password_member: if User.encryption_method: order = form_schema.members_order = list(form_schema.members_order) pos = order.index("synchronization_password") if self.item.is_inserted: change_password_member = schema.Boolean( name = "change_password", required = True, default = False, visible_in_detail_view = False ) form_schema.add_member(change_password_member) order.insert(pos, "change_password") password_member.exclusive = change_password_member # No encryption: edit passwords in plain sight else: password_member.edit_control = "cocktail.html.TextBox" return form_schema
class CustomDefinition(Item): visible_from_root = False members_order = [ "title", "identifier", "definition_type", "enabled", "content_types", "initialization" ] title = schema.String(required=True, indexed=True, unique=True, translated=True, descriptive=True) identifier = schema.String() definition_type = schema.String(required=True, default="dimension", enumeration=["dimension", "metric"]) enabled = schema.Boolean(required=True, default=True) content_types = schema.Collection( items=schema.Reference(class_family=Item), default=[Publishable], min=1) initialization = schema.CodeBlock(language="python") def applies(self, publishable, website=None): return isinstance(publishable, tuple(self.content_types)) def apply(self, publishable, values, index=None, env=None): if not self.initialization: return if index is None: from woost.models import Configuration defs = Configuration.instance.google_analytics_custom_definitions index = defs.index(self) context = { "publishable": publishable, "index": index, "value": schema.undefined, "undefined": schema.undefined, "env": {} if env is None else env } CustomDefinition.initialization.execute(self, context) index = context["index"] if index is not None: value = context["value"] if value is not schema.undefined: key = self.definition_type + str(index) value = get_ga_value(value) values[key] = value
class Style(Item): type_group = "customization" members_order = [ "title", "applicable_to_text", "applicable_to_blocks", "custom_class_name", "declarations", "admin_declarations" ] title = schema.String(required=True, unique=True, indexed=True, normalized_index=True, full_text_indexed=True, descriptive=True, translated=True, listed_by_default=False) applicable_to_text = schema.Boolean(required=True, indexed=True, default=True, listed_by_default=False) applicable_to_blocks = schema.Boolean(required=True, default=True, indexed=True, listed_by_default=False) custom_class_name = schema.String(indexed=True, unique=True, normalized_index=False, listed_by_default=False) declarations = schema.String(text_search=False, edit_control="cocktail.html.TextArea", listed_by_default=False) admin_declarations = schema.String(text_search=False, edit_control="cocktail.html.TextArea", listed_by_default=False) @property def class_name(self): return self.custom_class_name or ("woost_style_%d" % self.id)
def schema(self): return schema.Schema( "ShopOrderCostFilter", members=[ schema.String( "operator", required=True, default="eq", enumeration=self.operators, text_search=False, translate_value=lambda value, language=None, **kwargs: "" if not value else translations( "cocktail.html.UserFilterEntry operator " + value, language, **kwargs)), schema.Boolean("include_shipping", default=False), schema.Boolean("include_taxes", default=False), schema.Boolean("include_discounts", default=False), schema.Decimal("value", required=True) ])
def _load(self): from woost.controllers.notifications import notify_user from woost.controllers.backoffice.basebackofficecontroller import \ BaseBackOfficeController from woost.controllers.backoffice.itemcontroller import \ ItemController from woost.extensions.mailer import ( sendemailaction, createmailingaction, strings ) from woost.extensions.mailer.mailing import Mailing, \ RunningMailingError from woost.extensions.mailer.sendemailcontroller import \ SendEmailController ItemController.send_email = SendEmailController Template.add_member( schema.Boolean( "per_user_customizable", default = False, listed_by_default = False ) ) Template.members_order.append("per_user_customizable") User.add_member( schema.Collection( "mailingLists", items = "woost.extensions.mailer.mailinglist.MailingList", bidirectional = True, listed_by_default = False ) ) @when(BaseBackOfficeController.exception_raised) def handle_exception_raised(event): if isinstance( event.exception, RunningMailingError ): notify_user(translations(event.exception), "error") raise cherrypy.HTTPRedirect(event.source.contextual_uri()) # Disable interactive features from rendered pages when rendering # static content from woost.controllers.cmscontroller import CMSController @when(CMSController.producing_output) def disable_user_controls(event): if context.get("sending_email", False): event.output["show_user_controls"] = False
def form_schema(self): form_schema = EditNode.form_schema(self) password_member = form_schema.get_member("password") if password_member: if self.item.encryption_method: order = form_schema.members_order = list( form_schema.members_order) pos = order.index("password") password_conf_member = schema.String( name="password_confirmation", edit_control="cocktail.html.PasswordBox", visible_in_detail_view=False, required=password_member.required) form_schema.add_member(password_conf_member) order.insert(pos + 1, "password_confirmation") if self.item.is_inserted: change_password_member = schema.Boolean( name="change_password", required=True, default=False, visible_in_detail_view=False) form_schema.add_member(change_password_member) order.insert(pos, "change_password") password_member.exclusive = change_password_member password_conf_member.exclusive = change_password_member @form_schema.add_validation def validate_password_confirmation(form_schema, value, ctx): password = ctx.get_value("password") password_confirmation = ctx.get_value( "password_confirmation") if password and password_confirmation \ and password != password_confirmation: yield PasswordConfirmationError( form_schema, value, ctx) # No encryption: edit passwords in plain sight else: password_member.edit_control = "cocktail.html.TextBox" return form_schema
class Attribute(Item): members_order = [ "title", "enabled", "content_types", "scope", "attribute_name", "code" ] title = schema.String( required = True, translated = True, unique = True, indexed = True, descriptive = True ) enabled = schema.Boolean( required = True, default = True, indexed = True ) content_types = schema.Collection( items = schema.Reference(class_family = Item), default = [Publishable], ui_form_control = "cocktail.ui.SplitSelector", min = 1 ) scope = schema.String( required = True, enumeration = ["any", "page", "ref"], default = "any", ui_form_control = "cocktail.ui.RadioSelector", indexed = True ) attribute_name = schema.String( required = True, unique = True, indexed = True ) code = schema.CodeBlock( language = "python", required = True )
def _load(self): from woost.models import User from woost.extensions.signup import ( signuppage, signupcontroller, strings ) # Extend User model if not hasattr(User, "confirmed_email"): User.add_member( schema.Boolean( "confirmed_email", default = False, Required = True ) ) self.install()
def form_schema(self): return schema.Schema( "FacebookAlbumsForm", members=[ schema.String("album_title", required=True), schema.String("album_description", edit_control="cocktail.html.TextArea"), schema.Collection( "subset", items=schema.Reference( type=File, relation_constraints=[ File.resource_type.equal("image") ], required=True, enumeration=lambda ctx: self.selection), min=1, default=schema.DynamicDefault(lambda: self.selection)), schema.Collection( "photo_languages", min=1, items=schema.String(required=True, enumeration=lambda ctx: Configuration. instance.languages, translate_value=lambda value, language= None, **kwargs: "" if not value else translations( value, language, **kwargs)), default=schema.DynamicDefault( lambda: Configuration.instance.languages)), schema.Boolean("generate_story", required=True, default=True), schema.Collection( "publication_targets", items=schema.Reference(type=FacebookPublicationTarget, required=True, enumeration=lambda ctx: self. allowed_publication_targets), min=1, default=schema.DynamicDefault( lambda: self.allowed_publication_targets)) ])
def _load(self): # Import the extension's models from woost.extensions.recaptcha import (strings, schemarecaptchas) # Append additional members to the extension ReCaptchaExtension.members_order = [ "public_key", "private_key", "theme", "custom_theme_widget", "custom_template", "ssl" ] ReCaptchaExtension.add_member( schema.String("public_key", required=True, text_search=False)) ReCaptchaExtension.add_member( schema.String("private_key", required=True, text_search=False)) ReCaptchaExtension.add_member( schema.String("theme", required=True, enumeration=("red", "white", "blackglass", "clean", "custom"), default="red", text_search=False)) ReCaptchaExtension.add_member( schema.String("custom_theme_widget", exclusive=ReCaptchaExtension.theme.equal("custom"), member_group="custom_group", text_search=False)) ReCaptchaExtension.add_member( schema.String( "custom_template", exclusive=ReCaptchaExtension.theme.equal("custom"), member_group="custom_group", default="woost.extensions.recaptcha.RecaptchaCustomView", text_search=False)) ReCaptchaExtension.add_member(schema.Boolean("ssl", default=False))
def requires_agreement(form, name = "terms", document = None): if document is None: document = "%s.%s" % (app.package, name) if isinstance(document, basestring): document = Publishable.require_instance(qname = document) if document is None: raise ValueError( "Must specify a document detailing the end user agreement" ) member = schema.Boolean( name = name, required = True, __translate__ = lambda language, **kwargs: schema.Boolean.__translate__(member, language, **kwargs) or translations( "woost.controllers.formagreement.%s" % member.name, member = member ) or translations("woost.controllers.formagreement", member = member), member_group = "form_agreement" ) member.agreement_document = document member.add_validation(_validate_consent) form.schema.add_member(member) if form.schema.groups_order: if "form_agreement" not in form.schema.groups_order: if not isinstance(form.schema.groups_order, list): form.schema.groups_order = list(form.schema.groups_order) form.schema.groups_order.append("form_agreement") form.adapter.exclude(name) return member
class FreeUnitsDiscount(Discount): instantiable = True members_order = ["paid_units", "free_units", "repeated"] members_order = [ "paid_units", "free_units", "repeated" ] paid_units = schema.Integer( required = True, min = 0 ) free_units = schema.Integer( required = True, min = 1 ) repeated = schema.Boolean( required = True, default = True ) def apply(self, item, costs): paid = self.paid_units free = self.free_units quantity = costs["paid_quantity"] if self.repeated: quantity -= (quantity / (paid + free)) * free elif quantity > paid: quantity = max(paid, quantity - free) costs["paid_quantity"] = quantity
class UserForm(Document): groups_order = list(Document.groups_order) groups_order.insert(groups_order.index("content") + 1, "form") members_order = [ "form_model", "excluded_members", "should_save_instances", "redirection", "email_notifications" ] default_controller = schema.DynamicDefault(lambda: Controller.get_instance( qname="woost.extensions.usermodels.user_form_controller")) default_template = schema.DynamicDefault(lambda: Template.get_instance( qname="woost.extensions.usermodels.user_form_template")) form_model = schema.Reference(required=True, class_family="woost.models.Item", member_group="form") excluded_members = schema.Collection(items=schema.String(), edit_control="cocktail.html.TextArea", member_group="form") should_save_instances = schema.Boolean(required=True, default=True, member_group="form") redirection = schema.Reference(type=Publishable, related_end=schema.Collection(), member_group="form") email_notifications = schema.Collection( items=schema.Reference(type=EmailTemplate), related_end=schema.Collection(), member_group="form")
class NewsListing(Block): max_page_size = 50 instantiable = True type_group = "blocks.listings" groups_order = list(Block.groups_order) groups_order.insert(groups_order.index("content") + 1, "listing") members_order = ["element_type", "paginated", "page_size", "view_class"] element_type = ElementType(member_group="content") paginated = schema.Boolean(required=True, default=False, member_group="listing") page_size = schema.Integer(min=1, required=paginated, member_group="listing") view_class = schema.String(required=True, shadows_attribute=True, enumeration=[ "woost.views.CompactNewsListing", "woost.views.TextOnlyNewsListing", "woost.views.TextAndImageNewsListing" ], default="woost.views.TextOnlyNewsListing", member_group="listing") def init_view(self, view): Block.init_view(self, view) view.tag = self.element_type view.name_prefix = self.name_prefix view.name_suffix = self.name_suffix view.depends_on(News) if self.paginated: view.pagination = self.pagination else: view.news = self.select_news() def select_news(self): news = News.select_accessible(order="-news_date") if not self.paginated and self.page_size: news.range = (0, self.page_size) return news @request_property def pagination(self): return get_parameter(self.pagination_member, errors="set_default", prefix=self.name_prefix, suffix=self.name_suffix) @request_property def pagination_member(self): return Pagination.copy( **{ "page_size.default": self.page_size, "page_size.max": self.max_page_size, "items": self.select_news() })
VideoPlayerSettings.members_order = VideoPlayerSettings.members_order + [ "vimeo_loop", "vimeo_allow_fullscreen", "vimeo_title", "vimeo_byline", "vimeo_portrait", "vimeo_color" ] VideoPlayerSettings.add_member( schema.Boolean( "vimeo_loop", required = True, default = False, listed_by_default = False, member_group = "vimeo" ) ) VideoPlayerSettings.add_member( schema.Boolean( "vimeo_allow_fullscreen", default = True, listed_by_default = False, member_group = "vimeo" ) ) VideoPlayerSettings.add_member(
.. moduleauthor:: Jordi Fernández <*****@*****.**> """ from cocktail import schema from woost.models import VideoPlayerSettings from woost.extensions.youtube.youtubevideo import YouTubeVideo VideoPlayerSettings.members_order = VideoPlayerSettings.members_order + [ "youtube_allow_fullscreen", "youtube_show_info", "youtube_show_related_videos" ] VideoPlayerSettings.add_member( schema.Boolean("youtube_allow_fullscreen", required=True, default=True, listed_by_default=False, member_group="youtube")) VideoPlayerSettings.add_member( schema.Boolean("youtube_show_info", required=True, default=False, listed_by_default=False, member_group="youtube")) VideoPlayerSettings.add_member( schema.Boolean("youtube_show_related_videos", required=True, default=False, listed_by_default=False,
translations.load_bundle("woost.extensions.opengraph.publishable") File.default_x_opengraph_enabled = False File.default_x_opengraph_type = None Publishable.members_order += ["x_opengraph_enabled", "x_opengraph_type"] class GroupByOpenGraphCategory(GroupByMember): member = OpenGraphType.category Publishable.add_member( schema.Boolean("x_opengraph_enabled", required=True, default=True, listed_by_default=False, member_group="meta.x_opengraph")) Publishable.add_member( schema.Reference("x_opengraph_type", type=OpenGraphType, required=Publishable["x_opengraph_enabled"], related_end=schema.Collection(block_delete=True), default=schema.DynamicDefault( lambda: OpenGraphType.get_instance(code="article")), indexed=True, listed_by_default=False, member_group="meta.x_opengraph"))
#-*- coding: utf-8 -*- """ @author: Martà Congost @contact: [email protected] @organization: Whads/Accent SL @since: February 2010 """ from decimal import Decimal from cocktail.translations import translations from cocktail import schema from woost.models import Publishable, URI Publishable.add_member(schema.Boolean("sitemap_indexable", required=True, default=True, indexed=True, member_group="sitemap", listed_by_default=False), append=True) URI.default_sitemap_indexable = False Publishable.add_member(schema.String( "sitemap_change_frequency", enumeration=[ "always", "hourly", "daily", "weekly", "monthly", "yearly", "never" ], translate_value=lambda value, language=None, **kwargs: "" if not value else translations( "woost.extensions.sitemap.change_frequency " + value, language, ** kwargs),
def client_side_scripting(self): return get_parameter(schema.Boolean("client_side_scripting"))
def include_neutral_language(self): return get_parameter(schema.Boolean("include_neutral_language", required=True, default=True), implicit_booleans=False, errors="raise")
def include_descendants(self): return get_parameter(schema.Boolean("include_descendants", required=True, default=False), implicit_booleans=False, errors="raise")
def pending_only(self): return get_parameter(schema.Boolean("pending_only", required=True, default=False), implicit_booleans=False, errors="raise")
class TweetButton(Block): instantiable = True type_group = "blocks.social" view_class = "woost.views.TweetButton" groups_order = list(Block.groups_order) pos = groups_order.index("content") groups_order = ( groups_order[:pos + 1] + ["tweet", "appearence"] + groups_order[pos + 1:] ) del pos members_order = [ "tw_target", "tw_via", "tw_related", "tw_hashtags", "tw_text", "tw_dnt", "tw_size", "tw_count" ] tw_target = schema.Reference( type = Publishable, related_end = schema.Collection(), member_group = "tweet" ) tw_via = schema.String( member_group = "tweet" ) tw_related = schema.String( member_group = "tweet" ) tw_hashtags = schema.String( member_group = "tweet" ) tw_text = schema.String( translated = True, edit_control = "cocktail.html.TextArea", member_group = "tweet" ) tw_dnt = schema.Boolean( required = True, default = False, member_group = "tweet" ) tw_size = schema.String( required = True, default = "medium", enumeration = ["medium", "big"], edit_control = "cocktail.html.RadioSelector", member_group = "appearence" ) tw_count = schema.String( required = True, default = "horizontal", enumeration = ["none", "horizontal", "vertical"], edit_control = "cocktail.html.RadioSelector", member_group = "appearence" ) def init_view(self, view): Block.init_view(self, view) view.url = self.tw_target and self.tw_target.get_uri(host = ".") view.via = self.tw_via view.related = self.tw_related view.hashtags = self.tw_hashtags view.dnt = self.tw_dnt view.text = self.tw_text view.size = self.tw_size view.count = self.tw_count