Example #1
0
    def update(self):
        request = self.request
        context = removeAllProxies(self.context)
        query = dict(noSecurityChecks=True)

        if 'form.button.reindex' in request:
            catalog = context.catalog
            catalog.clear()

            for rid, record in context.records.items():
                if record.object is None:
                    context.remove(rid)

            for rid, record in context.records.items():
                catalog.index_doc(rid, record)

            IStatusMessage(request).add(
                _('Activity catalog has been reindexed.'))

        if request.get('searchtype', 'all') != 'all':
            query['type'] = {'any_of': (request['searchtype'],)}

        results = context.search(**query)

        self.batch = Batch(results, size=20, context=context, request=request)

        self.auth = getUtility(IAuthentication)
        self.formatter = getFormatter(self.request, 'fancyDatetime', 'medium')
        self.voc = getUtility(IVocabularyFactory, 'acitivity.record.descriptions')(getSite())
    def listComments(self):
        auth = getUtility(IAuthentication)
        formatter = getFormatter(self.request, 'fancyDatetime', 'medium')

        comments = []
        for comment in self.comments:
            info = {'name': comment.__name__,
                    'title': comment.content.title,
                    'url': absoluteURL(comment.content, self.request),
                    'author': None,
                    'profile': None,
                    'date': comment.date,
                    'fomratteddate': formatter.format(comment.date)}

            try:
                principal = auth.getPrincipal(comment.author)
                profile = IPersonalProfile(principal)
                info['author'] = profile.title

                space = profile.space
                if space is not None:
                    info['profile'] = '%s/'%absoluteURL(space, self.request)

            except PrincipalLookupError:
                pass

            comments.append(info)

        return comments
Example #3
0
    def update(self, **kw):
        request = self.request
        message = removeSecurityProxy(self.context)

        if kw:
            for attr, value in kw.items():
                setattr(self, attr, value)
        else:
            self.formatter = getFormatter(request, 'fancyDatetime', 'medium')
            self.userinfos = {}

        ownership = IOwnership(message)
        self.owner = owner = ownership.owner
        ownerId = ownership.ownerId

        if message.signature:
            sigs = ISignatures(owner, None)
            self.signature = getattr(sigs, 'signature%s'%message.signature, '')

        self.text = message.text.cooked
        self.created = self.formatter.format(ICMFDublinCore(message).created)

        userinfo = self.userinfos.get(ownership.ownerId)
        if userinfo is None:
            userinfo = getMultiAdapter(
                (owner, request), IPrincipalInformation)
            userinfo.update()
            userinfo = userinfo.render()
            self.userinfos[ownership.ownerId] = userinfo

        self.userinfo = userinfo
Example #4
0
    def update(self):
        topic = self.context
        request = self.request
        formatter = getFormatter(request, 'fancyDatetime', 'medium')

        name = topic.__name__
        owner = IOwnership(topic).owner
        profile = IPersonalProfile(owner)
        space = getattr(profile, 'space', None)

        self.name = name
        self.replies = len(topic)-1
        self.owner = getattr(profile, 'title', '')
        self.avatar = profile is not None and profile.avatarUrl(request) or '#',
        self.personal = '%s/'%(space and absoluteURL(space, request) or '',)

        message = topic.lastMessage

        if message is not None:
            owner = IOwnership(message).owner
            profile = IPersonalProfile(owner, None)
            space = getattr(profile, 'space', None)

            self.lastmessage = {
                'date': formatter.format(IDCTimes(message).modified),
                'owner': getattr(profile, 'title', ''),
                'personal': '%s/'%(space and absoluteURL(space,request) or '',),
                'avatar': profile is not None and profile.avatarUrl(request) or '#',
                'url': '%s/%s/'%(name, message.__name__)}
    def update(self):
        dc = ICMFDublinCore(self.context, None)

        if dc is not None and dc.modified:
            formatter = getFormatter(self.request, 'fancyDatetime', 'medium')
            self.modified = formatter.format(dc.modified)
        else:
            self.modified = None
Example #6
0
    def update(self):
        super(ContainerListing, self).update()

        request = self.request

        url = getMultiAdapter((self.context, self), IContainerURL)
        self.environ['url'] = url.absoluteURL()

        self.environ['formatter'] = getFormatter(
            request, 'fancyDatetime', 'short')
Example #7
0
    def listContents(self):
        context = self.context
        request = self.request
        catalog = getUtility(ICatalog)
        ids = getUtility(IIntIds)
        formatter = getFormatter(request, 'humanDatetime', 'medium')

        query = {'traversablePath': {'any_of':(context,)},
                 'sort_order': 'reverse',
                 'sort_on': 'modified',
                 'isDraft': {'any_of': (False,)}}

        if '__all__' in self.types:
            query['typeType']={'any_of': ('Portal type',)}
        else:
            query['type']={'any_of': self.types}

        try:
            local_context = self.manager.view.maincontext
        except AttributeError:
            local_context = context

        if self.spaceMode == 2:
            query['contentSpace'] = {'any_of': [ids.queryId(removeSecurityProxy(getSpace(local_context)))] }
            del query['traversablePath']
        elif self.spaceMode == 3:
            query['traversablePath'] = {'any_of':(getSpace(local_context),)}

        query.update(self.extraParameters())

        docs = []
        for document in catalog.searchResults(**query)[:self.number]:
            view = queryMultiAdapter((document, request), IContentViewView)
            if view is not None:
                url = '%s/%s'%(absoluteURL(document, request), view.name)
            else:
                url = '%s/'%absoluteURL(document, request)

            space = getSpace(document, context)
            item = IItem(document, None)

            docs.append({'url': url,
                         'title': getattr(item, 'title', document.__name__),
                         'description': getattr(item, 'description', u''),
                         'date': formatter.format(IDCTimes(document).modified),
                         'icon': queryMultiAdapter(
                                   (document, request), name='zmi_icon'),
                         'space': space.title,
                         'spacedescription': space.description,
                         'spaceurl': '%s/'%absoluteURL(space, request),
                         'content': document,
                         })
        return docs
Example #8
0
    def update(self):
        super(MessageTemplate, self).update()

        context = self.context
        request = self.request

        formatter = getFormatter(request, 'fancyDatetime', 'medium')

        self.date = formatter.format(context.__date__)
        self.service = context.__parent__

        storage = self.service.__parent__
        self.url = '%s/%s/'%(absoluteURL(storage, request), context.__name__)
Example #9
0
    def listMessages(self):
        request = self.request
        messages = self.messages

        data = {'signatures': getUtility(IPreferenceGroup, 'forum.sigs'),
                'formatter': getFormatter(request, 'fancyDatetime', 'medium'),
                'userinfos': {}}

        for msgId in self.batch:
            message = messages[msgId]
            view = getMultiAdapter((message, request), IMessageView)
            view.update(**data)
            yield view.template()
Example #10
0
    def update(self):
        super(SendMessageForm, self).update()

        context = self.context
        request = self.request

        self.manager = queryUtility(IPersonalSpaceManager)
        if self.manager is not None:
            self.managerURL = absoluteURL(self.manager, self.request)

        results = list(self.context.keys())
        self.batch = Batch(results, size=30, context=context, request=request)
        self.auth = getUtility(IAuthentication)
        self.formatter = getFormatter(request, 'fancyDatetime', 'medium')
    def render(self):

        if not IUnauthenticatedPrincipal.providedBy(self.request.principal):

            formatter = getFormatter(self.request, 'dateTime', 'medium')

            result = getUtility(IAcknowledgements).verifyRecord(
                object=self.context, uid=self.request.principal.id)

            if result:
                return msg_success % dict(user=self.request.principal.title,
                                          date=formatter.format(result.date))

            return msg_default
    def render(self):

        if not IUnauthenticatedPrincipal.providedBy(self.request.principal):

            formatter = getFormatter(self.request, 'fancyDatetime', 'medium')

            result = getUtility(IAcknowledgements).verifyRecord(
                object=self.context, uid=self.request.principal.id)

            if result:
                return msg_success % dict(
                    user=self.request.principal.title,
                    date=formatter.format(result.date))

            return msg_default
Example #13
0
    def update(self):
        super(TaskModifiedTemplate, self).update()

        task = self.context
        ev = self.context0
        request = self.request

        data = {}
        attributes = dict([(attr.interface, list(attr.attributes)) for attr in ev.descriptions])
        for iface, fields in attributes.items():
            ob = iface(task)
            for fieldId in fields:
                field = iface[fieldId].bind(ob)
                value = field.get(ob)

                if IChoice.providedBy(field):
                    try:
                        value = field.vocabulary.getTerm(value).title
                    except LookupError:
                        pass

                if ICollection.providedBy(field) and IChoice.providedBy(field.value_type):
                    voc = field.value_type.vocabulary
                    value = u", ".join([voc.getTerm(v).title for v in value])

                if IDate.providedBy(field):
                    value = getFormatter(request, "date", "full").format(value)

                if IDatetime.providedBy(field):
                    value = getFormatter(request, "dateTime", "medium").format(value)

                data[field.title] = value

        data = data.items()
        data.sort()
        self.data = data
    def update(self):
        request = self.request
        principal = self.context.principal

        formatter = getFormatter(request, 'dateTime')
        self.date = formatter.format(datetime.now())

        configlet = getUtility(IMailer)
        self.email_from_name = configlet.email_from_name
        self.email_from_address = configlet.email_from_address

        remoteAddr = request.get('REMOTE_ADDR', '')
        forwardedFor = request.get('HTTP_X_FORWARDED_FOR', None)

        self.from_ip = (forwardedFor and '%s/%s' %
                        (remoteAddr, forwardedFor) or remoteAddr)

        self.url = '%s/resetpassword.html/%s/'%(
            absoluteURL(getSite(), request), self.context.passcode)
Example #15
0
    def add(self, uid=None, oid=None):

        if not uid or not oid:
            return dict(error="ERROR: user and object can not be empty")

        date = datetime.utcnow()
        formatter = getFormatter(self.request, 'dateTime', 'medium')
        configlet = getUtility(IAcknowledgements)

        if configlet.verifyRecord(oid=int(oid), uid=uid):
            return dict(
                error="ERROR: You have already acknowledged this document")

        try:
            configlet.add(
                Acknowledgement(principal=uid, oid=int(oid), date=date))
        except:
            return dict(error="ERROR: couldn't add record to catalog")

        return dict(user=self.request.principal.title,
                    date=formatter.format(date))
Example #16
0
    def query(self, default=None):
        forum = self.content
        url = absoluteURL(self.context, self.request)
        siteUrl = absoluteURL(getSite(), self.request)
        formatter = getFormatter(self.request, 'fancyDatetime', 'medium')

        topic = forum.lastTopic
        if topic is not None:
            message = topic.lastMessage
            owner = IOwnership(message).owner
            profile = IPersonalProfile(owner)
            space = profile.space

            return {
                'date': formatter.format(
                    ICMFDublinCore(message).modified),
                'owner': profile.title,
                'profile': '%s/'%(space is not None and absoluteURL(space, self.request) or siteURL),
                'avatar': profile.avatarUrl(self.request),
                'title': topic.title,
                'url': '%s/%s/%s/%s/'%(
                    url, forum.__name__, topic.__name__, message.__name__)}
    def update(self):
        record = self.context
        request = self.request

        content = record.object
        formatter = getFormatter(request, 'humanDatetime', 'medium')

        view = queryMultiAdapter((content, request), IContentViewView)
        try:
            if view is not None:
                url = '%s/%s'%(absoluteURL(content, request), view.name)
            else:
                url = '%s/'%absoluteURL(content, request)
        except:
            url = u''

        self.url = url
        self.title = getattr(content, 'title', content.__name__)
        self.description = getattr(content, 'description', u'')
        self.date = formatter.format(record.date)
        self.content = content

        auth = getUtility(IAuthentication)
        try:
            principal = auth.getPrincipal(record.principal)
        except:
            principal = None

        if principal is not None:
            profile = IPersonalProfile(principal)
            self.avatar = profile.avatarUrl(request)
            self.author = profile.title

            space = profile.space
            if space is not None:
                self.profile = '%s/'%absoluteURL(space, request)
        else:
            self.author = _('Unknown')
Example #18
0
 def query(self, default=None):
     fancyDatetime = getFormatter(self.request, 'fancyDatetime', 'medium')
     return fancyDatetime.format(self.content.date)
Example #19
0
    def update(self):
        super(DateColumn, self).update()

        self.table.environ['fancyDatetime'] = getFormatter(
            self.request, 'fancyDatetime', 'medium')
Example #20
0
 def update(self):
     self.formatter = getFormatter(self.request, 'humanDatetime', 'medium')
Example #21
0
 def update(self):
     self.today = date.today()
     self.fancyDatetime = getFormatter(self.request, 'date', 'short')
Example #22
0
 def update(self):
     self.formatter = getFormatter(self.request, 'date', 'short')
Example #23
0
    def listMilestones(self):
        request = self.request
        context = self.context

        today = date.today()
        ids = getUtility(IIntIds)
        catalog = getUtility(ICatalog)
        formatter = getFormatter(request, 'fancyDatetime', 'medium')
        dateFormatter = getFormatter(request, 'date', 'full')

        milestones = []
        active_milestones = []

        for ms in context.values():
            dc = IDCTimes(ms)

            principal = IOwnership(ms).owner
            profile = IPersonalProfile(principal, None)

            space = getattr(profile, 'space', None)
            if space is not None:
                space = u'%s/'%absoluteURL(space, request)

            tasks = getMultiAdapter(
                (ms, request, self),
                IContentProvider, 'project.tasks.browseactive')
            tasks.update()

            info = {
                'name': ms.__name__,
                'title': ms.title,
                'creator': getattr(profile, 'title', None),
                'space': space,
                'created': formatter.format(dc.created),
                'date': dateFormatter.format(ms.date),
                'tasks': None,
                'completed': None,
                'overdue': None,
                'percent': 100,
                'milestone': ms
                }

            if context.showactive:
                info['tasks'] = tasks

            if context.showcompleted:
                info['completedtasks'] = getMultiAdapter(
                    (ms, request, self),
                    IContentProvider, 'project.tasks.browsecompleted')
                info['completedtasks'].update()

            # date
            if ms.state == 1 and ms.date < today:
                info['overdue'] = today - ms.date

            # tasks statistics
            completed = len(catalog.searchResults(
                type={'any_of': ('project.task',),},
                projectTaskState = {'any_of': (2,)},
                projectTaskMilestone = {
                        'any_of': (ids.getId((removeAllProxies(ms))),)},
                searchContext = context.__parent__.__parent__,
                noPublishing=True, noSecurityChecks=True))

            total = len(tasks.dataset) + completed
            info['total'] = total
            info['completed'] = completed
            if total > 0:
                info['percent'] = int(completed/(total/100.0))
            
            if info['percent'] < 100:    
                active_milestones.append((ms.date, ms.title, info))
            else:
                milestones.append((ms.date, ms.title, info))
        milestones.sort()
        active_milestones.sort()
        return [info for _d, _t, info in active_milestones], [info for _d, _t, info in milestones]
Example #24
0
    def update(self):
        super(TimesColumn, self).update()

        self.table.environ['humanDatetime'] = getFormatter(
            self.request, 'humanDatetime', 'medium')
    def __call__(self):
        request = self.request
        callback = request.get('callback', 'stcCallback1001') + '(%s)'

        try:
            start = int(request.form.get('start', 0))
            limit = int(request.form.get('limit', 10))
            query = request.form.get('query', u'')
        except:
            return callback%encoder.encode({'result': [], 'totalCount': 0})

        catalog = queryUtility(ICatalog)
        if catalog is not None:
            fti = catalog.getFTIndex()
            if fti is None:
                return callback%encoder.encode({'result': [], 'totalCount': 0})

            result = catalog.searchResults(
                **{'searchContext': (getSite(),),
                   str(fti):  {'any_of': (query,)}})
            formatter = getFormatter(request, 'fancyDatetime', 'medium')

            data = []
            for idx in range(start, start+limit):
                item = result.get(idx)
                if item is None:
                    break

                info = {'id': str(idx),
                        'url': '%s/'%absoluteURL(item, request)}

                it = IItem(item, None)
                if it is not None:
                    info['title'] = it.title
                    info['description'] = it.description
                else:
                    info['title'] = unicode(getattr(item, 'title', item.__name__))
                    info['description'] = u''

                if not info['description']:
                    info['description'] = _('empty description')

                icon = queryMultiAdapter((item, request), name='zmi_icon')
                if icon is not None:
                    info['icon'] = icon()
                else:
                    info['icon'] = ''

                dc = ICMFDublinCore(item)
                info['modified'] = formatter.format(dc.modified)

                owner = IOwnership(item).owner
                try:
                    info['owner'] = owner.title
                except:
                    info['owner'] = owner

                data.append(info)

            return callback%encoder.encode({'result': data, 'totalCount': len(result)})

        return callback%encoder.encode({'result': [], 'totalCount':0})