# Path: wiki/models.py
# class Article(models.Model):
#     """ A wiki page.
#     """
#     title = models.CharField(_(u"Title"), max_length=50)
#     content = models.TextField(_(u"Content"))
#     summary = models.CharField(_(u"Summary"), max_length=150,
#                                null=True, blank=True)
#     markup = models.CharField(_(u"Content Markup"), max_length=3,
#                               choices=markup_choices,
#                               null=True, blank=True)
#     creator = models.ForeignKey(User, verbose_name=_('Article Creator'),
#                                 null=True)
#     creator_ip = models.IPAddressField(_("IP Address of the Article Creator"),
#                                        blank=True, null=True)
#     created_at = models.DateTimeField(default=datetime.now)
#     last_update = models.DateTimeField(blank=True, null=True)
#     removed = models.BooleanField(_("Is removed?"), default=False)
# 
#     content_type = models.ForeignKey(ContentType, null=True)
#     object_id = models.PositiveIntegerField(null=True)
#     group = generic.GenericForeignKey('content_type', 'object_id')
# 
#     tags = TagField()
# 
#     objects = QuerySetManager()
# 
#     non_removed_objects = NonRemovedArticleManager()
# 
#     class QuerySet(QuerySet):
# 
#         def get_by(self, title, group=None):
#             if group is None:
#                 return self.get(title=title)
#             return group.get_related_objects(self.filter(title=title)).get()
#             
#     class Meta:
#         verbose_name = _(u'Article')
#         verbose_name_plural = _(u'Articles')
# 
#     def get_absolute_url(self):
#         if self.group is None:
#             return reverse('wiki_article', args=(self.title,))
#         return self.group.get_absolute_url() + 'wiki/' + self.title
# 
#     def save(self, force_insert=False, force_update=False):
#         self.last_update = datetime.now()
#         super(Article, self).save(force_insert, force_update)
# 
#     def remove(self):
#         """ Mark the Article as 'removed'. If the article is
#         already removed, delete it.
#         Returns True if the article was deleted, False when just marked
#         as removed.
#         """
#         if self.removed:
#             self.delete()
#             return True
#         else:
#             self.removed = True
#             self.save()
#             return False
# 
#     def latest_changeset(self):
#         try:
#             return self.changeset_set.filter(
#                 reverted=False).order_by('-revision')[0]
#         except IndexError:
#             return ChangeSet.objects.none()
# 
#     def new_revision(self, old_content, old_title, old_markup,
#                      comment, editor_ip, editor):
#         '''Create a new ChangeSet with the old content.'''
# 
#         content_diff = diff(self.content, old_content)
# 
#         cs = ChangeSet.objects.create(
#             article=self,
#             comment=comment,
#             editor_ip=editor_ip,
#             editor=editor,
#             old_title=old_title,
#             old_markup=old_markup,
#             content_diff=content_diff)
# 
#         if None not in (notification, self.creator):
#             if editor is None:
#                 editor = editor_ip
#             notification.send([self.creator], "wiki_article_edited",
#                               {'article': self, 'user': editor})
# 
#         return cs
# 
#     def revert_to(self, revision, editor_ip, editor=None):
#         """ Revert the article to a previuos state, by revision number.
#         """
#         changeset = self.changeset_set.get(revision=revision)
#         changeset.reapply(editor_ip, editor)
# 
# 
#     def __unicode__(self):
#         return self.title


import re
from django import forms
from django.forms import widgets
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.utils.translation import ugettext_lazy as _
from wiki.models import Article
# -*- coding: utf-8 -*-



try:
    WIKI_WORD_RE = settings.WIKI_WORD_RE
except AttributeError:
    WIKI_WORD_RE = r'(?:[A-Z]+[a-z]+){2,}'


wikiword_pattern = re.compile('^' + WIKI_WORD_RE + '$')


class ArticleForm(forms.ModelForm):

    summary = forms.CharField(widget=forms.Textarea)

    comment = forms.CharField(required=False)
    user_ip = forms.CharField(widget=forms.HiddenInput)

    content_type = forms.ModelChoiceField(
        queryset=ContentType.objects.all(),
        required=False,
        widget=forms.HiddenInput)
    object_id = forms.IntegerField(required=False,
                                   widget=forms.HiddenInput)

    action = forms.CharField(widget=forms.HiddenInput)

    class Meta:

# Path: wiki/models.py
# class Article(models.Model):
#     """ A wiki page.
#     """
#     title = models.CharField(_(u"Title"), max_length=50)
#     content = models.TextField(_(u"Content"))
#     summary = models.CharField(_(u"Summary"), max_length=150,
#                                null=True, blank=True)
#     markup = models.CharField(_(u"Content Markup"), max_length=3,
#                               choices=markup_choices,
#                               null=True, blank=True)
#     creator = models.ForeignKey(User, verbose_name=_('Article Creator'),
#                                 null=True)
#     creator_ip = models.IPAddressField(_("IP Address of the Article Creator"),
#                                        blank=True, null=True)
#     created_at = models.DateTimeField(default=datetime.now)
#     last_update = models.DateTimeField(blank=True, null=True)
#     removed = models.BooleanField(_("Is removed?"), default=False)
# 
#     content_type = models.ForeignKey(ContentType, null=True)
#     object_id = models.PositiveIntegerField(null=True)
#     group = generic.GenericForeignKey('content_type', 'object_id')
# 
#     tags = TagField()
# 
#     objects = QuerySetManager()
# 
#     non_removed_objects = NonRemovedArticleManager()
# 
#     class QuerySet(QuerySet):
# 
#         def get_by(self, title, group=None):
#             if group is None:
#                 return self.get(title=title)
#             return group.get_related_objects(self.filter(title=title)).get()
#             
#     class Meta:
#         verbose_name = _(u'Article')
#         verbose_name_plural = _(u'Articles')
# 
#     def get_absolute_url(self):
#         if self.group is None:
#             return reverse('wiki_article', args=(self.title,))
#         return self.group.get_absolute_url() + 'wiki/' + self.title
# 
#     def save(self, force_insert=False, force_update=False):
#         self.last_update = datetime.now()
#         super(Article, self).save(force_insert, force_update)
# 
#     def remove(self):
#         """ Mark the Article as 'removed'. If the article is
#         already removed, delete it.
#         Returns True if the article was deleted, False when just marked
#         as removed.
#         """
#         if self.removed:
#             self.delete()
#             return True
#         else:
#             self.removed = True
#             self.save()
#             return False
# 
#     def latest_changeset(self):
#         try:
#             return self.changeset_set.filter(
#                 reverted=False).order_by('-revision')[0]
#         except IndexError:
#             return ChangeSet.objects.none()
# 
#     def new_revision(self, old_content, old_title, old_markup,
#                      comment, editor_ip, editor):
#         '''Create a new ChangeSet with the old content.'''
# 
#         content_diff = diff(self.content, old_content)
# 
#         cs = ChangeSet.objects.create(
#             article=self,
#             comment=comment,
#             editor_ip=editor_ip,
#             editor=editor,
#             old_title=old_title,
#             old_markup=old_markup,
#             content_diff=content_diff)
# 
#         if None not in (notification, self.creator):
#             if editor is None:
#                 editor = editor_ip
#             notification.send([self.creator], "wiki_article_edited",
#                               {'article': self, 'user': editor})
# 
#         return cs
# 
#     def revert_to(self, revision, editor_ip, editor=None):
#         """ Revert the article to a previuos state, by revision number.
#         """
#         changeset = self.changeset_set.get(revision=revision)
#         changeset.reapply(editor_ip, editor)
# 
# 
#     def __unicode__(self):
#         return self.title


# Path: wiki/forms.py
import re
from django import forms
from django.forms import widgets
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.utils.translation import ugettext_lazy as _
from wiki.models import Article

# -*- coding: utf-8 -*-



try:
    WIKI_WORD_RE = settings.WIKI_WORD_RE
except AttributeError:
    WIKI_WORD_RE = r'(?:[A-Z]+[a-z]+){2,}'


wikiword_pattern = re.compile('^' + WIKI_WORD_RE + '$')


class ArticleForm(forms.ModelForm):

    summary = forms.CharField(widget=forms.Textarea)

    comment = forms.CharField(required=False)
    user_ip = forms.CharField(widget=forms.HiddenInput)

    content_type = forms.ModelChoiceField(
        queryset=ContentType.objects.all(),
        required=False,
        widget=forms.HiddenInput)
    object_id = forms.IntegerField(required=False,
                                   widget=forms.HiddenInput)

    action = forms.CharField(widget=forms.HiddenInput)

    class Meta:

        model = Article