# coding: utf-8 from django.conf import settings from django.contrib.auth import get_user_model from django.contrib.contenttypes.models import ContentType from django.dispatch import receiver from django.db.models.signals import post_save, post_delete from mutant.contrib.file.models import FilePathFieldDefinition from mutant.contrib.related.models import ForeignKeyDefinition from mutant.contrib.boolean.models import BooleanFieldDefinition from userlayers import get_modeldefinition_model from userlayers.models import ModelDef as MD ModelDef = get_modeldefinition_model() @receiver(post_save, sender=MD, dispatch_uid='registreator') def post_change(*args, **kwargs): wow = { 'image': {'type': ModelDef.RESOURCE_TYPE_CHOICES_IMAGE, 'name': u'Изображение', 'name_plural': u'Изображения'}, 'video': {'type': ModelDef.RESOURCE_TYPE_CHOICES_VIDEO, 'name': u'Видео', 'name_plural': u'Видео'}, } instance = kwargs.get('instance') if instance.name in wow or instance.hidden: return if kwargs.get('created', None): ForeignKeyDefinition( name='user', model_def_id=instance.contenttype_ptr_id, related_name='%ss' % instance.name, to_id=ContentType.objects.get_for_model(get_user_model()).id, verbose_name=u'владелец').save() BooleanFieldDefinition( name='is_onmap', model_def_id=instance.contenttype_ptr_id, default=False, verbose_name=u'помещен на карту').save()
# coding: utf-8 from django.conf import settings from django.db.models.fields import FilePathField from userlayers import get_modeldefinition_model from registrator.contrib.fix_exif import fix_exif try: for md in get_modeldefinition_model().objects.all(): model = md.model_class() def save(self, *args, **kwargs): super(self.__class__, self).save(*args, **kwargs) for field in self.__class__._meta.fields: if isinstance(field, FilePathField): filepath = ('%s/%s' % (settings.MEDIA_ROOT, getattr( self, field.name))).replace('//', '/') fix_exif(filepath) model.save = save except: pass