示例#1
0
    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)
示例#2
0
    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)
示例#3
0
    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)
示例#4
0
def contentHandler(ob, ev):
    ct = IContentType(ob, None)
    if IPortalType.providedBy(ct) and not IDraftedContent.providedBy(ob):
        try:
            ContentTag.update(ob)
        except TypeError:
            pass
示例#5
0
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})
示例#6
0
 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]
示例#7
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)
示例#8
0
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)
示例#9
0
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')
示例#10
0
    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()
示例#11
0
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})
示例#12
0
    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
示例#13
0
 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')
示例#14
0
 def update(self):
     super(BlogPostView, self).update()
     self.draft = IDraftedContent.providedBy(self.context)
示例#15
0
    def isAvailable(self):
        if IDraftedContent.providedBy(self.context):
            return False

        return bool(self.categories)
示例#16
0
def blogPostHandler(post, event):
    if not IDraftedContent.providedBy(post):
        BloggerPosts.update(post)
示例#17
0
 def fields(self):
     res = super(ContentBasicFields, self).fields
     if IDraftedContent.providedBy(self.context):
         res = res.omit('fullNumber')
     return res
示例#18
0
    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)
示例#19
0
 def getContent(self):
     if IDraftedContent.providedBy(self.context):
         return self.parentForm.wizard.draft
示例#20
0
 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)
示例#21
0
 def photos(self):
     context = self.context
     if not IDraftedContent.providedBy(context):
         photos = list(context.__parent__.listPhotos())
         return PhotoBatch(photos, start=photos.index(context.__name__))
示例#22
0
    def update(self):
        self.drafted = IDraftedContent.providedBy(self.context)
        self.extension = IContentDiscussion(self.context, None)

        super(ContentDiscussonEdit, self).update()
示例#23
0
def modifiedHandler(ob, ev):
    if not IDraftedContent.providedBy(ob):
        ModifiedTag.update(ob)
示例#24
0
 def isAvailable(self):
     return IDraftedContent.providedBy(self.context)
示例#25
0
    def isAvailable(self):
        if IDraftedContent.providedBy(self.getContent()):
            return False

        return super(MailInAwareForm, self).isAvailable()
示例#26
0
    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
示例#27
0
def mediaItemHandler(ob, ev):
    if not IDraftedContent.providedBy(ob):
        try:
            MediaItemsTag.update(ob)
        except TypeError:
            pass
示例#28
0
def fileModifiedHandler(object, event):
    """ generate preview for File
    """
    if not IDraftedContent.providedBy(object):
        object = removeAllProxies(object)
        object.generatePreview()
示例#29
0
def draftRemovedHandler(draft, obevent):
    if IDraftedContent.providedBy(draft.content):
        event.notify(ObjectRemovedEvent(draft.content))
示例#30
0
 def fields(self):
     if IDraftedContent.providedBy(self.context):
         return Fields(IUserManualPageDraft)
     return Fields()