summaryrefslogtreecommitdiff
path: root/chimere/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'chimere/models.py')
-rw-r--r--chimere/models.py68
1 files changed, 54 insertions, 14 deletions
diff --git a/chimere/models.py b/chimere/models.py
index d0861a0..4c77211 100644
--- a/chimere/models.py
+++ b/chimere/models.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-# Copyright (C) 2008-2013 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
+# Copyright (C) 2008-2015 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as
@@ -41,11 +41,12 @@ from django.db.models.signals import post_save, pre_save, m2m_changed
from django.template import defaultfilters
from django.utils.translation import ugettext_lazy as _
-from chimere.widgets import PointField, RouteField, SelectMultipleField, \
- TextareaWidget, DatePickerWidget
+from chimere.widgets import HiddenPointChooserWidget, PointField, RouteField, \
+ SelectMultipleField, TextareaWidget, \
+ DatePickerWidget
from chimere.managers import BaseGeoManager
from chimere.utils import KMLManager, OSMManager, ShapefileManager, \
- GeoRSSManager, CSVManager
+ GeoRSSManager, CSVManager, HtmlXsltManager, XMLXsltManager
class Page(models.Model):
"""Simple extra pages
@@ -102,7 +103,7 @@ class News(models.Model):
available = models.BooleanField(_(u"Available"))
is_front_page = models.NullBooleanField(_(u"Is front page"), blank=True,
null=True)
- date = models.DateField(_(u"Date"), auto_now_add=True)
+ date = models.DateField(_(u"Date"))
content = models.TextField()
url = models.URLField(_(u"Url"), max_length=200, blank=True, null=True)
maps = SelectMultipleField('Map', verbose_name=_(u"Associated maps"),
@@ -277,9 +278,10 @@ class SubCategory(models.Model):
return subcategories
@classmethod
- def getAvailableTuples(cls, map_name=None):
+ def getAvailableTuples(cls, item_types=None, map_name=None):
cats = []
- for cat, subcats in cls.getAvailable(map_name=map_name):
+ for cat, subcats in cls.getAvailable(item_types=item_types,
+ map_name=map_name):
cats.append((unicode(cat),
[(subcat.pk, subcat.name) for subcat in subcats]))
return cats
@@ -306,14 +308,18 @@ IMPORTERS = {'KML':KMLManager,
'OSM':OSMManager,
'SHP':ShapefileManager,
'RSS':GeoRSSManager,
- 'CSV':CSVManager
+ 'CSV':CSVManager,
+ 'XSLT':HtmlXsltManager,
+ 'XXLT':XMLXsltManager
}
IMPORTER_CHOICES = (('KML', 'KML'),
('OSM', 'OSM'),
('SHP', 'Shapefile'),
('RSS', 'GeoRSS'),
- ('CSV', 'CSV')
+ ('CSV', 'CSV'),
+ ('XSLT', 'HTML-XSLT'),
+ ('XXLT', 'XML-XSLT'),
)
IMPORTER_CHOICES_DICT = dict(IMPORTER_CHOICES)
@@ -327,9 +333,12 @@ class Importer(models.Model):
filtr = models.CharField(_(u"Filter"), max_length=200,
blank=True, null=True)
source = models.CharField(_(u"Web address"), max_length=200,
- blank=True, null=True)
+ blank=True, null=True,
+ help_text=_(u"Don't forget the trailing slash"))
source_file = models.FileField(_(u"Source file"),
upload_to='import_files', blank=True, null=True)
+ source_file_alt = models.FileField(_(u"Alt source file"),
+ upload_to='import_files', blank=True, null=True)
default_name = models.CharField(_(u"Name by default"), max_length=200,
blank=True, null=True)
srid = models.IntegerField(_(u"SRID"), blank=True, null=True)
@@ -344,12 +353,17 @@ class Importer(models.Model):
blank=True, null=True)
license = models.CharField(_(u"License"), max_length=100,
blank=True, null=True)
- categories = SelectMultipleField(SubCategory,
+ categories = SelectMultipleField(SubCategory, blank=True, null=True,
verbose_name=_(u"Associated subcategories"))
- state = models.CharField(_(u"State"), max_length=200,
- blank=True, null=True)
+ state = models.TextField(_(u"State"), blank=True, null=True)
associate_marker_to_way = models.BooleanField(_(u"Automatically associate "\
u"a marker to a way"), default=False)
+ automatic_update = models.BooleanField(_(u"Automatically updated"),
+ default=False)
+ default_localisation = PointField(_(u"Default localisation"),
+ srid=settings.CHIMERE_EPSG_DISPLAY_PROJECTION,
+ blank=True, null=True,
+ widget=HiddenPointChooserWidget)
class Meta:
verbose_name = _(u"Importer")
@@ -369,6 +383,31 @@ class Importer(models.Model):
def display_categories(self):
return u"\n".join([cat.name for cat in self.categories.all()])
+ def get_key_category_dict(self):
+ dct = {}
+ # if no category provided: all category are considered
+ q = SubCategory.objects.all()
+ if self.categories.count():
+ q = self.categories.all()
+ for cat in q.all():
+ dct[defaultfilters.slugify(cat.name)] = cat
+
+ for key_cat in self.key_categories.all():
+ dct[key_cat.key] = key_cat.category
+ return dct
+
+class ImporterKeyCategories(models.Model):
+ """
+ Association between key and categories
+ """
+ importer = models.ForeignKey(Importer, verbose_name=_(u"Importer"),
+ related_name='key_categories')
+ category = models.ForeignKey(SubCategory, verbose_name=_(u"Category"))
+ key = models.CharField(_(u"Import key"), max_length=200)
+
+ class Meta:
+ verbose_name = _(u"Importer - Key categories")
+
STATUS = (('S', _(u'Submited')),
('A', _(u'Available')),
('M', _(u'Modified')),
@@ -690,7 +729,7 @@ class Marker(GeographicItem):
def default_category(self):
# Should we select only available ones ?
# Should we catch if not exists ?
- cats = self.categories
+ cats = self.categories.filter(available=True, category__available=True)
if cats.count():
return cats.all()[0]
@@ -1653,6 +1692,7 @@ class PropertyModel(models.Model):
('D', _("Date")),
('B', _("Boolean")),
('C', _("Choices")),
+ ('B', _("Boolean")),
)
TYPE_WIDGET = {'T':forms.TextInput,
'L':TextareaWidget,