From 985ca3a21df2340caa545f27e5f01fd1eb87c9c8 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Wed, 25 May 2011 16:48:46 +0200 Subject: [PATCH] +Change.author_desc, minor changes --- apps/dvcs/migrations/0001_initial.py | 2 ++ apps/dvcs/models.py | 36 +++++++++++++++---- ...unique_chunk_book_number__add_unique_ch.py | 4 ++- apps/wiki/templates/wiki/document_list.html | 16 +++++---- apps/wiki/views.py | 9 +---- redakcja/static/css/filelist.css | 2 +- 6 files changed, 45 insertions(+), 24 deletions(-) diff --git a/apps/dvcs/migrations/0001_initial.py b/apps/dvcs/migrations/0001_initial.py index 16ba34df..7510e8ad 100644 --- a/apps/dvcs/migrations/0001_initial.py +++ b/apps/dvcs/migrations/0001_initial.py @@ -12,6 +12,7 @@ class Migration(SchemaMigration): db.create_table('dvcs_change', ( ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), ('author', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'], null=True, blank=True)), + ('author_desc', self.gf('django.db.models.fields.CharField')(max_length=128, null=True, blank=True)), ('patch', self.gf('django.db.models.fields.TextField')(blank=True)), ('tree', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['dvcs.Document'])), ('revision', self.gf('django.db.models.fields.IntegerField')(db_index=True)), @@ -86,6 +87,7 @@ class Migration(SchemaMigration): 'dvcs.change': { 'Meta': {'ordering': "('created_at',)", 'unique_together': "(['tree', 'revision'],)", 'object_name': 'Change'}, 'author': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}), + 'author_desc': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}), 'created_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'db_index': 'True'}), 'description': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), diff --git a/apps/dvcs/models.py b/apps/dvcs/models.py index ef11dbe8..7ac7cbef 100644 --- a/apps/dvcs/models.py +++ b/apps/dvcs/models.py @@ -15,6 +15,7 @@ class Change(models.Model): Data contains a pickled diff needed to reproduce the initial document. """ author = models.ForeignKey(User, null=True, blank=True) + author_desc = models.CharField(max_length=128, null=True, blank=True) patch = models.TextField(blank=True) tree = models.ForeignKey('Document') revision = models.IntegerField(db_index=True) @@ -38,6 +39,16 @@ class Change(models.Model): def __unicode__(self): return u"Id: %r, Tree %r, Parent %r, Patch '''\n%s'''" % (self.id, self.tree_id, self.parent_id, self.patch) + def author_str(self): + if self.author: + return "%s %s <%s>" % ( + self.author.first_name, + self.author.last_name, + self.author.email) + else: + return self.author_desc + + def save(self, *args, **kwargs): """ take the next available revision number if none yet @@ -67,20 +78,24 @@ class Change(models.Model): text = change.apply_to(text) return text - def make_child(self, patch, author, description): + def make_child(self, patch, description, author=None, author_desc=None): return self.children.create(patch=patch, tree=self.tree, author=author, + author_desc=author_desc, description=description) - def make_merge_child(self, patch, author, description): + def make_merge_child(self, patch, description, author=None, + author_desc=None): return self.merge_children.create(patch=patch, tree=self.tree, author=author, + author_desc=author_desc, description=description) def apply_to(self, text): return mdiff.patch(text, pickle.loads(self.patch.encode('ascii'))) - def merge_with(self, other, author, description=u"Automatic merge."): + def merge_with(self, other, author=None, author_desc=None, + description=u"Automatic merge."): assert self.tree_id == other.tree_id # same tree if other.parent_id == self.pk: # immediate child @@ -95,7 +110,8 @@ class Change(models.Model): patch = self.make_patch(local, result) return self.children.create( patch=patch, merge_parent=other, tree=self.tree, - author=author, description=description) + author=author, author_desc=author_desc, + description=description) def revert(self, **kwargs): """ commit this version of a doc as new head """ @@ -148,14 +164,20 @@ class Document(models.Model): patch = kwargs['patch'] author = kwargs.get('author', None) + author_desc = kwargs.get('author_desc', None) old_head = self.head if parent != old_head: - change = parent.make_merge_child(patch, author, kwargs.get('description', '')) + change = parent.make_merge_child(patch, author=author, + author_desc=author_desc, + description=kwargs.get('description', '')) # not Fast-Forward - perform a merge - self.head = old_head.merge_with(change, author=author) + self.head = old_head.merge_with(change, author=author, + author_desc=author_desc) else: - self.head = parent.make_child(patch, author, kwargs.get('description', '')) + self.head = parent.make_child(patch, author=author, + author_desc=author_desc, + description=kwargs.get('description', '')) self.save() return self.head diff --git a/apps/wiki/migrations/0003_auto__add_book__add_chunk__add_unique_chunk_book_number__add_unique_ch.py b/apps/wiki/migrations/0003_auto__add_book__add_chunk__add_unique_chunk_book_number__add_unique_ch.py index 59f1f620..229825d2 100644 --- a/apps/wiki/migrations/0003_auto__add_book__add_chunk__add_unique_chunk_book_number__add_unique_ch.py +++ b/apps/wiki/migrations/0003_auto__add_book__add_chunk__add_unique_chunk_book_number__add_unique_ch.py @@ -98,7 +98,7 @@ def migrate_file_from_hg(orm, fname, entry): maxrev = entry.filerev() gallery_link = None; for rev in xrange(maxrev + 1): - # TODO: author, tags, gallery + # TODO: tags fctx = entry.filectx(rev) data = fctx.data() gallery_link = gallery(fname, data) @@ -109,6 +109,7 @@ def migrate_file_from_hg(orm, fname, entry): patch=make_patch(old_data, data), created_at=datetime.datetime.fromtimestamp(fctx.date()[0]), description=fctx.description().decode("utf-8", 'replace'), + author_desc=fctx.user().decode("utf-8", 'replace'), parent=chunk.head ) chunk.head = head @@ -227,6 +228,7 @@ class Migration(SchemaMigration): 'dvcs.change': { 'Meta': {'ordering': "('created_at',)", 'unique_together': "(['tree', 'revision'],)", 'object_name': 'Change'}, 'author': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}), + 'author_desc': ('django.db.models.fields.CharField', [], {'max_length': '128', 'null': 'True', 'blank': 'True'}), 'created_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'db_index': 'True'}), 'description': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), diff --git a/apps/wiki/templates/wiki/document_list.html b/apps/wiki/templates/wiki/document_list.html index fd4760e9..f808a1d3 100644 --- a/apps/wiki/templates/wiki/document_list.html +++ b/apps/wiki/templates/wiki/document_list.html @@ -32,21 +32,23 @@ $(function() { {% for book in books %} - {{ book.title }} - - + + [?] {% ifequal book.chunk_set.count 1 %} - [{% trans "edit" %}] + {{ book.title }} {% else %} + {{ book.title }} +
{% for chunk in book %} - [{{ forloop.counter }}. - {{ chunk.comment }}]
+ {{ forloop.counter }}. + {{ chunk.comment }}
{% endfor %} +
{% endifequal %} diff --git a/apps/wiki/views.py b/apps/wiki/views.py index b3035422..8fa1fc9b 100644 --- a/apps/wiki/views.py +++ b/apps/wiki/views.py @@ -385,17 +385,10 @@ def history(request, slug, chunk=None): changes = [] for change in doc.history().order_by('-created_at'): - if change.author: - author = "%s %s <%s>" % ( - change.author.first_name, - change.author.last_name, - change.author.email) - else: - author = None changes.append({ "version": change.revision, "description": change.description, - "author": author, + "author": change.author_str(), "date": change.created_at, "tag": [], }) diff --git a/redakcja/static/css/filelist.css b/redakcja/static/css/filelist.css index f3de556d..7dfdf807 100644 --- a/redakcja/static/css/filelist.css +++ b/redakcja/static/css/filelist.css @@ -95,6 +95,6 @@ a:hover { td { vertical-align: top; } -.listitem-tools { +.chunk-list { padding-left: 2em; } -- 2.20.1