diff options
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r-- | ishtar_common/models.py | 79 |
1 files changed, 60 insertions, 19 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 35608abdf..988254359 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -191,6 +191,8 @@ def valid_ids(cls): def func(value): if "," in value: value = value.split(",") + if type(value) not in (list, tuple): + value = [value] for v in value: try: cls.objects.get(pk=v) @@ -411,7 +413,7 @@ class GeneralType(Cached, models.Model): if item: return item item, created = cls.objects.get_or_create( - txt_idx=slug, defaults={'label': label}) + txt_idx=slug, defaults={'label': label}) return item @classmethod @@ -769,6 +771,10 @@ class ImageModel(models.Model): return SimpleUploadedFile('temp', temp.read()) def save(self, *args, **kwargs): + if 'force_copy' in kwargs: + kwargs.pop('force_copy') + super(ImageModel, self).save(*args, **kwargs) + return # manage images if self.has_changed('image') and self.image: # convert to jpg @@ -1300,6 +1306,19 @@ class UserDashboard: class DashboardFormItem(object): + """ + Provide methods to manage statistics + """ + + def _get_or_set_stats(self, funcname, update, + timeout=settings.CACHE_TIMEOUT): + key, val = get_cache(self.__class__, [funcname, self.pk]) + if not update and val is not None: + return val + val = getattr(self, funcname)() + cache.set(key, val, timeout) + return val + @classmethod def get_periods(cls, slice='month', fltr={}, date_source='creation'): date_var = date_source + '_date' @@ -1951,7 +1970,8 @@ class ImporterColumn(models.Model): """ Import file column description """ - label = models.CharField(_(u"Label"), blank=True, null=True, max_length=200) + label = models.CharField(_(u"Label"), blank=True, null=True, + max_length=200) importer_type = models.ForeignKey(ImporterType, related_name='columns') col_number = models.IntegerField(_(u"Column number"), default=1) description = models.TextField(_("Description"), blank=True, null=True) @@ -2141,7 +2161,8 @@ TARGET_MODELS = [ ('archaeological_operations.models.ReportState', _(u"Report state")), ('archaeological_operations.models.RemainType', _(u"Remain type")), ('archaeological_context_records.models.Unit', _(u"Unit")), - ('archaeological_context_records.models.ActivityType', _(u"Activity type")), + ('archaeological_context_records.models.ActivityType', + _(u"Activity type")), ('archaeological_finds.models.MaterialType', _(u"Material")), ('archaeological_finds.models.ConservatoryState', _(u"Conservatory state")), @@ -2149,7 +2170,8 @@ TARGET_MODELS = [ ('archaeological_finds.models.PreservationType', _(u"Preservation type")), ('archaeological_finds.models.ObjectType', _(u"Object type")), ('archaeological_finds.models.IntegrityType', _(u"Integrity type")), - ('archaeological_finds.models.RemarkabilityType', _(u"Remarkability type")), + ('archaeological_finds.models.RemarkabilityType', + _(u"Remarkability type")), ('archaeological_finds.models.BatchType', _(u"Batch type")), ('archaeological_context_records.models.IdentificationType', _("Identification type")), @@ -2301,14 +2323,12 @@ class Import(models.Model): conservative_import = models.BooleanField( _(u"Conservative import"), default=False, help_text='If set to true, do not overload existing values') - creation_date = models.DateTimeField(_(u"Creation date"), - auto_now_add=True, blank=True, - null=True) + creation_date = models.DateTimeField( + _(u"Creation date"), auto_now_add=True, blank=True, null=True) end_date = models.DateTimeField(_(u"End date"), blank=True, null=True, editable=False) - seconds_remaining = models.IntegerField(_(u"Remaining seconds"), - blank=True, null=True, - editable=False) + seconds_remaining = models.IntegerField( + _(u"Remaining seconds"), blank=True, null=True, editable=False) class Meta: verbose_name = _(u"Import") @@ -2770,6 +2790,18 @@ class Person(Address, Merge, OwnPerms, ValueGetter): for fle in self.general_contractor.all(): fle.save() # force update of raw_general_contractor + @classmethod + def get_query_owns(cls, user): + return \ + Q(operation_scientist_responsability__collaborators__ishtaruser + =user.ishtaruser) | \ + Q(operation_scientist_responsability__scientist__ishtaruser + =user.ishtaruser) | \ + Q(operation_collaborator__collaborators__ishtaruser + =user.ishtaruser) | \ + Q(operation_collaborator__scientist__ishtaruser + =user.ishtaruser) + class IshtarUser(User): TABLE_COLS = ('username', 'person__name', 'person__surname', @@ -2803,17 +2835,13 @@ class IshtarUser(User): surname = user.first_name or default name = user.last_name or default email = user.email - if user.is_superuser: - ADMINISTRATOR, created = PersonType.objects.get_or_create( - txt_idx='administrator') - person_type = ADMINISTRATOR - else: - person_type, created = PersonType.objects.get_or_create( - txt_idx='public_access') person = Person.objects.create(surname=surname, name=name, email=email, history_modifier=user) - person.person_types.add(person_type) + if user.is_superuser: + person_type, created = PersonType.objects.get_or_create( + txt_idx='administrator') + person.person_types.add(person_type) password = user.password isht_user = IshtarUser.objects.create( user_ptr=user, username=default, person=person, password=password) @@ -2844,6 +2872,7 @@ IshtarUser._meta.get_field('password').help_text = _( class AuthorType(GeneralType): order = models.IntegerField(_(u"Order"), default=1) + class Meta: verbose_name = _(u"Author type") verbose_name_plural = _(u"Author types") @@ -2861,6 +2890,18 @@ class Author(models.Model): verbose_name = _(u"Author") verbose_name_plural = _(u"Authors") ordering = ('author_type__order', 'person__name') + permissions = ( + ("view_author", + ugettext(u"Can view all Authors")), + ("view_own_author", + ugettext(u"Can view own Author")), + ("add_own_author", + ugettext(u"Can add own Author")), + ("change_own_author", + ugettext(u"Can change own Author")), + ("delete_own_author", + ugettext(u"Can delete own Author")), + ) def __unicode__(self): return unicode(self.person) + settings.JOINT + \ @@ -2903,7 +2944,7 @@ post_save.connect(post_save_cache, sender=Format) post_delete.connect(post_save_cache, sender=Format) -class Source(ImageModel, models.Model): +class Source(OwnPerms, ImageModel, models.Model): title = models.CharField(_(u"Title"), max_length=300) external_id = models.CharField(_(u"External ID"), max_length=12, null=True, blank=True) |