Anonymous avatar Anonymous committed bb2e502 Merge

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

Comments (0)

Files changed (3)

 
         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)
         post.bind_categories(data['categories'])
         post.bind_tags(data['tags'])
         self._set_common_attributes(post)
+        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._set_common_attributes(group)
+        self.group = group
         return group
 
     def save_changes(self):
         user = User(self.data['username'], self.data['password'],
                     self.data['email'])
         self._set_common_attributes(user)
+        self.user = user
         return user
 
     def save_changes(self):
 
     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')

zine/views/admin.py

      CREATE_ENTRIES, EDIT_OWN_ENTRIES, EDIT_OTHER_ENTRIES, \
      CREATE_PAGES, EDIT_OWN_PAGES, EDIT_OTHER_PAGES, MODERATE_COMMENTS, \
      MANAGE_CATEGORIES, BLOG_ADMIN
-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')
     else:
-        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')
             else:
-                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))
 
 
 @require_admin_privilege()
             db.commit()
             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')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.