summaryrefslogtreecommitdiff
path: root/ishtar_common/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r--ishtar_common/models.py50
1 files changed, 22 insertions, 28 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 12f286c61..7b596d209 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -1707,28 +1707,6 @@ IMPORTER_CLASSES.update({
'archaeological_files.data_importer.FileImporterSraPdL'})
-def get_importer_models():
- MODELS = [
- ('ishtar_common.models.Person', _(u"Person")),
- ('ishtar_common.models.Organization', _(u"Organization")),
- ('archaeological_operations.models.Operation', _(u"Operation")),
- ('archaeological_operations.models.ArchaeologicalSite',
- _(u"Archaeological site")),
- ('archaeological_operations.models.Parcel', _(u"Parcels")),
- ('archaeological_operations.models.OperationSource',
- _(u"Operation source")),
- ]
- MODELS = [('archaeological_files.models.File',
- _(u"Archaeological files"))] + MODELS
- MODELS = [('archaeological_context_records.models.ContextRecord',
- _(u"Context records")),
- ('archaeological_context_records.models.RecordRelations',
- _(u"Context record relations"))] + MODELS
- MODELS = [('archaeological_finds.models.BaseFind',
- _(u"Base finds")), ] + MODELS
- return MODELS
-
-
def get_model_fields(model):
"""
Return a dict of fields from model
@@ -1751,6 +1729,19 @@ def import_class(full_path_classname):
return getattr(module, mods[-1])
+class ImporterModel(models.Model):
+ name = models.CharField(_(u"Name"), max_length=200)
+ klass = models.CharField(_(u"Class name"), max_length=200)
+
+ class Meta:
+ verbose_name = _(u"Importer - Model")
+ verbose_name_plural = _(u"Importer - Models")
+ ordering = ('name',)
+
+ def __unicode__(self):
+ return self.name
+
+
class ImporterType(models.Model):
"""
Description of a table to be mapped with ishtar database
@@ -1763,9 +1754,13 @@ class ImporterType(models.Model):
max_length=500)
users = models.ManyToManyField('IshtarUser', verbose_name=_(u"Users"),
blank=True, null=True)
- associated_models = models.CharField(_(u"Associated model"),
- max_length=200,
- choices=get_importer_models())
+ associated_models = models.ForeignKey(
+ ImporterModel, verbose_name=_(u"Associated model"),
+ related_name='+', blank=True, null=True)
+ created_models = models.ManyToManyField(
+ ImporterModel, verbose_name=_(u"Models that can accept new items"),
+ blank=True, null=True, help_text=_(u"Leave blank for no restrictions"),
+ related_name='+')
is_template = models.BooleanField(_(u"Is template"), default=False)
unicity_keys = models.CharField(_(u"Unicity keys (separator \";\")"),
blank=True, null=True, max_length=500)
@@ -1781,7 +1776,7 @@ class ImporterType(models.Model):
if self.slug and self.slug in IMPORTER_CLASSES:
cls = import_class(IMPORTER_CLASSES[self.slug])
return cls
- OBJECT_CLS = import_class(self.associated_models)
+ OBJECT_CLS = import_class(self.associated_models.klass)
DEFAULTS = dict([(default.keys, default.values)
for default in self.defaults.all()])
LINE_FORMAT = []
@@ -1836,7 +1831,6 @@ class ImporterType(models.Model):
def get_associated_model(parent_model, keys):
model = None
- OBJECT_CLS = None
if isinstance(parent_model, unicode) or \
isinstance(parent_model, str):
OBJECT_CLS = import_class(parent_model)
@@ -1874,7 +1868,7 @@ class ImporterDefault(models.Model):
@property
def associated_model(self):
- return get_associated_model(self.importer_type.associated_models,
+ return get_associated_model(self.importer_type.associated_models.klass,
self.keys)
@property