- local = self.materialize().encode('utf-8')
- base = other.parent.materialize().encode('utf-8')
- remote = other.materialize().encode('utf-8')
-
- merge = simplemerge.Merge3Text(base, local, remote)
- result = ''.join(merge.merge_lines())
- merge_node = self.children.create(
- merge_parent=other, tree=self.tree,
- author=author,
- author_name=author_name,
- author_email=author_email,
- description=description)
- merge_node.data.save('', ContentFile(result))
- return merge_node
-
- def revert(self, **kwargs):
- """ commit this version of a doc as new head """
- self.tree.commit(text=self.materialize(), **kwargs)
-
-
-def create_tag_model(model):
- name = model.__name__ + 'Tag'
- attrs = {
- '__module__': model.__module__,
- }
- return type(name, (Tag,), attrs)
-
-
-def create_change_model(model):
- name = model.__name__ + 'Change'
-
- attrs = {
- '__module__': model.__module__,
- 'tree': models.ForeignKey(model, related_name='change_set'),
- 'tags': models.ManyToManyField(model.tag_model, related_name='change_set'),
- }
- return type(name, (Change,), attrs)
-
-
-
-class DocumentMeta(ModelBase):
- "Metaclass for Document models."
- def __new__(cls, name, bases, attrs):
- model = super(DocumentMeta, cls).__new__(cls, name, bases, attrs)
- if not model._meta.abstract:
- # create a real Tag object and `stage' fk
- model.tag_model = create_tag_model(model)
- models.ForeignKey(model.tag_model,
- null=True, blank=True).contribute_to_class(model, 'stage')
-
- # create real Change model and `head' fk
- model.change_model = create_change_model(model)
- models.ForeignKey(model.change_model,
- null=True, blank=True, default=None,
- help_text=_("This document's current head."),
- editable=False).contribute_to_class(model, 'head')
-
- return model
-
-
-
-class Document(models.Model):
- """
- File in repository.
- """
- __metaclass__ = DocumentMeta
-
- creator = models.ForeignKey(User, null=True, blank=True, editable=False,
- related_name="created_documents")
-
- user = models.ForeignKey(User, null=True, blank=True)