How to use the routemap.util.customfields function in routemap

To help you get started, we’ve selected a few routemap 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 waymarkedtrails / waymarked-trails-site / django / src / routemap / sites / models.py View on Github external
from django.contrib.gis.db import models
import routemap.util.customfields as cfields
from django.db import connection, transaction
from django.conf import settings

from osgende.tags import TagStore

class RouteTableModel(models.Model):
    """Generalized model for table with route information.
    """

    # only the fields required by the generalized functions
    # are added here
    id = cfields.BigIntegerField(primary_key=True)
    name = models.TextField(null=True)
    intnames = cfields.HStoreField()
    geom = models.GeometryField(srid=settings.DATABASES['default']['SRID'])

    def tags(self):
        if not hasattr(self,'_tags'):
            cursor = connection.cursor()
            cursor.execute("SELECT tags FROM relations WHERE id = %s", (self.id,))
            ret = cursor.fetchone()
            self._tags = TagStore(ret[0] if ret is not None else {})
        return self._tags

    def localize_name(self, locstrings):
        for locstring in locstrings:
            if locstring in self.intnames:
                if not self.name == self.intnames[locstring]:
                    self.origname = self.name
                    self.name = self.intnames[locstring]