def shortDescription(self, maxlength=55, html=True): """ return a simplified description where the title is shown and then as much of the description as possible. """ title = self.getTitle() if title is None: title = self.action if not title.strip(): if html: title = "<i>(%s)</i>" % _("No subject") else: title = "(%s)" % _("No subject") desc = self.getCommentPure() if self.actual_time_hours: actual_time_hours = self._parseTimeHours(self.actual_time_hours) desc = "%s, %s" % \ (self.showTimeHours(actual_time_hours, show_unit=True), desc) shortened = self.lengthLimit(title, maxlength, "|...|") if shortened.endswith('|...|'): # the title was shortened shortened = shortened[:-len('|...|')] if html: return "<b>%s</b>..." % shortened else: return shortened + '...' else: # i.e. title==shortened # put some of the description ontop if len(shortened) + len(desc) > maxlength: desc = self.lengthLimit(desc, maxlength - len(title)) if html: return u"<b>%s</b>, %s" % (shortened, desc) else: return u"%s, %s" % (shortened, desc)
def shortDescription(self, maxlength=55, html=True): """ return a simplified description where the title is shown and then as much of the description as possible. """ title = self.getTitle() if title is None: title = self.action if not title.strip(): if html: title = "<i>(%s)</i>" % _("No subject") else: title = "(%s)" % _("No subject") desc = self.getCommentPure() if self.actual_time_hours: actual_time_hours = self._parseTimeHours(self.actual_time_hours) desc = "%s, %s" % \ (self.showTimeHours(actual_time_hours, show_unit=True), desc) shortened = self.lengthLimit(title, maxlength, "|...|") if shortened.endswith('|...|'): # the title was shortened shortened = shortened[:-len('|...|')] if html: return "<b>%s</b>..."%shortened else: return shortened+'...' else: # i.e. title==shortened # put some of the description ontop if len(shortened) + len(desc) > maxlength: desc = self.lengthLimit(desc, maxlength-len(title)) if html: return u"<b>%s</b>, %s"%(shortened, desc) else: return u"%s, %s"%(shortened, desc)
def loginPasskey(self, passkey, remember_passkey=False, REQUEST=None): """ try to log in """ users = self._findUserByPasskey(passkey) _success = False if users: uid = users[0].uid self._loginUID(uid) if remember_passkey: # automatic login. We actually don't store the password in a cookie, # we just store the uid in a special cookie variable. cookie_key = COOKIEKEY_AUTOLOGIN_UID days = AUTOLOGIN_EXPIRES_DAYS self.set_cookie(cookie_key, uid, expires=days, path='/' ) _success = True if REQUEST: if _success: success = _("Logged in") else: success = _("Could not log in :(") self.http_redirect(self.getRootURL(), success=success) else: return _success
def _mergeBirthdaysIntoMessage(self, birthdays, uid): """ put all birthday messages into one """ all_lines = [] all_html_lines = [] all_best_names = [] for birthday in birthdays: lines = [_("Don't forget, it's")] html_lines = lines[:] if birthday.name and birthday.email: best_name = birthday.name name = u"%s's" % birthday.name _html = u'<a href="mailto:%s"><strong>%s\'s</strong></a>' html_name = _html % (birthday.email, birthday.name) elif birthday.email: best_name = name = birthday.email _html = '<a href="mailto:%s"><strong>%s\'s</strong></a>' html_name = _html % (birthday.email, birthday.email) else: name = best_name = "%s's" % birthday.name best_name = birthday.name html_name = '<strong>%s\'s</strong>' % birthday.name if birthday.birthday_today: lines.append('\t%s birthday today!' % name) html_lines.append(' '*4 + '%s birthday today!' % html_name) elif birthday.days_till == 1: lines.append('\t%s birthday in one day!' % name) html_lines.append(' '*4 + '%s birthday in one day!' % html_name) else: lines.append('\t%s birthday in %s days!' % (name, birthday.days_till)) html_lines.append(' '*4 + '%s birthday in %s days!' % \ (html_name, birthday.days_till)) all_best_names.append(best_name) all_lines.append('\n'.join(lines)) all_html_lines.append('\n'.join(html_lines)+'\n\n') rooturl = self.getRootURL() user = self._getUser(uid) plain_footer, html_footer = self._getSigntureWithOptout(rooturl, user.passkey) all_lines.append(plain_footer) all_html_lines.append(html_footer) msg = '\n\n'.join(all_lines) html_msg = '\n'.join(all_html_lines) html_msg = newline_to_br(html_msg) if len(all_best_names) == 1: subject = _("RememberYourFriends.com birthday reminder for") + \ ' %s' % all_best_names[0] else: subject = _("RememberYourFriends.com birthday reminder ") + \ DateTime().strftime('%d %B') return subject, msg, html_msg
def _sendnaggings(self, verbose=False): """ send out a reminder to those people who have signed up but haven't added any reminders. The 'max_send' parameter is ignored. """ sent_to = [] rooturl = self.getRootURL() reminderless_users = self._getReminderlessUsers() subject = _("Getting started with RememberYourFriends.com") for user in reminderless_users: html = bool(user.html_emails) lines = [] html_lines = [] add_date = user.add_date_formatted para1 = _("You signed up to RememberYourFriends.com on the")+\ " " + add_date + " " +\ _("but haven't set up any reminders yet.") lines.append(para1) html_lines.append(para1) add_reminders_url = '%s/_%s/add' % \ (rooturl, user.passkey) html_lines.append(_('To add some, <a href="%s">go to the <b>Add a new reminder</b> page</a>') %\ add_reminders_url) lines.append(_('To add some, go to the Add a new reminder page:')+\ '\n'+ add_reminders_url) lines.append('\n') html_lines.append('\n') plain, html_ = self._getSigntureWithOptout(rooturl, user.passkey) html_lines.append(html_) lines.append(plain) msg = '\n\n'.join(lines) html_msg = '\n'.join(html_lines) html_msg = newline_to_br(html_msg) if html: self._sendEmailWrapped(user.email, self.getWebmasterFromfield(), subject, msg, html_msg) else: self._sendEmailWrapped(user.email, self.getWebmasterFromfield(), subject, msg) sent_to.append(user.email) if sent_to: return "Sent to %s" % ', '.join(sent_to) else: return "Didn't send to anyone"
def _initPageFolder(self): """make sure there is a PageFolder in this issuetracker called 'Pages' """ root = self.getRoot() if not getattr(root, 'Pages', None): instance = PageFolder('Pages', _(u"Pages")) root._setObject('Pages', instance)
def edit(self, REQUEST, RESPONSE): """save changes to page""" SubmitError = {} if not self.canViewPage(): # the chosen action requires manager role, # but the person is not a manager self.redirectlogin(came_from=self.absolute_url()) return if REQUEST.REQUEST_METHOD == "POST": title = REQUEST.form.get('title', '').strip() body = REQUEST.form.get('body', '').strip() parent = aq_parent(aq_inner(self)) if not title: SubmitError['title'] = _(u"Missing") else: # check that there isn't already a page by this exact title for page in parent.getPages(): if page is not self: if page.getTitle().lower() == title.lower(): SubmitError['title'] = \ _(u"Duplicate title. Already used on another page") break body = unicodify(body) try: body = self._validate_and_clean_body(body) except BodyValidationError, msg: SubmitError['body'] = unicodify(msg) if not SubmitError: if title != self.getTitle(): # new title, need to rename oid = _title_to_id(title) parent.manage_renameObjects([self.getId()], [oid]) self._savePage(title, body, REQUEST) # ready ! redirect! RESPONSE.redirect(self.absolute_url()+'/edit')
def edit(self, REQUEST, RESPONSE): """save changes to page""" SubmitError = {} if not self.canViewPage(): # the chosen action requires manager role, # but the person is not a manager self.redirectlogin(came_from=self.absolute_url()) return if REQUEST.REQUEST_METHOD == "POST": title = REQUEST.form.get('title', '').strip() body = REQUEST.form.get('body', '').strip() parent = aq_parent(aq_inner(self)) if not title: SubmitError['title'] = _(u"Missing") else: # check that there isn't already a page by this exact title for page in parent.getPages(): if page is not self: if page.getTitle().lower() == title.lower(): SubmitError['title'] = \ _(u"Duplicate title. Already used on another page") break body = unicodify(body) try: body = self._validate_and_clean_body(body) except BodyValidationError, msg: SubmitError['body'] = unicodify(msg) if not SubmitError: if title != self.getTitle(): # new title, need to rename oid = _title_to_id(title) parent.manage_renameObjects([self.getId()], [oid]) self._savePage(title, body, REQUEST) # ready ! redirect! RESPONSE.redirect(self.absolute_url() + '/edit')
def manage_passwordReminder(self, name): """ wrap up a template """ try: user = self.getUser(name) except: return MessageDialog( title ='Illegal value', message='The specified user does not exist', action ='manage_main') issuetrackerroot = self.getIssueTrackerRoot() if self.webmaster_email: from_field = self.webmaster_email elif issuetrackerroot: from_field = issuetrackerroot.getSitemasterFromField() else: from_field = "" subject = _("Password reminder") if issuetrackerroot is not None: subject = "%s: %s" % (issuetrackerroot.getTitle(), subject) msg = "Dear %(fullname)s,\n\n" msg += "This is a password reminder for you to use on %(url)s.\n" if self.encrypt_passwords: msg += "Since your previous password was encrypted we have had "\ "to recreate a new password for you.\n" msg += "Your username is still: %(username)s\nand your password is: "\ "<password shown here>" msg += "\n\n" msg += "PS. The administrator sending this password reminder will"\ " not able to read your password at any time." #if issuetrackerroot is not None: # msg += "Now you can go to %s and log in"%(issuetrackerroot.absolute_url() d = {'fullname':user.getFullname(), 'username':name} if issuetrackerroot is not None: d['url'] = issuetrackerroot.absolute_url() else: d['url'] = self.absolute_url().replace('/acl_users','') msg = msg % d return self._passwordReminder(self, self.REQUEST, user=user, username=name, subject=subject, message=msg, from_field=from_field)
def _getSigntureWithOptout(self, rooturl, passkey): """ return a tuple with the (plain, html) signature with the opt-out link in it. """ unsubscribe_url = "%s/_%s/unsubscribe" %(rooturl, passkey) unsubscribe_link_start = _("To unsubscribe go to") unsubscribe_link = "%s %s" % (unsubscribe_link_start, unsubscribe_url) unsubscribe_link_html = '%s <a href="%s">the unsubscribe page</a>' \ % (unsubscribe_link_start, unsubscribe_url) plain = '--\n%s\n%s' % (self.getSignature(), unsubscribe_link) sig_wrapper = '<span style="font-size:0.9em;color:#666">--\n%s\n%s</span>' sig_url_wrapper = '<a href="%s" style="font-weight:bold">RememberYourFriends.com</a>' root_url_with_passkey = '%s/_%s' % (rooturl, passkey) signature = self.getSignature().replace('RememberYourFriends.com', sig_url_wrapper % root_url_with_passkey) html = sig_wrapper % (signature, unsubscribe_link_html) return plain, html
def addNewPage(self, REQUEST, RESPONSE): """page for adding new pages""" SubmitError = {} if REQUEST.REQUEST_METHOD == 'POST': print REQUEST.form title = REQUEST.form.get('title', '').strip() if not title: SubmitError['title'] = _(u"Title missing") if not SubmitError: page = self._createNewPage(title) return RESPONSE.redirect(page.absolute_url()+'/edit') return self.addNewPage_template(REQUEST, RESPONSE, SubmitError=SubmitError)
def addNewPage(self, REQUEST, RESPONSE): """page for adding new pages""" SubmitError = {} if REQUEST.REQUEST_METHOD == 'POST': print REQUEST.form title = REQUEST.form.get('title', '').strip() if not title: SubmitError['title'] = _(u"Title missing") if not SubmitError: page = self._createNewPage(title) return RESPONSE.redirect(page.absolute_url() + '/edit') return self.addNewPage_template(REQUEST, RESPONSE, SubmitError=SubmitError)
ISSUEASSIGNMENT_METATYPE = 'Issue Tracker Assignment' FILTEROPTION_METATYPE = 'Issue Tracker Filter Option' REPORTSCRIPT_METATYPE = 'Issue Tracker Report Script' REPORTS_CONTAINER_METATYPE = 'Report Scripts Container' CUSTOMFIELD_METATYPE = 'Issue Tracker Custom Field' CUSTOMFIELDFOLDER_METATYPE = 'Issue Tracker Custom Field Folder' CUSTOMFIELD_VALIDATION_EXPRESSION_METATYPE = 'Issue Tracker Custom Field Validation Expression' PAGE_METATYPE = 'Issue Tracker Page' PAGE_FOLDER_METATYPE = 'Issue Tracker Page Folder' PAGE_CHANGE_METATYPE = 'Issue Tracker Page Change' # properties #DEFAULT_TYPES = ('general', 'announcement', 'idea', 'bug report', # 'feature request','question', # 'usability','other') DEFAULT_TYPES = (_(u'general'), _(u'announcement'), _(u'idea'), _(u'bug report'), _(u'feature request'), _(u'question'), _(u'usability'), _(u'other'), ) DEFAULT_TYPE = DEFAULT_TYPES[0] #DEFAULT_URGENCIES = ('low','normal','high','critical') DEFAULT_URGENCIES = (_(u'low'), _(u'normal'), _(u'high'), _(u'critical')) DEFAULT_ALWAYS_NOTIFY = () DEFAULT_ALWAYS_NOTIFY_EVERYTHING = False DEFAULT_URGENCY = DEFAULT_URGENCIES[1] DEFAULT_SECTIONS_OPTIONS = (_(u'General'), _(u'Homepage'), _(u'Other')) DEFAULT_SECTIONS = [DEFAULT_SECTIONS_OPTIONS[0]] DEFAULT_WHEN_IGNORE_WORD = 'ignored' DEFAULT_DISPLAY_DATE = '%d/%m %Y %H:%M %Z' DEFAULT_SITEMASTER_NAME = 'Issue Tracker'
def getYourNameInput(self): default = str(_(u"Your name")) tmpl = '<input name="name" size="17" style="color:#ccc" value="%s" '\ 'onfocus="if(this.value==%r){this.value=\'\';this.style.color=\'black\'}" '\ 'onblur="if(this.value==\'\'){this.value=%r;this.style.color=\'#ccc\'}" />' return tmpl % (default, default, default)
def showMonthName(self, m): return { 1: _(u"January"), 2: _(u"February"), 3: _(u"March"), 4: _(u"April"), 5: _(u"May"), 6: _(u"June"), 7: _(u"July"), 8: _(u"August"), 9: _(u"September"), 10: _(u"October"), 11: _(u"November"), 12: _(u"December") }[m]
FILTEROPTION_METATYPE = 'Issue Tracker Filter Option' REPORTSCRIPT_METATYPE = 'Issue Tracker Report Script' REPORTS_CONTAINER_METATYPE = 'Report Scripts Container' CUSTOMFIELD_METATYPE = 'Issue Tracker Custom Field' CUSTOMFIELDFOLDER_METATYPE = 'Issue Tracker Custom Field Folder' CUSTOMFIELD_VALIDATION_EXPRESSION_METATYPE = 'Issue Tracker Custom Field Validation Expression' PAGE_METATYPE = 'Issue Tracker Page' PAGE_FOLDER_METATYPE = 'Issue Tracker Page Folder' PAGE_CHANGE_METATYPE = 'Issue Tracker Page Change' # properties #DEFAULT_TYPES = ('general', 'announcement', 'idea', 'bug report', # 'feature request','question', # 'usability','other') DEFAULT_TYPES = ( _(u'general'), _(u'announcement'), _(u'idea'), _(u'bug report'), _(u'feature request'), _(u'question'), _(u'usability'), _(u'other'), ) DEFAULT_TYPE = DEFAULT_TYPES[0] #DEFAULT_URGENCIES = ('low','normal','high','critical') DEFAULT_URGENCIES = (_(u'low'), _(u'normal'), _(u'high'), _(u'critical')) DEFAULT_ALWAYS_NOTIFY = () DEFAULT_ALWAYS_NOTIFY_EVERYTHING = False DEFAULT_URGENCY = DEFAULT_URGENCIES[1]
def sendUsersReminders(self, uid, reminders): """ if reminder.name and reminder.email: name = "%s (%s)" % (reminder.name, reminder.email) elif reminder.email: name = reminder.email else: name = reminder.name if reminder.snooze: msgs.append("Need to send snoozed reminder to %s" % name) else: msgs.append("Need to send reminder to %s" % name) """ if not reminders: return all_lines = [] all_html_lines = [] all_urls = {} all_names = [] user = self._getUser(uid, True) # prepare the extra text that we'll throw into the email nag = html_nag = '' if random.randint(1,3)==1 and not (\ user.first_name or \ user.last_name): # ok, this time we'll nag about getting them to enter their name html_nag = _("You still haven't completed your full name.\n") settings_url = '%s/_%s/settings' % (self.getRootURL(), user.passkey) nag = html_nag + _('Follow this link to change your settings: %s') % settings_url html_nag += _('Do that on the <a href="%s">your settings page</a>.') % settings_url elif random.randint(1,3) == 1 and len(reminders) == 1 and \ self._invitableReminder(reminders[0].rid, uid=uid): r = reminders[0] if r.name: name = r.name else: name = r.email name = unicodify(name, UNICODE_ENCODING) #LOG("RememberYourFriends.Cron", INFO, "name =%r" % name) html_nag = _(u"Do you want to invite %s to also use RememberYourFriends.com?") % name html_nag += ' ' nag = html_nag invite_url = '%s/_%s/r%s/send-invite' % (self.getRootURL(), user.passkey, r.rid) nag += _('If so, click this link: %s') % invite_url html_nag += _('If so, go to the <a href="%s">Send invite page</a>') % invite_url elif random.randint(1,4) == 1: send_invite_url = '%s/_%s/send-invite' % (self.getRootURL(), user.passkey) html_nag = _(u"You can invite more friends to RememberYourFriends.com") nag = html_nag + ' ' + _('on this page: %s') % send_invite_url html_nag += ' ' + _('on the <a href="%s">Send invite page</a>.') % send_invite_url elif random.randint(1,3) == 1: add_reminders_url = '%s/_%s/add' % \ (self.getRootURL(), user.passkey) html_nag = _(u"To add more reminders of other friends or change your current reminders") nag = html_nag + ' '+ _("go to this page: %s") % add_reminders_url html_nag += ' ' + _('go to the <a href="%s">Add a new reminder page</a>.') % add_reminders_url rooturl = self.getRootURL() for reminder in reminders: if reminder.paused: self._resetReminder(reminder.rid) continue lines = [_("You are being reminded to remember:")] html_lines = lines[:] if reminder.name and reminder.email: best_name = reminder.name name = "%s, %s" % (reminder.name, reminder.email) _html = '<a href="mailto:%s"><strong>%s</strong></a>' html_name = _html % (reminder.email, reminder.name) elif reminder.email: best_name = name = reminder.email _html = '<a href="mailto:%s"><strong>%s</strong></a>' html_name = _html % (reminder.email, reminder.email) else: name = best_name = reminder.name html_name = '<strong>%s</strong>' % reminder.name name = unicodify(name, UNICODE_ENCODING) html_name = unicodify(html_name, UNICODE_ENCODING) lines.append('\t%s\n' % name) html_lines.append(' '*4 + '%s\n' % html_name) all_names.append(name) count_sent_reminders = self._countSentRemindersByReminder(reminder.rid) if count_sent_reminders: rid = reminder.rid last_reminder = self._getSentRemindersByReminder(rid, limit=1, order='add_date', reverse=True)[0] if count_sent_reminders == 1: msg = _("One reminder sent before.") else: msg = _("%s reminders sent before.") % count_sent_reminders if last_reminder.snoozed: msg += " " + _("It was snoozed %s days") % last_reminder.snoozed lines.append(msg) html_lines.append(msg) lines.append(_("Snooze options:")) html_snooze_msg = _("Snooze this:") urls = [] _options = ('1 day', '2 days', '1 week','1 month') for e in _options: url = "%s/_%s/r%s/SNOOZE...%s" %(rooturl, user.passkey, reminder.rid, e.replace(' ','.')) all_urls[url] = e urls.append(url) html_snooze_msg += ' ' + ', '.join(urls) for url, label in all_urls.items(): html_snooze_msg = html_snooze_msg.replace(url, '<a href="%s">%s</a>' % (url, label)) lines.extend(urls) html_lines.append(html_snooze_msg) best_name = unicodify(best_name, UNICODE_ENCODING) if reminder.birthday and reminder.birthmonth: LOG("RememberYourFriends.Cron", INFO, "best_name =%r" % best_name) _edit_msg = _(u"Change settings for %s") % best_name _edit_href = '%s/_%s/edit?rid=%s&sbf=y' %\ (rooturl, user.passkey, reminder.rid) else: _edit_msg = _(u"Do you know %s's birthday?") % best_name _edit_href = '%s/_%s/edit?rid=%s' % (rooturl, user.passkey, reminder.rid) html_lines.append('<a href="%s" style="font-size:80%%">%s</a>' %\ (_edit_href, _edit_msg)) all_lines.append('\n'.join(lines)) LOG("RememberYourFriends.Cron", INFO, "html_lines =%s"%html_lines) all_html_lines.append('\n'.join(html_lines)+'\n\n') # remember that we sent something on this reminder self._logSentReminder(reminder.rid) # move the next_date forward and reset the snooze self._resetReminder(reminder.rid) if nag: all_lines.append(nag+'\n') if html_nag: all_html_lines.append(html_nag+'\n') plain_footer, html_footer = self._getSigntureWithOptout(rooturl, user.passkey) all_lines.append(plain_footer) all_html_lines.append(html_footer) msg = '\n\n'.join(all_lines) html_msg = '\n'.join(all_html_lines) html_msg = newline_to_br(html_msg) subject = _("RememberYourFriends.com reminder: ") + DateTime().strftime('%d %B') # Send it!! user = self._getUser(uid) if user.html_emails: self._sendEmailWrapped(user.email, self.getWebmasterFromfield(), subject, msg, html_msg) else: self._sendEmailWrapped(user.email, self.getWebmasterFromfield(), subject, msg)