X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/5913c54d19b8f6775633176032161d49f9b2f1aa..040285e94b385dd57a003a4fe5b693c299fe921b:/src/dvcs/models.py?ds=sidebyside diff --git a/src/dvcs/models.py b/src/dvcs/models.py index 24bdeb3a..d6b0cc68 100644 --- a/src/dvcs/models.py +++ b/src/dvcs/models.py @@ -11,7 +11,7 @@ from django.core.files.base import ContentFile from django.db import models, transaction from django.db.models.base import ModelBase from django.utils.translation import string_concat, ugettext_lazy as _ -from mercurial import simplemerge +import merge3 from django.conf import settings from dvcs.signals import post_commit, post_publishable @@ -30,7 +30,7 @@ class Tag(models.Model): abstract = True ordering = ['ordering'] - def __unicode__(self): + def __str__(self): return self.name @classmethod @@ -93,7 +93,7 @@ class Change(models.Model): ordering = ('created_at',) unique_together = ['tree', 'revision'] - def __unicode__(self): + def __str__(self): return u"Id: %r, Tree %r, Parent %r, Data: %s" % (self.id, self.tree_id, self.parent_id, self.data) def author_str(self): @@ -124,7 +124,7 @@ class Change(models.Model): f = self.data.storage.open(self.data) text = f.read() f.close() - return unicode(text, 'utf-8') + return str(text, 'utf-8') def merge_with(self, other, author=None, author_name=None, author_email=None, @@ -135,11 +135,11 @@ class Change(models.Model): # immediate child - fast forward return other - local = self.materialize().encode('utf-8') - base = other.parent.materialize().encode('utf-8') - remote = other.materialize().encode('utf-8') + local = self.materialize().splitlines(True) + base = other.parent.materialize().splitlines(True) + remote = other.materialize().splitlines(True) - merge = simplemerge.Merge3Text(base, local, remote) + merge = merge3.Merge3(base, local, remote) result = ''.join(merge.merge_lines()) merge_node = self.children.create( merge_parent=other, tree=self.tree, @@ -225,11 +225,9 @@ class DocumentMeta(ModelBase): return model -class Document(models.Model): +class Document(models.Model, metaclass=DocumentMeta): """File in repository. Subclass it to use version control in your app.""" - __metaclass__ = DocumentMeta - # default repository path REPO_PATH = os.path.join(settings.MEDIA_ROOT, 'dvcs') @@ -238,7 +236,7 @@ class Document(models.Model): class Meta: abstract = True - def __unicode__(self): + def __str__(self): return u"{0}, HEAD: {1}".format(self.id, self.head_id) def materialize(self, change=None): @@ -256,12 +254,12 @@ class Document(models.Model): This will automatically merge the commit into the main branch, if parent is not document's head. - :param unicode text: new version of the document + :param str text: new version of the document :param parent: parent revision (head, if not specified) :type parent: Change or None :param User author: the commiter - :param unicode author_name: commiter name (if ``author`` not specified) - :param unicode author_email: commiter e-mail (if ``author`` not specified) + :param str author_name: commiter name (if ``author`` not specified) + :param str author_email: commiter e-mail (if ``author`` not specified) :param Tag[] tags: list of tags to apply to the new commit :param bool publishable: set new commit as ready to publish :returns: new head