Esempio n. 1
0
 def render(self):
     try:
         return priorityVocabulary.getTerm(self.content.priority).title
     except LookupError:
         return u'---'
Esempio n. 2
0
    def update(self):
        context = self.context
        task = removeAllProxies(context)
        self.name = task.__name__

        # status
        self.status = IWorkflowState(context).getState().title

        # severity
        voc = getUtility(IVocabularyFactory, 'project.task.severity')(task)
        if voc:
            try:
                self.severity = voc.getTerm(context.severity).title
            except LookupError:
                self.severity = u'---'

        # categories
        voc = getUtility(IVocabularyFactory, 'project.task.categories')(task)
        if voc:
            categories = []
            for cat in context.category or ():
                try:
                    categories.append(voc.getTerm(cat).title)
                except LookupError:
                    pass
            if not categories:
                categories.append(u'---')

            self.categories = categories

        # priority
        try:
            self.priority = priorityVocabulary.getTerm(context.priority).title
        except LookupError:
            self.priority = u'---'

        # times
        dc = IDCTimes(context)
        self.created = dc.created
        self.modified = dc.modified

        # milestone
        if context.milestone:
            try:
                milestone = getUtility(IIntIds).queryObject(context.milestone)
                if milestone is not None:
                    self.milestone = milestone.title
                    self.milestoneURL = u'%s/'%absoluteURL(
                        milestone, self.request)
            except:
                pass

        # project
        project = removeAllProxies(context).__parent__.__parent__
        self.project = project.title
        self.projectURL = u'%s/'%absoluteURL(project, self.request)

        # owner
        self.owner = IOwnership(context).owner

        # date
        if self.context.state == 1:
            today = date.today()
            if context.date < today:
                self.overdue = today - context.date

        # assignees
        assignments = []
        for principal in IAssignments(task).getAssignees():
            assignments.append(principal.title)
        assignments.sort()
        self.assignments = assignments

        # attachments
        attachments = []

        for attach in IAttachmentsExtension(task).values():
            ownership = IOwnership(attach)
            profile = IPersonalProfile(ownership.owner, None)

            info = {'id': attach.__name__,
                    'title': attach.title or attach.__name__,
                    'description': attach.description,
                    'size': ISized(attach).sizeForDisplay(),
                    'created': IDCTimes(attach).created,
                    'owner': getattr(profile, 'title', _('Unknown')),
                    'attach': attach,
                    }

            attachments.append((info['created'], info))

        attachments.sort()
        self.attachments = [attach for _c, attach in attachments]
Esempio n. 3
0
    def update(self):
        super(TaskNotification, self).update()

        context = removeAllProxies(self.context)
        request = self.request
        principal = self.request.principal
        ids = getUtility(IIntIds)

        self.name = context.__name__

        mailer = getUtility(IMailer)

        profile = IPersonalProfile(principal, None)
        if profile is not None and profile.email:
            author = profile.title
            self.author = author
            self.addHeader(u"To", formataddr((author, profile.email)))
        else:
            self.author = principal.title or principal.id

        self.addHeader(u"From", formataddr((self.author, mailer.email_from_address)))

        self.addHeader(u"In-Reply-To", u"<*****@*****.**>" % ids.getId(context))

        self.url = "%s/" % absoluteURL(context, request)
        self.title = u"%s %s" % (self.name, context.title)
        self.project = context.__parent__.__parent__

        # project
        self.projectTitle = self.project.title
        self.projectUrl = u"%s/" % absoluteURL(self.project, request)

        # status
        self.status = IWorkflowState(context).getState().title

        # severity
        voc = getUtility(IVocabularyFactory, "project.task.severity")(context)
        if voc:
            try:
                self.severity = voc.getTerm(context.severity).title
            except LookupError:
                self.severity = u"---"

        # categories
        voc = getUtility(IVocabularyFactory, "project.task.categories")(context)
        if voc:
            categories = []
            if context.category:
                for cat in context.category:
                    try:
                        categories.append(voc.getTerm(cat).title)
                    except LookupError:
                        pass
            if not categories:
                categories.append(u"---")

            self.categories = categories

        # priority
        try:
            self.priority = priorityVocabulary.getTerm(context.priority).title
        except LookupError:
            self.priority = u"---"

        # times
        dc = IDCTimes(context)
        self.created = dc.created
        self.modified = dc.modified

        # milestone
        if context.milestone:
            try:
                milestone = getUtility(IIntIds).queryObject(context.milestone)
                if milestone is not None:
                    self.milestone = milestone.title
                    self.milestoneURL = u"%s/" % absoluteURL(milestone, self.request)
            except:
                pass

        # owner
        self.owner = IOwnership(context).owner

        # date
        if self.context.state == 1:
            today = date.today()
            if context.date < today:
                self.overdue = today - context.date

        # assignees
        assignments = []
        for principal in IAssignments(context).getAssignees():
            assignments.append(principal.title)
        assignments.sort()
        self.assignments = assignments
Esempio n. 4
0
    def addCommentHandler(self, action):
        request = self.request
        data, errors = self.extractData()

        if errors:
            IStatusMessage(request).add(self.formErrorsMessage, 'warning')
        else:
            task = self.context

            changes = {}
            if 'severity' in data and task.severity != data['severity']:
                try:
                    value = self.severity.getTerm(task.severity).title
                except:
                    value = u''
                changes['severity'] = [
                    value, self.severity.getTerm(data['severity']).title]
                task.severity = data['severity']

            if 'priority' in data and task.priority != data['priority']:
                try:
                    value = priorityVocabulary.getTerm(task.priority).title
                except:
                    value = u''
                changes['priority'] = [
                    value, priorityVocabulary.getTerm(data['priority']).title]
                task.priority = data['priority']

            if data.get('transition'):
                state = IWorkflowState(task).getState().title

                self.wfinfo.fireTransition(data['transition'], data['comment'])

                changes['status'] = [
                    state, IWorkflowState(task).getState().title]

            if 'assigned' in data:
                assignments = IAssignments(task)

                oldassignees = []
                for principal in assignments.getAssignees():
                    oldassignees.append(principal.title)
                oldassignees.sort()

                assignees = list(assignments.assignees)
                assignees.sort()
                newassignees = list(data['assigned'])
                newassignees.sort()

                if assignees != newassignees:
                    assignments.assign(newassignees)

                    assignees = []
                    for principal in assignments.getAssignees():
                        assignees.append(principal.title)
                    assignees.sort()

                    changes['assigned'] = [oldassignees, assignees]

            # attachments
            comment = data['comment']
            if 'file' in self.widgets:
                attachments = IAttachmentsExtension(self.context)
                chooser = INameChooser(attachments)
                files = self.request.form[self.widgets['file'].name]
                if isinstance(files, FileUpload):
                    files = [files]
            else:
                files = []

            attachs = []

            for file in files:
                if isinstance(file, FileUpload):
                    filename = os.path.split(file.filename)[1].lower().strip()

                    fdata = FileData(file, filename)
                    if fdata.mimeType in ('image/jpeg','image/gif','image/png'):
                        attach = Image(title=filename, description=comment)
                    else:
                        attach = File(title=filename, description=comment)

                    attach.data = fdata
                    event.notify(ObjectCreatedEvent(attach))

                    name = chooser.chooseName(filename, attach)
                    attachments[name] = attach

                    attachs.append(attach)

            if attachs:
                ids = getUtility(IIntIds)
                attachs = [ids.getId(attach) for attach in attachs]

            event.notify(ObjectModifiedEvent(task))

            discussion = IContentDiscussion(task)
            if discussion.status != 1:
                discussion.status = 1

            comment = data['comment'].render()

            comment = TaskComment(
                request.principal.id, comment, changes, attachs)
            comment.date = datetime.now(ITZInfo(self.request, utc))

            comment = discussion.add(comment)

            IStatusMessage(self.request).add(_('Comment has been added.'))
            self.redirect('.')