示例#1
0
文件: forms.py 项目: niran/localwiki
 def get_save_comment(self):
     comments = []
     short_comments = []
     previous = self.instance.pk and self.instance.tags or None
     d = TagsFieldDiff(previous, self.cleaned_data["tags"])
     diff = d.get_diff()
     deleted = ['"%s"' % t.name for t in diff["deleted"]]
     added = ['"%s"' % t.name for t in diff["added"]]
     if deleted:
         tag_name_pluralized = self.pluralize_tag(deleted)
         comments.append(
             ungettext("removed %(name)s %(deleted)s.", "removed %(name)s %(deleted)s.", len(deleted))
             % {"deleted": ", ".join(deleted), "name": tag_name_pluralized}
         )
         short_comments.append(
             ungettext("removed %(count)i %(name)s.", "removed %(count)i %(name)s.", len(deleted))
             % {"count": len(deleted), "name": tag_name_pluralized}
         )
     if added:
         tag_name_pluralized = self.pluralize_tag(added)
         comments.append(
             ungettext("added %(name)s %(added)s.", "added %(name)s %(added)s.", len(added))
             % {"added": ", ".join(added), "name": tag_name_pluralized}
         )
         short_comments.append(
             ungettext("added %(count)i %(name)s.", "added %(count)i %(name)s.", len(added))
             % {"count": len(added), "name": tag_name_pluralized}
         )
     if not comments:
         return _("no changes made")
     comments = _(" and ").join(comments)
     # with lots of tags, this can get too long for db field
     if len(comments) > 140:
         return _(" and ").join(short_comments)
     return comments
示例#2
0
 def get_save_comment(self):
     comments = []
     short_comments = []
     previous = self.instance.pk and self.instance.tags or None
     d = TagsFieldDiff(previous, self.cleaned_data['tags'])
     diff = d.get_diff()
     deleted = ['"%s"' % t.name for t in diff['deleted']]
     added = ['"%s"' % t.name for t in diff['added']]
     if deleted:
         tag_name_pluralized = self.pluralize_tag(deleted)
         comments.append(ungettext(
                     'removed %(name)s %(deleted)s.',
                     'removed %(name)s %(deleted)s.',
                     len(deleted)
             ) % {
                 'deleted': ', '.join(deleted),
                 'name': tag_name_pluralized
             }
         )
         short_comments.append(ungettext(
                     'removed %(count)i %(name)s.',
                     'removed %(count)i %(name)s.',
                     len(deleted)
             ) % {
                 'count': len(deleted),
                 'name': tag_name_pluralized
             }
         )
     if added:
         tag_name_pluralized = self.pluralize_tag(added)
         comments.append(ungettext(
                     'added %(name)s %(added)s.',
                     'added %(name)s %(added)s.',
                     len(added)
             ) % {
                 'added': ', '.join(added),
                 'name': tag_name_pluralized
             }
         )
         short_comments.append(ungettext(
                     'added %(count)i %(name)s.',
                     'added %(count)i %(name)s.',
                     len(added)
             ) % {
                 'count': len(added),
                 'name': tag_name_pluralized
             }
         )
     if not comments:
         return _('no changes made')
     comments = _(' and ').join(comments)
     # with lots of tags, this can get too long for db field
     if len(comments) > 140:
         return _(' and ').join(short_comments)
     return comments
 def get_save_comment(self):
     comments = []
     short_comments = []
     previous = self.instance.pk and self.instance.tags or None
     d = TagsFieldDiff(previous, self.cleaned_data['tags'])
     diff = d.get_diff()
     deleted = ['"%s"' % t.name for t in diff['deleted']]
     added = ['"%s"' % t.name for t in diff['added']]
     if deleted:
         tag_name_pluralized = self.pluralize_tag(deleted)
         comments.append(ungettext(
                     'removed %(name)s %(deleted)s.',
                     'removed %(name)s %(deleted)s.',
                     len(deleted)
             ) % {
                 'deleted': ', '.join(deleted),
                 'name': tag_name_pluralized
             }
         )
         short_comments.append(ungettext(
                     'removed %(count)i %(name)s.',
                     'removed %(count)i %(name)s.',
                     len(deleted)
             ) % {
                 'count': len(deleted),
                 'name': tag_name_pluralized
             }
         )
     if added:
         tag_name_pluralized = self.pluralize_tag(added)
         comments.append(ungettext(
                     'added %(name)s %(added)s.',
                     'added %(name)s %(added)s.',
                     len(added)
             ) % {
                 'added': ', '.join(added),
                 'name': tag_name_pluralized
             }
         )
         short_comments.append(ungettext(
                     'added %(count)i %(name)s.',
                     'added %(count)i %(name)s.',
                     len(added)
             ) % {
                 'count': len(added),
                 'name': tag_name_pluralized
             }
         )
     if not comments:
         return _('no changes made')
     comments = _(' and ').join(comments)
     # with lots of tags, this can get too long for db field
     if len(comments) > 140:
         return _(' and ').join(short_comments)
     return comments
示例#4
0
 def get_save_comment(self):
     comments = []
     short_comments = []
     previous = self.instance.pk and self.instance.tags or None
     d = TagsFieldDiff(previous, self.cleaned_data["tags"])
     diff = d.get_diff()
     deleted = ['"%s"' % t.name for t in diff["deleted"]]
     added = ['"%s"' % t.name for t in diff["added"]]
     if deleted:
         comments.append("removed %s %s" % (self.pluralize_tag(deleted), ", ".join(deleted)))
         short_comments.append("removed %i %s " % (len(deleted), self.pluralize_tag(deleted)))
     if added:
         comments.append("added %s %s" % (self.pluralize_tag(added), ", ".join(added)))
         short_comments.append("added %i %s " % (len(added), self.pluralize_tag(added)))
     if not comments:
         return "no changes made"
     comments = " and ".join(comments)
     # with lots of tags, this can get too long for db field
     if len(comments) > 140:
         return " and ".join(short_comments)
     return comments