How to use the regions.models.Region function in regions

To help you get started, we’ve selected a few regions examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github localwiki / localwiki-backend-server / localwiki / regions / tests.py View on Github external
def setUp(self):
        self.regions = []

        self.sf = Region(full_name="San Francisco", slug="sf")
        self.sf.save()
        self.oak = Region(full_name="Oakland", slug="oak")
        self.oak.save()

        self.philip = User(username="Philip", email="philip@example.org")
        self.philip.save()

        self.marina = User(username="Marina", email="marina@example.org")
        self.marina.save()

        # Philip admin of SF
        self.sf.regionsettings.admins.add(self.philip)

        # Marina admin of Oakland
        self.oak.regionsettings.admins.add(self.marina)
github localwiki / localwiki-backend-server / localwiki / regions / tests.py View on Github external
def setUp(self):
        self.regions = []

        self.sf = Region(full_name="San Francisco", slug="sf")
        self.sf.save()
        self.oak = Region(full_name="Oakland", slug="oak")
        self.oak.save()
github localwiki / localwiki-backend-server / localwiki / tags / models.py View on Github external
from django.contrib.gis.db import models
from django.db.utils import IntegrityError
from django.utils.encoding import smart_text
from django.template.defaultfilters import stringfilter
from django.utils.html import strip_tags
from django.utils.translation import ugettext_lazy as _

from regions.models import Region
from localwiki.utils.urlresolvers import reverse
from versionutils import versioning, diff


class Tag(models.Model):
    name = models.CharField(max_length=100, blank=False)
    slug = models.CharField(editable=False, max_length=100, blank=False, db_index=True)
    region = models.ForeignKey(Region, null=True)

    def __unicode__(self):
        return self.name

    def save(self, *args, **kwargs):
        self.name = smart_text(self.name)
        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:
github localwiki / localwiki-backend-server / localwiki / region_scores / models.py View on Github external
from celery import shared_task

from django.utils.translation import ugettext as _
from django.db import models
from django.db.models.signals import post_save

from regions.models import Region


class RegionScore(models.Model):
    """
    A score assigned to a region that, roughly speaking, represents its
    quality.
    """
    region = models.OneToOneField(Region, related_name='score')
    score = models.PositiveIntegerField()

    def __unicode__(self):
        return _("Region score %s: %s" % (self.region, self.score))


def normalize_score(score):
    if score > 10000:
       score = 10000
    elif score > 4000:
       score = 5000
    elif score > 1000:
       score = 1000
    elif score > 100:
       score = 100
    elif score > 50:
github localwiki / localwiki-backend-server / localwiki / cards / templatetags / cards_tags.py View on Github external
def show_card(context, obj):
    if isinstance(obj, Page):
        return render_page_card(context, obj)
    elif isinstance(obj, Region):
        return render_region_card(context, obj)