def _setParam(self): ContextManager.set('dateChangeNotificationProblems', {}) if (self._pTime < self._target.getStartDate()): raise ServiceError( "ERR-E3", "Date/time of end cannot " + "be lower than data/time of start") self._target.setDates(self._target.getStartDate(), self._pTime.astimezone(timezone("UTC")), moveEntries=0) dateChangeNotificationProblems = ContextManager.get( 'dateChangeNotificationProblems') if dateChangeNotificationProblems: warningContent = [] for problemGroup in dateChangeNotificationProblems.itervalues(): warningContent.extend(problemGroup) return Warning(_('Warning'), [ _('The end date of your event was changed correctly.'), _('However, there were the following problems:'), warningContent ]) else: return None
class ConferenceStartEndDateTimeModification(ConferenceModifBase): """ Conference start date/time modification When changing the start date / time, the _setParam method will be called by DateTimeModificationBase's _handleSet method. The _setParam method will return None (if there are no problems), or a Warning object if the event start date change was OK but there were side problems, such as an object observing the event start date change could not perform its task (Ex: a videoconference booking could not be moved in time according with the conference's time change) For this, it will check the 'dateChangeNotificationProblems' context variable. """ def _checkParams(self): ConferenceModifBase._checkParams(self) pm = ParameterManager(self._params.get('value'), timezone=self._conf.getTimezone()) self._startDate = pm.extract('startDate', pType=datetime.datetime) self._endDate = pm.extract('endDate', pType=datetime.datetime) def _getAnswer(self): ContextManager.set('dateChangeNotificationProblems', {}) if (self._startDate > self._endDate): raise ServiceError( "ERR-E3", "Date/time of start cannot " + "be greater than date/time of end") try: self._target.setDates(self._startDate, self._endDate, moveEntries=1) except TimingError, e: raise ServiceError("ERR-E2", e.getMsg()) dateChangeNotificationProblems = ContextManager.get( 'dateChangeNotificationProblems') if dateChangeNotificationProblems: warningContent = [] for problemGroup in dateChangeNotificationProblems.itervalues(): warningContent.extend(problemGroup) return Warning(_('Warning'), [ _('The start date of your event was changed correctly.'), _('However, there were the following problems:'), warningContent ]) else: return self._params.get('value')
raise TimingNoReportError(e.getMessage(), title=_("Cannot set event dates"), explanation=e.getExplanation()) dateChangeNotificationProblems = ContextManager.get( 'dateChangeNotificationProblems') if dateChangeNotificationProblems: warningContent = [] for problemGroup in dateChangeNotificationProblems.itervalues(): warningContent.extend(problemGroup) w = Warning(_('Warning'), [ _('The start date of your event was changed correctly. ' 'However, there were the following problems:'), warningContent ]) return ResultWithWarning(self._params.get('value'), w).fossilize() else: return self._params.get('value') class ConferenceListContributionsReview(ConferenceListModificationBase): """ Returns a list of all contributions of a conference, ordered by id """ def _checkParams(self): ConferenceListModificationBase._checkParams(self) pm = ParameterManager(self._params)
def _getAnswer(self): if self._user: idxs = indexes.IndexesHolder() funcGet = "get%s%s" % (self._dataType[0].upper(), self._dataType[1:]) funcSet = "set%s%s" % (self._dataType[0].upper(), self._dataType[1:]) if self._dataType == "title": if self._value in TitlesRegistry().getList(): self._user.setTitle(self._value) else: raise NoReportError(_("Invalid title value")) elif self._dataType == "surName": self._user.setFieldSynced('surName', False) self._user.setSurName(self._value, reindex=True) elif self._dataType == "name": self._user.setFieldSynced('firstName', False) self._user.setName(self._value, reindex=True) elif self._dataType == "organisation": self._user.setFieldSynced('affiliation', False) self._user.setOrganisation(self._value, reindex=True) elif self._dataType == "email": # Check if there is any user with this email address if self._value != self._avatar.getEmail(): other = user.AvatarHolder().match( {"email": self._value}, searchInAuthenticators=False) if other and other[0] != self._avatar: raise NoReportError( _("The email address %s is already used by another user." ) % self._value) self._user.setEmail(self._value, reindex=True) elif self._dataType == "secondaryEmails": emailList = self._buildEmailList() secondaryEmails = [] newSecondaryEmailAdded = False # check if every secondary email is valid for sEmail in emailList: sEmail = sEmail.lower().strip() if sEmail != "": av = user.AvatarHolder().match( {"email": sEmail}, searchInAuthenticators=False) if av and av[0] != self._avatar: raise NoReportError( _("The email address %s is already used by another user." ) % sEmail) elif self._user.getEmail( ) == sEmail: # do not accept primary email address as secondary continue elif self._user.hasSecondaryEmail(sEmail): secondaryEmails.append(sEmail) else: newSecondaryEmailAdded = True self._user.addPendingSecondaryEmail(sEmail) self._sendSecondaryEmailNotifiication(sEmail) self._user.setSecondaryEmails(secondaryEmails, reindex=True) if newSecondaryEmailAdded: warn = Warning( _("New secondary email address"), _("You will receive an email in order to confirm\ your new email address. Once confirmed, it will be shown in your profile." )) return ResultWithWarning( ", ".join(self._user.getSecondaryEmails()), warn).fossilize() else: return ", ".join(self._user.getSecondaryEmails()) elif self._dataType == "telephone": self._user.setFieldSynced('phone', False) self._user.setTelephone(self._value) elif self._dataType == "fax": self._user.setFieldSynced('fax', False) self._user.setFax(self._value) elif self._dataType == "address": self._user.setFieldSynced('address', False) self._user.setAddress(self._value) else: getattr(self._user, funcSet)(self._value) return getattr(self._user, funcGet)() else: raise ServiceError("ERR-U5", _("User id not specified"))