def fullNumber(self, value): if IDraftedContent.providedBy(self): location = self.__parent__.getLocation() parents = filter(IUserManual.providedBy, [location] + getParents(location)) else: parents = filter(IUserManual.providedBy, getParents(self)) manual = parents[-1] numbers = map(int, value.split('.')) ct = getUtility(IContentType, name='content.usermanualpage') del self.__parent__[self.__name__] for number in numbers[0:-1]: try: manual = IOrder(manual).getByPosition(number) except KeyError: m = ct.create(_(u'Autocreated page'), _(u'Autocreated page description')) m.number = number ct.__bind__(manual).add(m) manual = m self.number = numbers[-1] manual[INameChooser(manual).chooseName(self.__name__, self)] = self IOrder(self.__parent__).rebuild() if IUserManualPage.providedBy(self.__parent__): return '%s.%s'%(self.__parent__.fullNumber, self.number) return str(self.number)
def _index_doc(self, docid, texts): for index in self.getIndexes(): if IDraftedContent.providedBy(texts) and \ index.__name__ in ('searchableText',): continue index.index_doc(docid, texts)
def __init__(self, context, request, view, manager=None): maincontext = context site = getSite() if not IRootSpace.providedBy(site) or \ IContentSpaceLayout.providedBy(site) and not site.showTabs: self.available = False super(PortalTabs, self).__init__(context, request, view, manager) return wsname = u'' ws = None if ILayout.providedBy(view.view): context = view.view.mainview elif ILayout.providedBy(view): context = view.mainview while not IRootSpace.providedBy(context) \ or IDraftedContent.providedBy(context): if IWorkspace.providedBy(context): ws = context wsname = context.__name__ context = context.__parent__ if context is None: break self.wsname = wsname self.workspace = ws super(PortalTabs, self).__init__(site, request, view, manager)
def contentHandler(ob, ev): ct = IContentType(ob, None) if IPortalType.providedBy(ct) and not IDraftedContent.providedBy(ob): try: ContentTag.update(ob) except TypeError: pass
def CalendarEventModified(object, ev): """ sends emails when the event is modified """ if IDraftedContent.providedBy(object): return principals = () owner = IOwnership(object).owner.id attendees = object.attendees or None notification = component.getAdapter(object.__parent__, IEventNotification, 'event') if attendees: if owner not in attendees: principals += (owner, ) principals += attendees if not attendees: principals += (owner, ) #check subscribe for principal in principals: try: if not notification.isSubscribed(principal): notification.subscribe(principal) except SubscriptionException: pass # send notifications sendNotification('event', object, ev, principal={'any_of': principals})
def next(self): if IDraftedContent.providedBy(self): return None ob = self.__parent__.get(IOrder(self.__parent__).nextKey(self.__name__)) if ob is not self: return ob elif len(self): return IOrder(self).values()[0]
def __get__(self, inst, klass): if IDraftedContent.providedBy(inst) or \ inst._v_currentRevision == -1: return getattr(inst.workingRevision, self.name) if inst._v_currentRevision is not None: revision = inst._revisions[inst._v_currentRevision] return getattr(revision, self.name) return getattr(inst.activeRevision, self.name)
def messageAdded(message, ev): if IDraftedContent.providedBy(message.__parent__): return sendNotification('forum', message.__parent__, message) notification = component.getAdapter(message.__parent__, ITopicNotification, 'forum.topic') try: if not notification.isSubscribed(): notification.subscribe() except SubscriptionException: pass sendNotification('forum.topic', message.__parent__, message)
def getContentPermissions(context): if IDraftedContent.providedBy(context): return getUtility(IPermissionsMap, 'content.permissions.opened') ct = IContentType(context, None) if ct is not None and IDraftedContentType.providedBy(ct): interaction = queryInteraction() if interaction is not None: dct = getUtility(IDraftContentType, ct.name) if dct.retractable and not \ interaction.checkPermission(dct.publish,context.__parent__): return getUtility(IPermissionsMap, 'content.permissions.closed') return getUtility(IPermissionsMap, 'content.permissions.opened')
def assignees(self): milestone = self.milestone if IDraftedContent.providedBy(milestone): milestones = milestone.__parent__.getLocation() if milestones is None: return [] project = milestones.__parent__ else: project = milestone.__parent__.__parent__ group = IMembersAware(project, None) if group is None: return [] return removeAllProxies(group.members).keys()
def CalendarEventRemoved(object, ev): """ sends emails when the event is removed """ if IDraftedContent.providedBy(object): return principals = () owner = IOwnership(object).owner.id attendees = object.attendees or None notification = component.getAdapter(object.__parent__, IEventNotification, 'event') if attendees: if owner not in attendees: principals += (owner, ) principals += attendees if not attendees: principals += (owner, ) # send notifications sendNotification('event', object, ev, principal={'any_of': principals})
def update(self): super(BasePostView, self).update() post = removeAllProxies(self.context) request = self.request owner = IOwnership(post).owner profile = IPersonalProfile(owner, None) space = getattr(profile, 'space', None) profileData = profile.getProfileData() self.post = post self.postUrl = absoluteURL(post, request) self.text = getattr(self.context.text, 'cooked', '') self.biography = profileData.get('about', False) self.jobtitle = profileData.get('jobtitle', False) if self.biography: self.biography = re.sub('<[^>]*>', '', self.biography.text) if len(self.biography) >= 240: self.biography = self.biography[:240].rsplit(' ', 1)[0].strip() + '...' # blog if IDraftedContent.providedBy(post): blog = post.__parent__ location = blog.getLocation() if location is not None: blog = location.get('blog') else: blog = None else: blog = post.__parent__ if IBlog.providedBy(blog): self.blog = blog self.blog_title = blog.title self.blog_url = absoluteURL(blog, request) self.tags_list = blog['tags'].listTags(post) # author try: self.author = profile.title self.avatar_url = profile.avatarUrl(request) except AttributeError: self.author = getattr(owner, 'title', '') self.avatar_url = '#' if space is not None: self.profile_url = '%s/profile/' % absoluteURL(space, request) # discussion discussion = IContentDiscussion(post, None) self.comments = discussion is not None and len(discussion) self.discussible = discussion is not None and discussion.status != 3 self.footer_discussion = self.discussible and self.comments_num # categories categories = [] ids = getUtility(IIntIds) for cId in post.category: category = ids.queryObject(cId) if category is not None: categories.append( (category.title, {'name': category.__name__, 'title': category.title})) categories.sort() self.categories = [info for t, info in categories] self.footer = self.categories or \ self.tags_list or self.footer_discussion
def update(self): super(AdvancedPostView, self).update() self.pages = [getattr(p.text, 'cooked', '') for p in self.context.pages] self.draft = IDraftedContent.providedBy(self.context) include('blogger-advanced-post-js')
def update(self): super(BlogPostView, self).update() self.draft = IDraftedContent.providedBy(self.context)
def isAvailable(self): if IDraftedContent.providedBy(self.context): return False return bool(self.categories)
def blogPostHandler(post, event): if not IDraftedContent.providedBy(post): BloggerPosts.update(post)
def fields(self): res = super(ContentBasicFields, self).fields if IDraftedContent.providedBy(self.context): res = res.omit('fullNumber') return res
def __set__(self, inst, value): if IDraftedContent.providedBy(inst) or inst.__parent__ is None: return setattr(inst.workingRevision, self.name, value) raise AttributeError('Field "%s" is read-only.'%self.name)
def getContent(self): if IDraftedContent.providedBy(self.context): return self.parentForm.wizard.draft
def fullNumber(self): if IDraftedContent.providedBy(self): return self.__parent__.fullNumber if IUserManualPage.providedBy(self.__parent__): return '%s.%s'%(self.__parent__.fullNumber, self.number) return str(self.number)
def photos(self): context = self.context if not IDraftedContent.providedBy(context): photos = list(context.__parent__.listPhotos()) return PhotoBatch(photos, start=photos.index(context.__name__))
def update(self): self.drafted = IDraftedContent.providedBy(self.context) self.extension = IContentDiscussion(self.context, None) super(ContentDiscussonEdit, self).update()
def modifiedHandler(ob, ev): if not IDraftedContent.providedBy(ob): ModifiedTag.update(ob)
def isAvailable(self): return IDraftedContent.providedBy(self.context)
def isAvailable(self): if IDraftedContent.providedBy(self.getContent()): return False return super(MailInAwareForm, self).isAvailable()
def update(self): super(ContentPermissions, self).update() context = self.context request = self.request if IDraftedContent.providedBy(context): return # get principals bprincipals, batch = self.getPrincipals() if not bprincipals: return self.batch = batch principals = [] principalIds = [] for principal in bprincipals: name = principal.id.replace('.', '_') principalIds.append(principal.id) principals.append( {'id': principal.id, 'name': name, 'title': IPersonalProfile(principal).title}) self.principals = principals # get permissions categories = [] allpermissions = [] for categoryName, category in getUtilitiesFor(IPermissionCategoryType): permissions = [] for name, perm in getAdapters((context,), category): if perm.isAvailable(): permOb = perm.permission permissions.append((permOb.title, permOb.description, perm)) allpermissions.append(perm) if not permissions: continue permissions.sort() categories.append( (categoryName, category.__doc__, [{'id': perm.permissionId, 'object': perm, 'settings':perm.principals,'title':title,'desc':description} for title, description, perm in permissions])) categories.sort() self.permissions = [ {'name': name, 'desc':desc, 'perms': perms} for name, desc, perms in categories] # process form if 'form.updatePrincipalPermissions' in request: permissions = {} for principal in principals: for perm in request.get('principal-%s'%principal['name'], ()): data = permissions.setdefault(perm, []) data.append(principal['id']) for permission in allpermissions: permission.unsetAll() if permission.permissionId in permissions: permission.allow(permissions[permission.permissionId]) updatePermissions(context, permissions.keys()) IStatusMessage(request).add(_('Permissions have been updated.')) for info in self.permissions: for perm in info['perms']: perm['settings'] = perm['object'].principals
def mediaItemHandler(ob, ev): if not IDraftedContent.providedBy(ob): try: MediaItemsTag.update(ob) except TypeError: pass
def fileModifiedHandler(object, event): """ generate preview for File """ if not IDraftedContent.providedBy(object): object = removeAllProxies(object) object.generatePreview()
def draftRemovedHandler(draft, obevent): if IDraftedContent.providedBy(draft.content): event.notify(ObjectRemovedEvent(draft.content))
def fields(self): if IDraftedContent.providedBy(self.context): return Fields(IUserManualPageDraft) return Fields()