diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/media/admin.py | 23 | ||||
-rw-r--r-- | app/media/models.py | 6 |
2 files changed, 26 insertions, 3 deletions
diff --git a/app/media/admin.py b/app/media/admin.py index 9278c56..305ebd7 100644 --- a/app/media/admin.py +++ b/app/media/admin.py @@ -38,13 +38,30 @@ class LuxImageAdmin(OSMGeoAdmin): fieldsets = ( (None, { - 'fields': ('title', ('image'), 'pub_date', 'sizes', 'alt', 'caption', 'point', ('is_public'), ('photo_credit_source', 'photo_credit_url')) + 'fields': ( + 'image', + 'alt', + 'sizes', + 'caption', + 'pub_date', + 'title', + ) }), - ('Exif Data', { + ('Exif and Other Data', { 'classes': ('collapse',), - 'fields': ('exif_raw', 'exif_aperture', 'exif_make', 'exif_model', 'exif_exposure', 'exif_iso', 'exif_focal_length', 'exif_lens', 'exif_date', 'height', 'width'), + 'fields': ( + 'point', + ('is_public'), + ('photo_credit_source', 'photo_credit_url'), + 'exif_raw', 'exif_aperture', 'exif_make', 'exif_model', 'exif_exposure', 'exif_iso', 'exif_focal_length', 'exif_lens', 'exif_date', 'height', 'width'), }), ) + def save_related(self, request, form, formsets, change): + super(LuxImageAdmin, self).save_related(request, form, formsets, change) + if not form.instance.sizes.all(): + print("there are no sizes") + form.instance.sizes.add(*LuxImageSize.objects.filter(slug__in=["picwide-sm", "picwide-med", "picwide"])) + class Media: js = ('image-preview.js', 'next-prev-links.js') diff --git a/app/media/models.py b/app/media/models.py index d7b79c6..c266c4f 100644 --- a/app/media/models.py +++ b/app/media/models.py @@ -207,6 +207,12 @@ class LuxImage(models.Model): created = self.pk is None if not created: self.sizes_cache = ",".join(s.slug for s in self.sizes.all()) + if not self.point: + self.point = LuxImage.objects.latest().point + try: + self.location = Location.objects.filter(geometry__contains=self.point).get() + except Location.DoesNotExist: + raise forms.ValidationError("There is no location associated with that point, add it: %sadmin/locations/location/add/" % (settings.BASE_URL)) super(LuxImage, self).save() |