+Change.author_desc, minor changes
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Wed, 25 May 2011 14:48:46 +0000 (16:48 +0200)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Wed, 25 May 2011 14:48:46 +0000 (16:48 +0200)
apps/dvcs/migrations/0001_initial.py
apps/dvcs/models.py
apps/wiki/migrations/0003_auto__add_book__add_chunk__add_unique_chunk_book_number__add_unique_ch.py
apps/wiki/templates/wiki/document_list.html
apps/wiki/views.py
redakcja/static/css/filelist.css

index 16ba34d..7510e8a 100644 (file)
@@ -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)),
         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)),
             ('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'}),
         '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'}),
             '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'}),
index ef11dbe..7ac7cbe 100644 (file)
@@ -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)
         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)
     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 __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
     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
 
             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,
         return self.children.create(patch=patch,
                         tree=self.tree, author=author,
+                        author_desc=author_desc,
                         description=description)
 
                         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,
         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')))
 
                         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 
         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,
         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 """
 
     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)
             patch = kwargs['patch']
 
         author = kwargs.get('author', None)
+        author_desc = kwargs.get('author_desc', None)
 
         old_head = self.head
         if parent != old_head:
 
         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
             # 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:
         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
 
         self.save()
         return self.head
index 59f1f62..229825d 100644 (file)
@@ -98,7 +98,7 @@ def migrate_file_from_hg(orm, fname, entry):
     maxrev = entry.filerev()
     gallery_link = None;
     for rev in xrange(maxrev + 1):
     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)
         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'),
             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
             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'}),
         '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'}),
             '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'}),
index fd4760e..f808a1d 100644 (file)
@@ -32,21 +32,23 @@ $(function() {
                <tbody>
        {% for book in books %}
             <tr>
                <tbody>
        {% for book in books %}
             <tr>
-                <td><a target="_blank" data-id="{{ book.slug }}"
-                    href="{% url wiki_book book.slug %}">{{ book.title }}</a>
-                </td>
-                <td class='listitem-tools'>
+                <td colspan="3">
+                    <a target="_blank" data-id="{{ book.slug }}"
+                    href="{% url wiki_book book.slug %}">[?]</a>
                     {% ifequal book.chunk_set.count 1 %}
                         <a target="_blank" data-id="{{ book.slug }}"
                                 href="{% url wiki_editor book.slug %}">
                     {% ifequal book.chunk_set.count 1 %}
                         <a target="_blank" data-id="{{ book.slug }}"
                                 href="{% url wiki_editor book.slug %}">
-                                [{% trans "edit" %}]</a>
+                                {{ book.title }}</a>
                     {% else %}
                     {% else %}
+                        {{ book.title }}
+                        <div class="chunk-list">
                         {% for chunk in book %}
                             <a target="_blank" data-id="{{ book.slug }}"
                                 href="{{ chunk.get_absolute_url }}">
                         {% for chunk in book %}
                             <a target="_blank" data-id="{{ book.slug }}"
                                 href="{{ chunk.get_absolute_url }}">
-                                [<span class='chunkno'>{{ forloop.counter }}.</span>
-                                {{ chunk.comment }}</a>]<br/>
+                                <span class='chunkno'>{{ forloop.counter }}.</span>
+                                {{ chunk.comment }}</a><br/>
                         {% endfor %}
                         {% endfor %}
+                        </div>
                     {% endifequal %}
                 </td>
                                <!-- placeholder </td> -->
                     {% endifequal %}
                 </td>
                                <!-- placeholder </td> -->
index b303542..8fa1fc9 100644 (file)
@@ -385,17 +385,10 @@ def history(request, slug, chunk=None):
 
     changes = []
     for change in doc.history().order_by('-created_at'):
 
     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,
         changes.append({
                 "version": change.revision,
                 "description": change.description,
-                "author": author,
+                "author": change.author_str(),
                 "date": change.created_at,
                 "tag": [],
             })
                 "date": change.created_at,
                 "tag": [],
             })
index f3de556..7dfdf80 100644 (file)
@@ -95,6 +95,6 @@ a:hover {
 td {
     vertical-align: top;
 }
 td {
     vertical-align: top;
 }
-.listitem-tools {
+.chunk-list {
     padding-left: 2em;
 }
     padding-left: 2em;
 }