Compare commits

..

No commits in common. "ce91a19068761b086450dcfce8a645094f3c0958" and "815be3126e3aeec18272522150b5579391ca42ce" have entirely different histories.

5 changed files with 20 additions and 29 deletions

View File

@ -15,24 +15,9 @@ 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, PlacesAdmin)
admin.site.register(PlaceImage, PlaceImagesAdmin)
admin.site.register(PhotoAlbum, PhotoAlbumsAdmin)
admin.site.register(Place)
admin.site.register(PlaceImage)
admin.site.register(PhotoAlbum)

View File

@ -26,10 +26,6 @@ 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

View File

@ -15,7 +15,6 @@ 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
@ -107,12 +106,8 @@ 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.pk)
return "Voucher " + str(self.code)
class Place(Submittable, Taggable, Mapable):
@ -181,7 +176,7 @@ class PlaceImage (Submittable):
of this image as textual represntation of this instance
"""
return 'Image ' + str(self.pk)
return ' '.join([self.place.name, str(self.pk)])
# These two auto-delete files from filesystem when they are unneeded:

View File

@ -83,6 +83,13 @@ 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')

View File

@ -42,3 +42,11 @@ 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__
)
)