def _show_communities_view_helper(context, request, prefix='', **kw ): # Grab the data for the two listings, main communities and portlet communities_path = resource_path(context) query = dict( sort_index='title', interfaces=[ICommunity], path={'query': communities_path, 'depth': 1}, allowed={'query': effective_principals(request), 'operator': 'or'}, **kw ) qualifiers = [] titlestartswith = request.params.get('titlestartswith') if titlestartswith: query['titlestartswith'] = (titlestartswith, titlestartswith) qualifiers.append( _(u"Communities that begin with '${titlestartswith}'", mapping={'titlestartswith': titlestartswith})) body = request.params.get('body') if body: query['texts'] = body qualifiers.append('Search for "%s"' % body) error = None try: batch_info = get_catalog_batch_grid(context, request, **query) except ParseError, e: batch_info = {'entries': [], 'batching_required': False} error = _(u'Error: ${message}', mapping={'message': e})
def show_community_view(context, request): assert ICommunity.providedBy(context), str(type(context)) user = authenticated_userid(request) page_title = _(u'View Community ${title}', mapping={'title': context.title}) api = TemplateAPI(context, request, page_title) # provide client data for rendering current tags in the tagbox tagquery = getMultiAdapter((context, request), ITagQuery) client_json_data = {'tagbox': {'docid': tagquery.docid, 'records': tagquery.tagswithcounts, }, } # Filter the actions based on permission actions = [] if has_permission(MODERATE, context, request): actions.append((_(u'Edit'), 'edit.html')) # If user has permission to see this view then has permission to join. if not(user in context.member_names or user in context.moderator_names): actions.append((_(u'Join'), 'join.html')) if has_permission(DELETE_COMMUNITY, context, request): actions.append((_(u'Delete'), 'delete.html')) if has_permission(ADMINISTER, context, request): actions.append((_(u'Advanced'), 'advanced.html')) recent_items = [] recent_items_batch = get_recent_items_batch(context, request) for item in recent_items_batch["entries"]: adapted = getMultiAdapter((item, request), IGridEntryInfo) recent_items.append(adapted) feed_url = resource_url(context, request, "atom.xml") return {'api': api, 'actions': actions, 'recent_items': recent_items, 'batch_info': recent_items_batch, 'head_data': convert_to_script(client_json_data), 'feed_url': feed_url, }
def show_active_communities_view(context, request): _set_cookie_via_request(request, 'active') six_months_ago = _today() - datetime.timedelta(days=180) content_modified = (coarse_datetime_repr(six_months_ago), None) return _show_communities_view_helper(context, request, prefix=_(u'Active '), content_modified=content_modified, )
def jquery_clear_preferred_view(context, request): request.response.cache_expires = 0 communities_folder = find_communities(context) set_preferred_communities(communities_folder, request, None) updated_communities = get_my_communities(communities_folder, request) return {'api': TemplateAPI(context, request), 'my_communities': updated_communities, 'preferred': None, 'show_all': False, 'profile': None, 'status_message': _(u'Cleared preferred communities.')}
def jquery_set_preferred_view(context, request): request.response.cache_expires = 0 communities_folder = find_communities(context) communities = request.params.getall('preferred[]') set_preferred_communities(communities_folder, request, communities) updated_communities = get_my_communities(communities_folder, request) return {'api': TemplateAPI(context, request), 'my_communities': updated_communities, 'preferred': communities, 'show_all': False, 'profile': None, 'status_message': _(u'Set preferred communities.')}
def form_fields(self): fields = super(AddCommunityFormController, self).form_fields() title_field = schemaish.String( title=_(u"Title"), validator=validator.All( validator.Length(max=100), validator.Required(self.error_messages), karlvalidators.FolderNameAvailable(self.context), ) ) fields.pop(0) fields.insert(0, ('title', title_field)) return self.translate_fields(fields)
mgr = ILetterManager(context) letter_info = mgr.get_info(request) view_cookie = request.cookies.get(_VIEW_COOKIE) classes = [] for name, title, description, urlname in _VIEWS: classes.append({'name': name, 'title': title, 'description': description, 'href': urlname, 'selected': name == view_cookie, }) actions = [] if has_permission('create', context, request): actions.append((_(u'Add Community'), 'add_community.html')) system_name = get_setting(context, 'system_name', 'KARL') page_title = _(u'Communities ${prefix}${system_name}', mapping={'prefix': prefix, 'system_name': system_name}) my_communities = get_my_communities(context, request) preferred_communities = get_preferred_communities(context, request) return {'communities': communities, 'batch_info': batch_info, 'letters': letter_info, 'community_tabs': classes,
from pyramid.i18n import get_localizer from localetest import messageFactory as _ _FORM_ERROR_MESSAGES = {"required": _(u'Required field')} class ValidationMessages(dict): def __init__(self, localizer, l): super(ValidationMessages, self).__init__() self.localizer = localizer self.update(l) for k, v in self.items(): self[k] = self.localizer.translate(v) class FormControllerMixin(object): @property def localizer(self): return get_localizer(self.request) def translate_fields(self, fields): localizer = self.localizer for item in fields: fld = item[1] title = fld.title if title: fld.title = localizer.translate(title) description = fld.description if description:
def __call__(self): api = TemplateAPI(self.context, self.request, _(u'Add Community')) return {'api': api}