1. Armin Ronacher
  2. zine-maintenance


mitsuhiko  committed bb2e502 Merge

Automated merge with ssh://team@pocoo.org/zine-0.1

  • Participants
  • Parent commits 4b48ca4, 93619da
  • Branches default

Comments (0)

Files changed (3)

File zine/forms.py

View file
         forms.Form.__init__(self, initial)
+        # if we have have an old post and the parser is not missing and
+        # it was published when the form was created we collect the old
+        # posts so that we don't have to ping them another time.
+        self._old_links = set()
+        if self.post is not None and not self.post.parser_missing and \
+           self.post.is_published:
+            self._old_links.update(self.post.find_urls())
+    def find_new_links(self):
+        """Return a list of all new links."""
+        for link in self.post.find_urls():
+            if not link in self._old_links:
+                yield link
     def validate_slug(self, value):
         """Make sure the slug is unique."""
         query = Post.query.filter_by(slug=value)
+        self.post = post
         return post
     def save_changes(self):
             raise ValidationError(_('This slug is already in use'))
     def make_category(self):
-        """A helper function taht creates a category object from the data."""
-        return Category(self.data['name'], self.data['description'],
-                        self.data['slug'] or None)
+        """A helper function that creates a category object from the data."""
+        category = Category(self.data['name'], self.data['description'],
+                            self.data['slug'] or None)
+        self.category = category
+        return category
     def save_changes(self):
         """Save the changes back to the database.  This also adds a redirect
         """A helper function that creates a new group object."""
         group = Group(self.data['groupname'])
+        self.group = group
         return group
     def save_changes(self):
         user = User(self.data['username'], self.data['password'],
+        self.user = user
         return user
     def save_changes(self):

File zine/models.py

View file
     def find_urls(self):
         """Iterate over all urls in the text.  This will only work if the
-        parser for this post is available.  If it's not the behavior is
-        undefined.  The urls returned are absolute urls.
+        parser for this post is available, otherwise an exception is raised.
+        The URLs returned are absolute URLs.
         from zine.parsers import parse
+        if self.parser_missing:
+            raise TypeError('parser is missing, urls cannot be looked up.')
         found = set()
         this_url = url_for(self, _external=True)
         tree = parse(self.text, self.parser, 'linksearch')

File zine/views/admin.py

View file
-from zine.i18n import _
+from zine.i18n import _, ngettext
 from zine.application import get_request, url_for, emit_event, \
      render_response, get_application
 from zine.models import User, Group, Post, Category, Comment, \
     return render_response(template_name, **values)
-def ping_post_links(request, post):
+def ping_post_links(form):
     """A helper that pings the links in a post."""
-    if request.app.cfg['maintenance_mode'] or not post.is_published:
+    pinged_successfully = []
+    if form.request.app.cfg['maintenance_mode'] or \
+       not form.post.is_published:
         flash(_(u'No URLs pinged so far because the post is not '
                 u'publicly available'))
-    elif post.parser_missing:
+    elif form.post.parser_missing:
         flash(_(u'Could not ping URLs because the parser for the '
                 u'post is not available any longer.'), 'error')
-        this_url = url_for(post, _external=True)
-        for url in post.find_urls():
+        this_url = url_for(form.post, _external=True)
+        for url in form.find_new_links():
             host = urlparse(url)[1].decode('utf-8', 'ignore')
             html_url = '<a href="%s">%s</a>' % (
                 escape(url, True),
                         'error': e.message
                     }, 'error')
-                flash(_(u'%s was pinged successfully.') %
-                        html_url)
+                pinged_successfully.append(html_url)
+    if pinged_successfully:
+        flash(ngettext(u'The following link was pinged successfully: %s',
+                       u'The following links where pinged successfully: %s',
+                       len(pinged_successfully)) %
+              u', '.join(pinged_successfully))
             emit_event('after-post-saved', post)
             if form['ping_links']:
-                ping_post_links(request, post)
+                ping_post_links(form)
             if 'save_and_continue' in request.form:
                 return redirect_to('admin/edit_post', post_id=post.id)
             return form.redirect('admin/new_entry')