def infos(self): """Returns Infos for email-template""" responses = self.get_responses() author = readable_author(self.context) if isinstance(author, Message): author = self.context.translate(author) ticket_infos = {'tracker_title': self.context.aq_parent.title, 'tracker_url': self.context.aq_parent.absolute_url(), 'title': self.context.Title(), 'ticket_id': self.context.getId(), 'individualIdendifier': self.context.aq_parent.getIndividualIdentifier, 'url': self.context.absolute_url(), 'text': self.context.getTicket_description(), 'state': map_attribute(self.context, "state"), 'responsibleManager': author, 'priority': map_attribute(self.context, "priority"), 'area': map_attribute(self.context, "area"), 'variety': map_attribute(self.context, "variety"), 'releases': map_attribute(self.context, "releases"), 'watchedRelease': map_attribute(self.context, "watchedRelease"), 'answerDate': self.context.toLocalizedTime( self.context.getAnswerDate(), long_format=True), 'response': False} if responses == []: return ticket_infos else: response_date = responses[len(responses) - 1]['response'].date if self.context.modification_date > response_date: return ticket_infos else: response = responses[len(responses) - 1] changes = { 'tracker_title': self.context.aq_parent.title, 'tracker_url': self.context.aq_parent.absolute_url(), 'title': self.context.Title(), 'ticket_id': self.context.getId(), 'individualIdendifier': self.context.aq_parent.getIndividualIdentifier, 'url': self.context.absolute_url(), 'text': '', 'state': '', 'responsibleManager': '', 'priority': '', 'area': '', 'variety': '', 'releases': '', 'watchedRelease': '', 'answerDate': '', 'response': True} for item in response['response'].changes: # XXX: Hack to solve the label_unassigned translations # problem. # If we retrieve a responsibleManager named # label_unassigned, try to translate it if item['id'] == 'responsibleManager': if item['before'] == 'label_unassigned': item['before'] = self.context.translate( _(item['before'])) if item['after'] == 'label_unassigned': item['after'] = self.context.translate( _(item['after'])) changes[item['id']] = ( item['before'] + ' → ' + item['after']) changes['text'] = response['response'].text return changes
def __call__(self): form = self.request.form context = aq_inner(self.context) modifiedDate = context.modified() response_text = form.get('response', u'') new_response = Response(response_text) new_response.mimetype = self.mimetype new_response.type = self.determine_response_type(new_response) issue_has_changed = False #Unassigned is no member in portal_membership. #So we have to set it manually unassigned = _(u'label_unassigned', default=u'unassigned') responsible_after = form.get('responsibleManager', u'') if responsible_after != context.getResponsibleManager(): #get ResponsibleManager and member-infos before changes responsible_before = context.getResponsibleManager() member_before = self.context.portal_membership.getMemberById( responsible_before) context.setResponsibleManager(responsible_after) #get member-infos after changes member_after = self.context.portal_membership.getMemberById( responsible_after) #get fullname from member before changes if member_before: before = member_before.getProperty( 'fullname', responsible_before) else: before = unassigned #get fullname from member after changes if member_after: after = member_after.getProperty( 'fullname', responsible_after) else: after = unassigned new_response.add_change('responsibleManager', _(u'label_responsibleManager', default=u"Responsible"), before, after) issue_has_changed = True # Answerdate answerdate_before = context.getAnswerDate() if answerdate_before: answerdate_before = answerdate_before.strftime('%d.%m.%Y %H:%M') else: answerdate_before = '' answerdate_after = answerdate_before year = int(form.get('answerdate_year', 0)) month = int(form.get('answerdate_month', 0)) day = int(form.get('answerdate_day', 0)) if year and month and day: hour = int(form.get('answerdate_hour', 0)) minute = int(form.get('answerdate_minute', 0)) answerdate_after = DateTime( year, month, day, hour, minute).strftime('%d.%m.%Y %H:%M') if answerdate_before != answerdate_after: context.setAnswerDate(answerdate_after) new_response.add_change('answerDate', _(u'label_answerdate', default=u'Answerdate'), answerdate_before, answerdate_after) issue_has_changed = True options = [ ('priority', _(u'label_priority_', default=u"Priority"), 'available_priorities'), ('releases', _(u'label_releases', default=u"Target Release"), 'available_releases'), ('state', _(u'label_state', default=u"State"), 'available_states'), ('area', _(u'label_areas', default=u"Area"), 'available_areas'), ('variety', _(u'label_varieties', default=u"Variety"), 'available_varieties'), ('watchedRelease', _(u'label_watched_release', default=u"Watched Release"), 'available_watched_releases'), ] # Changes that need to be applied to the issue (apart from # workflow changes that need to be handled separately). changes = {} for option, title, vocab in options: new = form.get(option, u'') if new and new in self.__getattribute__(vocab): current = context.__getattribute__(option) if current != new: changes[option] = new new_response.add_change( option, title, map_attribute(self.context, option, current), map_attribute(self.context, option, new)) issue_has_changed = True attachment = form.get('attachment') if attachment: # Create filename like AT - some Browser delivers the # local full path filename = attachment.filename filename = filename[max( filename.rfind('/'), filename.rfind('\\'), filename.rfind(':')) + 1:] # File(id, title, file) data = File(filename, filename, attachment) if not hasattr(data, 'filename'): setattr(data, 'filename', filename) # Create TicketAttachment and save the uid in attachment attr of # new_response new_id = queryUtility(IIDNormalizer).normalize( filename.decode('utf-8')) if context.get(new_id, None): IStatusMessage(context.REQUEST).addStatusMessage( _(u"text_file_exists_error"), type='error') context.setAttachment('DELETE_FILE') return self.request.response.redirect(context.absolute_url()) new_file_id = context.invokeFactory( type_name="TicketAttachment", id=new_id, title=filename, file=data) new_file = context.get(new_file_id, None) new_response.attachment = new_file.UID() issue_has_changed = True references = form.get('ticketReferences') if references: new_response.references = references # Store refs also on Ticket self.context.setTicketReferences( references + self.context.getRawTicketReferences()) if len(response_text) == 0 and not issue_has_changed: status = IStatusMessage(self.request) msg = _( u"msg_no_changes", default="No response text added and no issue changes made.") # # msg = self.context.translate(msg) status.addStatusMessage(msg, type='error') else: # Apply changes to issue # XXX: CHANGE WORKFLOW - OR CHANGE SECURITYMANAGER # We cannot use AT's update method, because of a security check # we don't want. Let's set the new values manually. # OLD: # context.update(**changes) # NEW: if 'releases' in changes: context.setReleases(changes['releases']) if 'priority' in changes: context.setPriority(changes['priority']) if 'area' in changes: context.setArea(changes['area']) if 'variety' in changes: context.setVariety(changes['variety']) if 'state' in changes: context.setState(changes['state']) if 'watchedRelease' in changes: context.setWatchedRelease(changes['watchedRelease']) # Add response catalog_tool = self.context.portal_catalog # re-set the modification date - # this must be the last modifying access context.reindexObject() self.folder.add(new_response) context.setModificationDate(modifiedDate) catalog_tool.catalog_object(context, '/'.join(context.getPhysicalPath())) if form.get('sendNotification', None): self.request.response.redirect( context.absolute_url() + '/notification_form') else: self.request.response.redirect(context.absolute_url())
def map_variety(self): """ search the title-name of a list with the id """ return map_attribute(self.context, "variety")
def map_watched_release(self): """ search the title-name of a list with the id """ return map_attribute(self.context, "watchedRelease")
def map_area(self): """ search the title-name of a list with the id """ return map_attribute(self.context, "area")