def editBaseContent( self, title=None, abstract=None, body=None, publish_date=None, abstract_display_format="html", body_display_format="html", ): """ Update basic attributes title, body, publish date """ if title is not None: if not title.strip(): raise "NoTitleError", "Title must be something" self.title = unicodify(title.strip()) if abstract is not None: self.abstract = self.tidyText(unicodify(abstract.strip())) if body is not None: self.body = self.tidyText(unicodify(body.strip())) self.abstract_display_format = abstract_display_format self.body_display_format = body_display_format if publish_date is not None: if not publish_date: raise "DateTimeError", "publish_date can not be blank" elif self.same_type(publish_date, "s"): self.publish_date = DateTime(publish_date) else: assert self.same_type(publish_date, DateTime()) self.publish_date = publish_date self._cook() self.reindex_object()
def __init__(self, id, title=u'', description=u''): """ init """ self.id = id self.title = unicodify(title) self.description = unicodify(description) self.is_published = True self.create_date = DateTime()
def manage_addFAQ(dispatcher, id, title, abstract='', body='', publish_date=None, category = None, REQUEST=None): """ Create FAQ object """ if hasattr(dispatcher, 'Destination'): dest = dispatcher.Destination() else: dest = dispatcher if not title: raise "TitleError", "No title supplied" if isinstance(title, str): title = unicodify(title) if isinstance(abstract, str): abstract = unicodify(abstract) if isinstance(body, str): body = unicodify(body) if isinstance(category, str): category = unicodify(category) instance = FAQ(id, title, abstract, body, publish_date, category = category) dest._setObject(id, instance) object = dest._getOb(id) object._cook() if REQUEST is not None: REQUEST.RESPONSE.redirect(REQUEST.URL1+'/FAQManagement')
def __init__( self, id, title, abstract="", body="", publish_date=None, abstract_display_format="html", body_display_format="html", ): """ init """ self.id = id self.title = unicodify(title) self.body = unicodify(body) self.abstract = unicodify(abstract) self.create_date = DateTime() self.abstract_display_format = abstract_display_format self.body_display_format = body_display_format if not publish_date: publish_date = DateTime() elif isinstance(publish_date, basestring): publish_date = DateTime(publish_date) self.publish_date = publish_date self._rendered_abstract = u"" self._rendered_body = u"" self._cook()
def _cook(self): """ prepare the _rendered_abstract and _rendered_body """ text, fmt = self.getAbstract(), self.getAbstractDisplayFormat() text = unicodify(text) self._rendered_abstract = self.ShowText(text, fmt) text, fmt = self.getBody(), self.getBodyDisplayFormat() text = unicodify(text) self._rendered_body = self.ShowText(text, fmt)
def manage_addBlogItem(dispatcher, title, abstract='', body='', publish_date=None, abstract_display_format='plaintext', body_display_format='plaintext', blogitem_url='', id=None, category = None, REQUEST=None): """ create """ dest = dispatcher.Destination() if blogitem_url == 'http://': blogitem_url = '' if blogitem_url: if blogitem_url.startswith('http://http'): blogitem_url = blogitem_url[len('http://'):] if blogitem_url.startswith('http'): parsed = urlparse(blogitem_url) assert parsed[1], "URL has no domain" if not title: raise "TitleError", "No title supplied" if isinstance(title, str): title = unicodify(title) if isinstance(abstract, str): abstract = unicodify(abstract) if isinstance(body, str): body = unicodify(body) if isinstance(category, str): category = unicodify(category) if not id: id = manage_suggestBlogItemId(dest) instance = BlogItem(id, title, abstract, body, publish_date, blogitem_url, abstract_display_format=abstract_display_format, body_display_format=body_display_format, category = category) dest._setObject(id, instance) object = dest._getOb(id) object.DeployStandards() object._cook() if REQUEST is not None: REQUEST.RESPONSE.redirect(REQUEST.URL1+'/BlogManagement')
def editNewsItem(self, title=None, abstract=None, body=None, publish_date=None, abstract_display_format=None, body_display_format=None, newsitemurl=None, REQUEST=None): """ save changes to the news item """ if title is not None: if not title.strip(): raise "NoTitleError", "Title must be something" self.title = unicodify(title.strip()) if abstract is not None: self.abstract = self.tidyText(unicodify(abstract.strip())) if body is not None: self.body = self.tidyText(unicodify(body.strip())) if abstract_display_format is not None: self.abstract_display_format = abstract_display_format if body_display_format is not None: self.body_display_format = body_display_format if publish_date is not None: if not publish_date: raise "DateTimeError", "publish_date can not be blank" elif self.same_type(publish_date, 's'): self.publish_date = DateTime(publish_date) else: assert self.same_type(publish_date, DateTime()) self.publish_date = publish_date if newsitemurl is not None: if newsitemurl.startswith('http://http'): newsitemurl = newsitemurl[len('http://'):] if newsitemurl.startswith('http'): parsed = urlparse(newsitemurl) assert parsed[1], "URL has no domain" self.newsitemurl = newsitemurl self._cook() if REQUEST is not None: msg = "New details saved" url = self.absolute_url()+'/editNewsItemForm' self.http_redirect(url, msg=msg)
def addComment(self,title,body,path='',email='',website='',id=None): """ Add new comment. Id parameter is used in tests, in applicaton it should be left to generate automatically. Comment structure: - date - creation date - id - unigue id - path - strig build with ids separated by '/' from root to this comment - visible - boolean flag - title - comment title - body - text of the comment - email - optional email address - website - optional website - comments - list of subcomments with the same structure as this """ if self.isCommentingAvailable(): comment = PersistentMapping() comment['date'] = datetime.now() if not id: comment['id'] = str(time()) else: comment['id'] = id if path: comment['path'] = "%s/%s"%(path,comment['id']) else: comment['path'] = "%s"%(comment['id']) comment['visible'] = False comment['title'] = unicodify(title) comment['body'] = unicodify(body) comment['email'] = email comment['website'] = website comment['comments'] = PersistentList() if not path: self._comments.append(comment) else: comments = self._getCommentsList(path) comments.append(comment) if self.auto_approve: self.approveComment(comment['path']) self._sendNotificationEmailToWebmaster(comment) return comment['path'] else: return False
def manage_editBust(self, title, description, bigphoto, littleimage, REQUEST=None): """ edit bust """ self.title = unicodify(title) self.description = unicodify(description) big_photo_uploaded = False if getattr(bigphoto, 'filename', None): self.uploadPhoto(bigphoto) big_photo_uploaded = True if getattr(littleimage, 'filename', None): self.uploadThumbnail(littleimage) elif big_photo_uploaded: self.convertPhotoToThumbnail() if REQUEST is not None: self.http_redirect(self.absolute_url() + '/editBustForm', msg="Sparad")
def manage_addPage(context, id, title, abstract = u'', body=u'',publish_date=None, REQUEST=None): """ create """ if isinstance(title, str): title = unicodify(title) if isinstance(abstract, str): abstract = unicodify(abstract) if isinstance(body, str): body = unicodify(body) obj = Page(id, title, abstract = abstract, body = body, publish_date = publish_date) context._setObject(id, obj) item = context._getOb(id) if REQUEST is not None: msg = "Page created." url = REQUEST.URL1+'/PagesManagementHome' item.http_redirect(url, msg=msg) else: return item
def manage_addFile(dispatcher, title, file, fileid='', abstract=u'', REQUEST=None): """ create """ dest = dispatcher.Destination() if not fileid: filename = getattr(file, 'filename', '') fileid=filename[max(filename.rfind('/'), filename.rfind('\\'), filename.rfind(':'), )+1:] filid = fileid.replace('&','-and-') title = unicodify(title) abstract = unicodify(abstract) instance = File(fileid, title, file, abstract=abstract.strip()) dest._setObject(fileid, instance) object = dest._getOb(fileid) object.DeployStandards() object._cook() if REQUEST is not None: REQUEST.RESPONSE.redirect(REQUEST.URL1+'/FileManagement')
def manage_addHomepage(dispatcher, id, title=u'', REQUEST=None): """ create instance """ dest = dispatcher.Destination() title = unicodify(title) instance = Homepage(id, title) dest._setObject(id, instance) site = dest._getOb(id) site.DeployStandards() if REQUEST is not None: REQUEST.RESPONSE.redirect(REQUEST.URL1+'/manage_workspace') else: return site
def editFile(self, title, abstract, new_file=None, publish_date=None, REQUEST=None): """ save changes """ self.title = unicodify(title.strip()) self.abstract = unicodify(abstract.strip()) if publish_date is not None: if not publish_date: raise "DateTimeError", "publish_date can not be blank" elif self.same_type(publish_date, 's'): self.publish_date = DateTime(publish_date) else: assert self.same_type(publish_date, DateTime()) self.publish_date = publish_date if new_file is not None: if self.isFile(new_file): self.manage_upload(new_file) self._cook() if REQUEST is not None: msg = "New details saved" url = self.absolute_url()+'/editFileForm' self.http_redirect(url, msg=msg)
def manage_addBlogContainer(dispatcher, id, title=u'', REQUEST=None): """ create instance """ dest = dispatcher.Destination() id = id.strip() title = unicodify(title.strip()) if title and not id: id = internationalizeID(title.replace(' ','-')) instance = BlogContainer(id, title) dest._setObject(id, instance) object = dest._getOb(id) if REQUEST is not None: if REQUEST.get('goto_after'): url = REQUEST.get('goto_after') else: url = REQUEST.URL1+'/manage_workspace' REQUEST.RESPONSE.redirect(url)
def manage_addGuestbook(dispatcher, id, title, REQUEST=None, redirect_to=None): """ create instance """ if not id: id = title.replace("&", " o ").strip().replace(" ", " ") id = id.replace(" ", "-") id = internationalizeID(id) title = unicodify(title) dest = dispatcher.Destination() instance = Guestbook(id, title) dest._setObject(id, instance) object = dest._getOb(id) if REQUEST is not None: if redirect_to: REQUEST.RESPONSE.redirect(redirect_to) else: REQUEST.RESPONSE.redirect(REQUEST.URL1 + "/manage_workspace")
def manage_addNewsContainer(dispatcher, id, title='', REQUEST=None): """ create instance """ dest = dispatcher.Destination() if not id and title: id = internationalizeID(title) id = id.replace(' ','-') title = unicodify(title) instance = NewsContainer(id, title) dest._setObject(id, instance) object = dest._getOb(id) #object.DeployStandards() if REQUEST is not None: if REQUEST.get('goto_after'): url = REQUEST.get('goto_after') else: url = REQUEST.URL1+'/manage_workspace' REQUEST.RESPONSE.redirect(url) else: return object
def _createEntry(self, name, email, comment, city, webpage, how_found): id = DateTime().strftime("%Y%m%d") if hasattr(self, id): id = DateTime().strftime("%Y%m%d-%H%M") if hasattr(self, id): id = DateTime().strftime("%Y%m%d-%H%M%S") while hasattr(self, id): id = DateTime().strftime("%Y%m%d-%H%M%S") sleep(1) name = unicodify(name) email = unicodify(email) comment = unicodify(comment) city = unicodify(city) webpage = unicodify(webpage) how_found = unicodify(how_found) inst = Entry(id, name, email, comment, city, webpage, how_found) self._setObject(id, inst) entry = self._getOb(id) return entry
def __init__(self, id, title=u''): """ init """ self.title = unicodify(title) apply(HomepageBTreeBase.__init__, (self, id), {})
def _actual_RSS10(self, batchsize=None): request = self.REQUEST root = self.getRoot() header = '<?xml version="1.0" encoding="ISO-8859-1"?>\n\n' header += '<rdf:RDF\n' header += ' xmlns="http://purl.org/rss/1.0/"\n' header += ' xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"\n' header += ' xmlns:dc="http://purl.org/dc/elements/1.1/"\n' header += ' xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"' header += '\n>\n\n' rss_url = root.absolute_url() + '/rss.xml' header += '<channel rdf:about="%s">\n' % rss_url _title = root.getTitle() _title = re.compile(r'\(.*?\)$').sub('', _title).strip() header += ' <title>%s</title>\n' % _title header += ' <link>%s</link>\n' % root.absolute_url() header += ' <description>%s</description>\n' % root.getTagline() header += ' <dc:language>en-uk</dc:language>\n' header += ' <dc:publisher>%s</dc:publisher>\n' % self.webmasteremail logosrc = request.SERVER_URL logosrc += '/misc_/Peterbecom/peterbe_logo_white_small.gif' image = '<image>\n' image += ' <title>%s</title>\n' % _title image += ' <url>%s</url>\n' % logosrc image += ' <link>%s</link>\n' % root.absolute_url() image += ' <width>%s</width>\n' % 140 image += ' <height>%s</height>\n' % 37 image += ' <description>%s</description>\n' % root.getTitle() image += '</image>\n' xml = '' items = '<items>\n <rdf:Seq>\n' if batchsize is None: batchsize = 10 else: batchsize = int(batchsize) now = int(DateTime()) search = { 'meta_type': BLOGITEM_METATYPE, 'pub_date': { 'query': now, 'range': 'max' }, 'sort_on': 'pub_date', 'sort_order': 'reverse', 'sort_limit': batchsize * 2, } ocs = request.get('onlycategories', request.get('oc', [])) if ocs: search['itemcategories'] = ocs count = 0 blogitems = [] for brain in self.getCatalog().searchResults(search): blogitem = brain.getObject() if not blogitem.isBookmark(): blogitems.append(blogitem) count += 1 if count >= batchsize: break for blogitem in blogitems: blogurl = blogitem.alias_absolute_url() title = unicodify(blogitem.getTitle(), 'latin1') title = self._prepare_feed(title) description, remindercount = blogitem.showText(split=True) if remindercount: tmpl = '<br/>[<a href="%s" style="font-size:80%%">%s more words</a>]' description += tmpl % (blogitem.absolute_url(), remindercount) # massage text description = self._prepare_feed(description).strip() _categories = blogitem.getItemCategories(limit=1) if _categories: subject = ', '.join(_categories) else: subject = "" date = blogitem.getPubDate().strftime("%Y-%m-%dT%H:%M:%S+00:00") item = '<item rdf:about="%s">\n' % blogurl item += ' <title>%s</title>\n' % title item += ' <description>%s</description>\n' % description item += ' <link>%s</link>\n' % blogurl item += ' <dc:subject>%s</dc:subject>\n' % subject item += ' <dc:date>%s</dc:date>\n' % date item += '</item>\n\n' xml += item items += ' <rdf:li rdf:resource="%s" />\n' % blogurl items += ' </rdf:Seq>\n</items>\n' footer = '</rdf:RDF>' # Combine things header += items + image + '</channel>\n\n' rss = header + xml + footer then = DateTime() + 2 / 24.0 # 1 hour then = then.rfc822() response = request.RESPONSE response.setHeader('Content-Type', 'text/xml') response.setHeader('Expires', then) response.setHeader('Cache-Control', 'public,max-age=%d' % int(3600)) # 1 hour return rss
def _actual_RSS10(self, batchsize=None): request = self.REQUEST root = self.getRoot() header = '<?xml version="1.0" encoding="ISO-8859-1"?>\n\n' header += '<rdf:RDF\n' header +=' xmlns="http://purl.org/rss/1.0/"\n' header +=' xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"\n' header +=' xmlns:dc="http://purl.org/dc/elements/1.1/"\n' header +=' xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"' header +='\n>\n\n' rss_url = root.absolute_url()+'/rss.xml' header += '<channel rdf:about="%s">\n'%rss_url _title = root.getTitle() _title = re.compile(r'\(.*?\)$').sub('', _title).strip() header += ' <title>%s</title>\n'%_title header += ' <link>%s</link>\n'%root.absolute_url() header += ' <description>%s</description>\n'%root.getTagline() header += ' <dc:language>en-uk</dc:language>\n' header += ' <dc:publisher>%s</dc:publisher>\n'%self.webmasteremail logosrc = request.SERVER_URL logosrc += '/misc_/Peterbecom/peterbe_logo_white_small.gif' image = '<image>\n' image += ' <title>%s</title>\n'%_title image += ' <url>%s</url>\n'%logosrc image += ' <link>%s</link>\n'%root.absolute_url() image += ' <width>%s</width>\n'%140 image += ' <height>%s</height>\n'%37 image += ' <description>%s</description>\n'%root.getTitle() image += '</image>\n' xml = '' items = '<items>\n <rdf:Seq>\n' if batchsize is None: batchsize = 10 else: batchsize = int(batchsize) now = int(DateTime()) search = {'meta_type':BLOGITEM_METATYPE, 'pub_date': {'query':now, 'range':'max'}, 'sort_on':'pub_date', 'sort_order':'reverse', 'sort_limit':batchsize * 2, } ocs = request.get('onlycategories', request.get('oc', [])) if ocs: search['itemcategories'] = ocs count = 0 blogitems = [] for brain in self.getCatalog().searchResults(search): blogitem = brain.getObject() if not blogitem.isBookmark(): blogitems.append(blogitem) count += 1 if count >= batchsize: break for blogitem in blogitems: blogurl = blogitem.alias_absolute_url() title = unicodify(blogitem.getTitle(), 'latin1') title = self._prepare_feed(title) description, remindercount = blogitem.showText(split=True) if remindercount: tmpl = '<br/>[<a href="%s" style="font-size:80%%">%s more words</a>]' description += tmpl%(blogitem.absolute_url(), remindercount) # massage text description = self._prepare_feed(description).strip() _categories = blogitem.getItemCategories(limit=1) if _categories: subject = ', '.join(_categories) else: subject = "" date = blogitem.getPubDate().strftime("%Y-%m-%dT%H:%M:%S+00:00") item = '<item rdf:about="%s">\n'%blogurl item += ' <title>%s</title>\n'%title item += ' <description>%s</description>\n'%description item += ' <link>%s</link>\n'%blogurl item += ' <dc:subject>%s</dc:subject>\n'%subject item += ' <dc:date>%s</dc:date>\n'%date item += '</item>\n\n' xml += item items += ' <rdf:li rdf:resource="%s" />\n'%blogurl items += ' </rdf:Seq>\n</items>\n' footer = '</rdf:RDF>' # Combine things header += items + image + '</channel>\n\n' rss = header + xml + footer then = DateTime()+2/24.0 # 1 hour then = then.rfc822() response = request.RESPONSE response.setHeader('Content-Type', 'text/xml') response.setHeader('Expires', then) response.setHeader('Cache-Control', 'public,max-age=%d'%int(3600)) # 1 hour return rss
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)
def __init__(self, id, title=u""): """ init """ if isinstance(title, str): title = unicodify(title) self.title = title apply(HomepageBTreeBase.__init__, (self, id), {})