Exemplo n.º 1
0
    def update(self):
        if self.context.state != 2:
            self.context.completeTask()
            event.notify(ObjectModifiedEvent(self.context))

            IStatusMessage(self.request).add(_('Task has been completed.'))

        self.redirect('./')
Exemplo n.º 2
0
    def update(self):
        if self.context.state != 1:
            self.context.reopenTask()
            event.notify(ObjectModifiedEvent(self.context))

            IStatusMessage(self.request).add(_('Milestone has been reopened.'))

        self.redirect('./')
Exemplo n.º 3
0
    def update(self):
        self.table = queryMultiAdapter(
            (self.context, self.request, self), IContentProvider, 'project.tasks')
        self.table.update()

        if 'button.complete' in self.request:
            self.context.completeTask()
            event.notify(ObjectModifiedEvent(self.context))
            IStatusMessage(self.request).add(_('Milestone has been completed.'))
            self.redirect('./')
            return

        if 'button.cancel' in self.request:
            self.redirect('./')
            return

        if not self.table:
            self.context.completeTask()
            event.notify(ObjectModifiedEvent(self.context))

            IStatusMessage(self.request).add(_('Milestone has been completed.'))
            self.redirect('./')
Exemplo n.º 4
0
    def update(self):
        if self.context.state != 1:
            self.context.reopenTask()
            event.notify(ObjectModifiedEvent(self.context))

            if self.context.milestone:
                try:
                    milestone = getUtility(IIntIds).queryObject(
                        self.context.milestone)
                except:
                    milestone = None
                if milestone is not None:
                    if milestone.state != 1:
                        removeAllProxies(milestone).reopenTask()
                        event.notify(ObjectModifiedEvent(milestone))
                        IStatusMessage(self.request).add(
                            _('Milestone and Task have been reopened.'))
                        self.redirect('./')
                        return

            IStatusMessage(self.request).add(_('Task has been reopened.'))

        self.redirect('./')
Exemplo n.º 5
0
    def update(self):
        context = self.context
        request = self.request

        if IStandaloneProjects.providedBy(context):
            browseAll = context.browse
        else:
            browseAll = False

        if not browseAll:
            self.hasGroups = bool(len(context))
            if not self.hasGroups:
                return

            searchContext = context
        else:
            searchContext = context.__parent__

        if 'form.search.clear' in request:
            self.redirect('./index.html')
            return

        catalog = getUtility(ICatalog)

        if 'form.search' in request:
            s = request.get('form.searchText', u'').strip()
            if s:
                query = {
                    'type': {'any_of': (
                            'content.project','content.standaloneproject')},
                    'isDraft': {'any_of': (False,)},
                    'projectState': {'any_of': (self.state,)},
                    'traversablePath': {'any_of': (searchContext,)},
                    'searchableText': s}

                try:
                    results = catalog.searchResults(**query)
                except ParseError, e:
                    IStatusMessage(request).add(e, 'error')
                    return

                self.batch = Batch(
                    results, size=context.pagecount,
                    context=context, request=request)
            else:
                IStatusMessage(request).add(
                    _('Please enter one or more words for search.'), 'warning')
            return
Exemplo n.º 6
0
    def update(self):
        super(TaskCommentView, self).update()

        changes = []
        for field, data in self.context.changes.items():
            if field in ITask:
                title = ITask[field].title
            elif field in ITaskAttributes:
                title = ITaskAttributes[field].title
            elif field == 'status':
                title = _('Workflow state')
            else:
                continue

            oldvalue = data[0]
            if type(data[0]) in (types.TupleType, types.ListType):
                oldvalue = u', '.join(data[0])

            newvalue = data[1]
            if type(data[1]) in (types.TupleType, types.ListType):
                newvalue = u', '.join(data[1])

            changes.append(
                (title, {'title': title, 'old': oldvalue, 'new': newvalue}))

        changes.sort()
        self.data = [info for _t, info in changes]

        # attachments
        attachments = []
        for attach in self.context.getAttachments():
            info = {'id': attach.__name__,
                    'title': attach.title or attach.__name__,
                    'description': attach.description,
                    'size': ISized(attach).sizeForDisplay(),
                    'image': False,
                    'attach': attach,
                    }
            if IImage.providedBy(attach):
                attach.preview.generatePreview(70, 70)
                info['image'] = True
                self.hasImages = True

            attachments.append(info)

        self.attachments = attachments
Exemplo n.º 7
0
    def update(self):
        self.task = removeAllProxies(self.context)

        if not checkPermission('zojax.DeleteContent', self.task):
            raise Unauthorized

        if 'form.delete.content' in self.request:
            del self.task.__parent__[self.task.__name__]

            IStatusMessage(self.request).add(_('Content has been deleted.'))
            self.redirect('../')
            return

        elif 'form.delete.cancel' in self.request:
            self.redirect('./')
            return

        super(TaskDelete, self).update()
Exemplo n.º 8
0
    def uploadHandler(self, action):
        data, errors = self.extractData()

        if errors:
            IStatusMessage(self.request).add(self.formErrorMessage, 'warning')
        else:
            comment = data['comment']
            files = self.request.form[self.widgets['file'].name]
            if isinstance(files, FileUpload):
                files = [files]

            attachments = IAttachmentsExtension(self.context)
            chooser = INameChooser(attachments)

            attachs = []

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

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

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

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

                    attachs.append(attach)

            sendNotification(
                'tasks', self.context, TaskAttachmentsInfo(comment, attachs))

            IStatusMessage(self.request).add(
                _('Attachments have been uploaded.'))
            self.redirect('.')
Exemplo n.º 9
0
    def update(self):
        attachments = []

        for attach in IAttachmentsExtension(self.context).values():
            ownership = IOwnership(attach)

            info = {'id': attach.__name__,
                    'title': attach.title or attach.__name__,
                    'description': attach.description,
                    'size': translate(ISized(attach).sizeForDisplay()),
                    'created': IDCTimes(attach).created,
                    'owner': ownership.owner and ownership.owner.title or _('Unknown'),
                    'image': False,
                    'attach': attach,
                    }
            if IImage.providedBy(attach):
                attach.preview.generatePreview(70, 70)
                info['image'] = True

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

        attachments.sort()
        self.attachments = [attach for _c, attach in attachments]
Exemplo n.º 10
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]
Exemplo n.º 11
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('.')