Merge commit '17b531e181e691055797ec95a030c399f4dbcb8f' into develop
This commit is contained in:
commit
ce91a19068
@ -15,9 +15,24 @@ from lostplaces.forms import ExplorerCreationForm, ExplorerChangeForm
|
||||
class VoucherAdmin(admin.ModelAdmin):
|
||||
fields = ['code', 'expires_when', 'created_when']
|
||||
readonly_fields = ['created_when']
|
||||
list_display = ('__str__', 'code', 'created_when', 'expires_when', 'valid')
|
||||
|
||||
def valid(self, instance):
|
||||
return timezone.now() <= instance.expires_when
|
||||
|
||||
valid.boolean = True
|
||||
|
||||
class PhotoAlbumsAdmin(admin.ModelAdmin):
|
||||
list_display = ('label', 'place', 'url' )
|
||||
|
||||
class PlacesAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'submitted_by', 'submitted_when')
|
||||
|
||||
class PlaceImagesAdmin(admin.ModelAdmin):
|
||||
list_display = ('__str__', 'place', 'submitted_by')
|
||||
|
||||
admin.site.register(Explorer)
|
||||
admin.site.register(Voucher, VoucherAdmin)
|
||||
admin.site.register(Place)
|
||||
admin.site.register(PlaceImage)
|
||||
admin.site.register(PhotoAlbum)
|
||||
admin.site.register(Place, PlacesAdmin)
|
||||
admin.site.register(PlaceImage, PlaceImagesAdmin)
|
||||
admin.site.register(PhotoAlbum, PhotoAlbumsAdmin)
|
||||
|
@ -26,6 +26,10 @@ class ExplorerCreationForm(UserCreationForm):
|
||||
self.add_error('voucher', 'Invalid voucher')
|
||||
return False
|
||||
|
||||
if not submitted_voucher.valid:
|
||||
self.add_error('voucher', 'Expired voucher')
|
||||
return False
|
||||
|
||||
fetched_voucher.delete()
|
||||
return True
|
||||
|
||||
|
@ -15,6 +15,7 @@ from django.contrib.auth.models import User
|
||||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
from django.core.validators import MaxValueValidator, MinValueValidator
|
||||
from django.utils import timezone
|
||||
from easy_thumbnails.fields import ThumbnailerImageField
|
||||
from easy_thumbnails.files import get_thumbnailer
|
||||
from taggit.managers import TaggableManager
|
||||
@ -106,8 +107,12 @@ class Voucher(models.Model):
|
||||
created_when = models.DateTimeField(auto_now_add=True)
|
||||
expires_when = models.DateTimeField()
|
||||
|
||||
@property
|
||||
def valid(self):
|
||||
return timezone.now() <= self.expires_when
|
||||
|
||||
def __str__(self):
|
||||
return "Voucher " + str(self.code)
|
||||
return "Voucher " + str(self.pk)
|
||||
|
||||
|
||||
class Place(Submittable, Taggable, Mapable):
|
||||
@ -176,7 +181,7 @@ class PlaceImage (Submittable):
|
||||
of this image as textual represntation of this instance
|
||||
"""
|
||||
|
||||
return ' '.join([self.place.name, str(self.pk)])
|
||||
return 'Image ' + str(self.pk)
|
||||
|
||||
|
||||
# These two auto-delete files from filesystem when they are unneeded:
|
||||
|
@ -83,13 +83,6 @@ class PlaceImageTestCase(ModelTestCase):
|
||||
)
|
||||
)
|
||||
|
||||
def test_str(self):
|
||||
self.assertTrue(self.place_image.place.name.lower() in str(self.place_image).lower(),
|
||||
msg='Expecting %s.__str__ to contain the name of the place' % (
|
||||
self.model.__name__
|
||||
)
|
||||
)
|
||||
|
||||
def test_change_filename(self):
|
||||
path = self.place_image.filename.path
|
||||
self.place_image.filename = os.path.join(settings.MEDIA_ROOT, 'im_a_image_changed.jpeg')
|
||||
|
@ -42,11 +42,3 @@ class VoucheTestCase(ModelTestCase):
|
||||
field_class=models.DateTimeField,
|
||||
must_not_have={'auto_now_add': True}
|
||||
)
|
||||
|
||||
def test_str(self):
|
||||
self.assertTrue(
|
||||
self.voucher.code.lower() in str(self.voucher).lower(),
|
||||
msg='Expecting %s.__str__ to contain the voucher code' % (
|
||||
self.model.__name__
|
||||
)
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user