Ejemplo n.º 1
0
                if obj.__class__.objects.filter(**obj_lookup):
                    continue
                obj.slug = new_p.slug
                obj.pk = None  # Reset the primary key before saving.
                obj.save(comment="Parent page renamed")


class PageDiff(diff.BaseModelDiff):
    fields = (
        'name',
        ('content', diff.diffutils.HtmlFieldDiff),
    )


diff.register(Page, PageDiff)
versioning.register(Page)


class PageFile(models.Model):
    file = models.FileField(upload_to='pages/files/',
                            storage=RandomFilenameFileSystemStorage())
    name = models.CharField(max_length=255)
    slug = models.SlugField(max_length=255, editable=False)

    _rough_type_map = [(r'^audio', 'audio'), (r'^video', 'video'),
                       (r'^application/pdf', 'pdf'),
                       (r'^application/msword', 'word'),
                       (r'^text/html', 'html'), (r'^text', 'text'),
                       (r'^image', 'image'),
                       (r'^application/vnd.ms-powerpoint', 'powerpoint'),
                       (r'^application/vnd.ms-excel', 'excel')]
Ejemplo n.º 2
0
from versionutils import versioning

"""
TODO: It would be cool to write a little thing to randomly generate
model definitions for tests.
"""


class M1(models.Model):
    a = models.CharField(max_length=200)
    b = models.CharField(max_length=200)
    c = models.CharField(max_length=200)
    d = models.CharField(max_length=200)

versioning.register(M1)


class M2(models.Model):
    a = models.CharField(max_length=200)
    b = models.TextField()
    c = models.IntegerField()

versioning.register(M2)


class M3BigInteger(models.Model):
    a = models.CharField(max_length=200)
    b = models.BooleanField(default=False)
    c = models.BigIntegerField()
Ejemplo n.º 3
0
from django.core.urlresolvers import reverse

from pages.models import Page
from versionutils import versioning

import exceptions


class Redirect(models.Model):
    source = models.SlugField(max_length=255, unique=True, editable=False)
    destination = models.ForeignKey(Page)

    def __unicode__(self):
        return "%s ---> %s" % (self.source, self.destination)

    def get_absolute_url(self):
        return reverse('pages:show', args=[self.source])


versioning.register(Redirect)


def _validate_redirect(sender, instance, raw, **kws):
    if instance.source == instance.destination.slug:
            raise exceptions.RedirectToSelf(
                    _("You cannot redirect a page to itself"))

pre_save.connect(_validate_redirect, sender=Redirect)

import feeds # To fire register() calls.
Ejemplo n.º 4
0
class Diff_M2(models.Model):
    a = models.FileField(upload_to='test_diff_uploads')


class Diff_M3(models.Model):
    a = models.ImageField(upload_to='test_diff_uploads')


class Diff_M4ForeignKey(models.Model):
    a = models.ForeignKey('Diff_M1')


class Diff_M5Versioned(models.Model):
    a = models.CharField(max_length=200)

versioning.register(Diff_M5Versioned)


class FakeFieldModel(models.Model):
    a = models.CharField(max_length=200)

    def b(self):
        return 'a is ' + self.a
    b = property(b)


class FakeFieldModelDiff(diff.BaseModelDiff):
    fields = (('b', diff.TextFieldDiff),)


TEST_MODELS = [
Ejemplo n.º 5
0
from django.contrib.auth.models import User

from follow.utils import register as register_follow
from follow.models import Follow

from versionutils import versioning 
from regions.models import Region
from pages.models import Page


# Register models with follow app
register_follow(User)
register_follow(Page)
register_follow(Region)

# Version the Follow model
versioning.register(Follow)

# Fire signals
import signals
Ejemplo n.º 6
0
    polys = models.MultiPolygonField(null=True, blank=True)
    geom = FlatCollectionFrom(points='points', lines='lines', polys='polys')
    length = models.FloatField(null=True, editable=False)

    page = models.OneToOneField('pages.Page')

    objects = models.GeoManager()

    def get_absolute_url(self):
        return reverse('maps:show', args=[self.page.pretty_slug])

    def save(self, *args, **kwargs):
        self.length = self.geom.length
        super(MapData, self).save(*args, **kwargs)

    def exists(self):
        """
        Returns:
            True if the MapData currently exists in the database.
        """
        if MapData.objects.filter(page=self.page):
            return True
        return False


versioning.register(MapData)

# For registration calls
import api
import feeds
Ejemplo n.º 7
0
        self.name = strip_tags(self.name)
        self.slug = slugify(self.name)
        if not self.slug:
            raise IntegrityError('Invalid tag name: %s' % self.name)
        super(Tag, self).save(*args, **kwargs)

    def get_absolute_url(self):
        return reverse('tags:tagged', kwargs={'region': self.region.slug, 'slug':self.slug})

    class Meta:
        unique_together = ('slug', 'region')
        ordering = ('slug',)
        verbose_name = _(u'Tag')
        verbose_name_plural = _(u'Tags')

versioning.register(Tag)


def slugify(value):
    # normalize unicode
    import unicodedata
    value = unicodedata.normalize('NFKD', unicode(value))
    # remove non-word characters
    misc_characters = re.compile(('[^\w]'), re.UNICODE)
    value = re.sub(misc_characters, '', value)
    return value.lower()
slugify = stringfilter(slugify)


class PageTagSet(models.Model):
    page = models.OneToOneField('pages.Page')
Ejemplo n.º 8
0
                obj_lookup = _get_slug_lookup(unique_together, obj, new_p)
                if obj.__class__.objects.filter(**obj_lookup):
                    continue
                obj.slug = new_p.slug
                obj.pk = None  # Reset the primary key before saving.
                obj.save(comment="Parent page renamed")


class PageDiff(diff.BaseModelDiff):
    fields = ('name',
              ('content', diff.diffutils.HtmlFieldDiff),
             )


diff.register(Page, PageDiff)
versioning.register(Page)


class PageFile(models.Model):
    file = models.FileField(upload_to='pages/files/',
                            storage=RandomFilenameFileSystemStorage())
    name = models.CharField(max_length=255)
    slug = models.SlugField(max_length=255, editable=False)

    _rough_type_map = [(r'^audio', 'audio'),
                       (r'^video', 'video'),
                       (r'^application/pdf', 'pdf'),
                       (r'^application/msword', 'word'),
                       (r'^text/html', 'html'),
                       (r'^text', 'text'),
                       (r'^image', 'image'),
Ejemplo n.º 9
0
class MapData(models.Model):
    points = models.MultiPointField(null=True, blank=True)
    lines = models.MultiLineStringField(null=True, blank=True)
    polys = models.MultiPolygonField(null=True, blank=True)
    geom = FlatCollectionFrom(points='points', lines='lines', polys='polys')
    length = models.FloatField(null=True, editable=False)

    page = models.OneToOneField(Page)

    objects = models.GeoManager()

    def get_absolute_url(self):
        return reverse('maps:show', args=[self.page.pretty_slug])

    def save(self, *args, **kwargs):
        self.length = self.geom.length
        super(MapData, self).save(*args, **kwargs)

    def exists(self):
        """
        Returns:
            True if the MapData currently exists in the database.
        """
        if MapData.objects.filter(page=self.page):
            return True
        return False

versioning.register(MapData)

import feeds # To fire register() calls.
Ejemplo n.º 10
0
from pages.models import Page
from versionutils import versioning

import exceptions


class Redirect(models.Model):
    source = models.SlugField(max_length=255, unique=True, editable=False)
    destination = models.ForeignKey(Page)

    def __unicode__(self):
        return "%s ---> %s" % (self.source, self.destination)

    def get_absolute_url(self):
        return reverse('pages:show', args=[self.source])


versioning.register(Redirect)


def _validate_redirect(sender, instance, raw, **kws):
    if instance.source == instance.destination.slug:
        raise exceptions.RedirectToSelf(
            _("You cannot redirect a page to itself"))


pre_save.connect(_validate_redirect, sender=Redirect)

import feeds  # To fire register() calls.
Ejemplo n.º 11
0
from versionutils import versioning

"""
TODO: It would be cool to write a little thing to randomly generate
model definitions for tests.
"""


class M1(models.Model):
    a = models.CharField(max_length=200)
    b = models.CharField(max_length=200)
    c = models.CharField(max_length=200)
    d = models.CharField(max_length=200)

versioning.register(M1)


class M2(models.Model):
    a = models.CharField(max_length=200)
    b = models.TextField()
    c = models.IntegerField()

versioning.register(M2)


class M3BigInteger(models.Model):
    a = models.CharField(max_length=200)
    b = models.BooleanField(default=False)
    c = models.BigIntegerField()
Ejemplo n.º 12
0
    a = models.FileField(upload_to='test_diff_uploads')


class Diff_M3(models.Model):
    a = models.ImageField(upload_to='test_diff_uploads')


class Diff_M4ForeignKey(models.Model):
    a = models.ForeignKey('Diff_M1')


class Diff_M5Versioned(models.Model):
    a = models.CharField(max_length=200)


versioning.register(Diff_M5Versioned)


class FakeFieldModel(models.Model):
    a = models.CharField(max_length=200)

    def b(self):
        return 'a is ' + self.a

    b = property(b)


class FakeFieldModelDiff(diff.BaseModelDiff):
    fields = (('b', diff.TextFieldDiff), )