summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_context_records/models.py34
-rw-r--r--archaeological_files/models.py27
-rw-r--r--archaeological_finds/models.py57
-rw-r--r--archaeological_operations/models.py32
-rw-r--r--ishtar_common/models.py29
-rw-r--r--ishtar_common/views.py4
6 files changed, 146 insertions, 37 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index 57c95c3b6..45da5935c 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-# Copyright (C) 2012 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
+# Copyright (C) 2012-2013 É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 Affero General Public License as
@@ -19,7 +19,7 @@
from django.conf import settings
from django.contrib.gis.db import models
-from django.utils.translation import ugettext_lazy as _, ugettext
+from django.utils.translation import ugettext_lazy as _, ugettext, pgettext
from ishtar_common.models import GeneralType, BaseHistorizedItem, \
HistoricalRecords, OwnPerms, Town, Person, Source
@@ -133,13 +133,17 @@ class ContextRecord(BaseHistorizedItem, OwnPerms):
verbose_name = _(u"Context Record")
verbose_name_plural = _(u"Context Record")
permissions = (
- ("view_contextrecord", ugettext(u"Can view all Context Record")),
- ("view_own_contextrecord", ugettext(u"Can view own Context Record")),
- ("add_own_contextrecord", ugettext(u"Can add own Context Record")),
- ("change_own_contextrecord", ugettext(u"Can change own Context Record")),
- ("delete_own_contextrecord", ugettext(u"Can delete own Context Record")),
+ ("view_contextrecord", ugettext(u"Can view all Context Record")),
+ ("view_own_contextrecord", ugettext(u"Can view own Context Record")),
+ ("add_own_contextrecord", ugettext(u"Can add own Context Record")),
+ ("change_own_contextrecord", ugettext(u"Can change own Context Record")),
+ ("delete_own_contextrecord", ugettext(u"Can delete own Context Record")),
)
+ @property
+ def short_class_name(self):
+ return pgettext("short", u"Context record")
+
def __unicode__(self):
return self.short_label()
@@ -166,6 +170,22 @@ class ContextRecord(BaseHistorizedItem, OwnPerms):
self.operation.operation_code,
self.label] if lbl])
+ @property
+ def reference(self):
+ if not self.operation:
+ return "00"
+ return self.full_label()
+
+ def get_department(self):
+ if not self.operation:
+ return "00"
+ return self.operation.get_department()
+
+ def get_town_label(self):
+ if not self.operation:
+ return "00"
+ return self.operation.get_town_label()
+
@classmethod
def get_years(cls):
years = set()
diff --git a/archaeological_files/models.py b/archaeological_files/models.py
index 30c060789..a6900ec08 100644
--- a/archaeological_files/models.py
+++ b/archaeological_files/models.py
@@ -119,6 +119,10 @@ class File(BaseHistorizedItem, OwnPerms):
)
ordering = ['-year', '-numeric_reference']
+ @property
+ def short_class_name(self):
+ return _(u"FILE")
+
@classmethod
def get_years(cls):
return [res['year'] for res in list(cls.objects.values('year').annotate(
@@ -138,12 +142,13 @@ class File(BaseHistorizedItem, OwnPerms):
self.save()
return self.cached_label
+ @property
+ def reference(self):
+ return u"-".join((unicode(self.year),
+ unicode(self.numeric_reference or '0')))
+
def _generate_cached_label(self):
- items = [unicode(_('Intercommunal'))]
- if self.towns.count() == 1:
- items[0] = unicode(self.towns.all()[0])
- items.append("-".join((unicode(self.year),
- unicode(self.numeric_reference or '0'))))
+ items = [self.get_town_label(), self.reference]
items += [unicode(getattr(self, k))
for k in ['internal_reference', 'name'] if getattr(self, k)]
return settings.JOINT.join(items)
@@ -152,6 +157,18 @@ class File(BaseHistorizedItem, OwnPerms):
from archaeological_operations.models import Parcel
return Parcel.grouped_parcels(list(self.parcels.all()))
+ def get_town_label(self):
+ lbl = unicode(_('Intercommunal'))
+ if self.towns.count() == 1:
+ lbl = self.towns.all()[0].name
+ return lbl
+
+ def get_department(self):
+ q = self.towns
+ if not self.towns.count():
+ return '00'
+ return self.towns.all()[0].numero_insee[:2]
+
@classmethod
def get_query_owns(cls, user):
return Q(history_modifier=user) & Q(end_date__isnull=True)
diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py
index e047e21cf..84a041a41 100644
--- a/archaeological_finds/models.py
+++ b/archaeological_finds/models.py
@@ -167,6 +167,49 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms):
thumbnail = self._meta.get_field_by_name("thumbnail")[0]
thumbnail.upload_to = "finds/thumbs/"
+ class Meta:
+ verbose_name = _(u"Find")
+ verbose_name_plural = _(u"Finds")
+ permissions = (
+ ("view_find", ugettext(u"Can view all Find")),
+ ("view_own_find", ugettext(u"Can view own Find")),
+ ("add_own_find", ugettext(u"Can add own Find")),
+ ("change_own_find", ugettext(u"Can change own Find")),
+ ("delete_own_find", ugettext(u"Can delete own Find")),
+ )
+
+ @property
+ def short_class_name(self):
+ return _(u"FIND")
+
+ def __unicode__(self):
+ return self.label
+
+ def get_first_base_find(self):
+ q= self.base_finds
+ if not q.count():
+ return
+ return q.all()[0]
+
+ @property
+ def reference(self):
+ bf = self.get_first_base_find()
+ if not bf:
+ return "00"
+ return bf.short_id()
+
+ def get_department(self):
+ bf = self.get_first_base_find()
+ if not bf:
+ return "00"
+ return bf.context_record.operation.get_department()
+
+ def get_town_label(self):
+ bf = self.get_first_base_find()
+ if not bf:
+ return "00"
+ return bf.context_record.operation.get_town_label()
+
@classmethod
def get_years(cls):
years = set()
@@ -220,20 +263,6 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms):
new.base_finds.add(base_find)
return new
- class Meta:
- verbose_name = _(u"Find")
- verbose_name_plural = _(u"Finds")
- permissions = (
- ("view_find", ugettext(u"Can view all Find")),
- ("view_own_find", ugettext(u"Can view own Find")),
- ("add_own_find", ugettext(u"Can add own Find")),
- ("change_own_find", ugettext(u"Can change own Find")),
- ("delete_own_find", ugettext(u"Can delete own Find")),
- )
-
- def __unicode__(self):
- return self.label
-
def save(self, *args, **kwargs):
if not self.pk:
super(Find, self).save(*args, **kwargs)
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 9e2fc9b4c..83f4f47c6 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -148,18 +148,38 @@ class Operation(BaseHistorizedItem, OwnPerms):
self.save()
return self.cached_label
+ @property
+ def short_class_name(self):
+ return _(u"OPE")
+
+ @property
+ def reference(self):
+ if self.code_patriarche:
+ return unicode(self.code_patriarche)
+ if self.year and self.operation_code:
+ return u"-".join((unicode(self.year),
+ unicode(self.operation_code)))
+ return "00"
+
def _generate_cached_label(self):
- items = [unicode(_('Intercommunal'))]
- if self.towns.count() == 1:
- items[0] = unicode(self.towns.all()[0])
- if self.operation_code:
- items.append("-".join((unicode(self.year),
- unicode(self.operation_code))))
+ items = [self.get_town_label(), self.reference]
if self.common_name:
items.append(self.common_name)
cached_label = settings.JOINT.join(items)
return cached_label
+ def get_town_label(self):
+ lbl = unicode(_('Intercommunal'))
+ if self.towns.count() == 1:
+ lbl = self.towns.all()[0].name
+ return lbl
+
+ def get_department(self):
+ q = self.towns
+ if not self.towns.count():
+ return '00'
+ return self.towns.all()[0].numero_insee[:2]
+
def grouped_parcels(self):
return Parcel.grouped_parcels(list(self.parcels.all()))
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index fc4cdbd17..ac2661fe1 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -29,12 +29,13 @@ from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.core.files.uploadedfile import SimpleUploadedFile
from django.core.validators import validate_slug
-from django.utils.translation import ugettext_lazy as _, ugettext
-from django.utils.safestring import SafeUnicode, mark_safe
from django.core.urlresolvers import reverse, NoReverseMatch
from django.db.utils import DatabaseError
from django.db.models import Q, Max, Count
from django.db.models.signals import post_save
+from django.utils.translation import ugettext_lazy as _, ugettext
+from django.utils.safestring import SafeUnicode, mark_safe
+from django.template.defaultfilters import slugify
from django.contrib.auth.models import User
from django.contrib.gis.db import models
@@ -376,6 +377,13 @@ class BaseHistorizedItem(models.Model):
item.pk = self.pk
return item
+ @property
+ def last_edition_date(self):
+ try:
+ return self.history.order_by('-history_date').all()[0].history_date
+ except IndexError:
+ return
+
def rollback(self, date):
"""
Rollback to a previous state
@@ -417,6 +425,23 @@ class BaseHistorizedItem(models.Model):
except NoReverseMatch:
return
+ @property
+ def associated_filename(self):
+ if [True for attr in ('get_town_label', 'get_department', 'reference',
+ 'short_class_name') if not hasattr(self, attr)]:
+ print [True if hasattr(self, attr) else False for attr in ('get_town_label', 'get_department', 'reference',
+ 'short_class_name') ]
+ return ''
+ print "yata"
+ items = [self.get_department(), self.get_town_label(),
+ self.short_class_name, self.reference]
+ last_edition_date = self.last_edition_date
+ if last_edition_date:
+ items.append(last_edition_date.strftime('%Y%m%d'))
+ else:
+ items.append('00000000')
+ return slugify(u"-".join([unicode(item) for item in items]))
+
class LightHistorizedItem(BaseHistorizedItem):
history_date = models.DateTimeField(default=datetime.datetime.now)
class Meta:
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index 54d2e26a0..eda0be543 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -40,7 +40,6 @@ from django.db.models import Q
from django.http import HttpResponse, Http404
from django.shortcuts import render_to_response, redirect
from django.template import RequestContext, loader
-from django.template.defaultfilters import slugify
from django.utils.translation import ugettext, ugettext_lazy as _
if settings.XHTML2ODT_PATH:
@@ -391,8 +390,7 @@ def show_item(model, name):
context_instance = RequestContext(request)
context_instance.update(dct)
n = datetime.datetime.now()
- filename = u'%s_%s_%s' % (name, slugify(unicode(item)),
- n.strftime('%Y%m%d-%H%M%S'))
+ filename = item.associated_filename
if doc_type == "odt" and settings.XHTML2ODT_PATH and \
settings.ODT_TEMPLATE:
tpl = loader.get_template('ishtar/sheet_%s.html' % name)