2020-09-22 21:56:51 +02:00
|
|
|
|
2020-10-04 22:11:37 +02:00
|
|
|
from django.utils import timezone
|
2020-09-22 21:56:51 +02:00
|
|
|
from django.db import models
|
2020-10-06 17:01:29 +02:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2020-09-22 21:56:51 +02:00
|
|
|
from django.core.validators import MaxValueValidator, MinValueValidator
|
|
|
|
|
|
|
|
from taggit.managers import TaggableManager
|
|
|
|
|
|
|
|
class Taggable(models.Model):
|
|
|
|
'''
|
2020-10-11 01:39:38 +02:00
|
|
|
This abstract model represtens an object that is taggable
|
2020-09-22 21:56:51 +02:00
|
|
|
using django-taggit
|
|
|
|
'''
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
|
|
|
|
tags = TaggableManager(blank=True)
|
|
|
|
|
|
|
|
class Mapable(models.Model):
|
|
|
|
'''
|
|
|
|
This abstract model class represents an object that can be
|
|
|
|
displayed on a map.
|
|
|
|
'''
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
|
2020-10-11 02:07:14 +02:00
|
|
|
name = models.CharField(
|
|
|
|
max_length=50,
|
|
|
|
verbose_name=_('Name'),
|
|
|
|
)
|
2020-09-22 21:56:51 +02:00
|
|
|
latitude = models.FloatField(
|
|
|
|
validators=[
|
|
|
|
MinValueValidator(-90),
|
|
|
|
MaxValueValidator(90)
|
2020-10-06 17:01:29 +02:00
|
|
|
],
|
2020-10-11 02:07:14 +02:00
|
|
|
verbose_name=_('Latitude'),
|
2020-10-06 17:01:29 +02:00
|
|
|
help_text=_('Latitude in decimal format: e. g. 41.40338')
|
2020-09-22 21:56:51 +02:00
|
|
|
)
|
|
|
|
longitude = models.FloatField(
|
|
|
|
validators=[
|
|
|
|
MinValueValidator(-180),
|
|
|
|
MaxValueValidator(180)
|
2020-10-06 17:01:29 +02:00
|
|
|
],
|
2020-10-11 02:07:14 +02:00
|
|
|
verbose_name=_('Longitude'),
|
2020-10-06 17:01:29 +02:00
|
|
|
help_text=_('Longitude in decimal format: e. g. 2.17403')
|
2020-09-22 21:56:51 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
class Submittable(models.Model):
|
|
|
|
'''
|
|
|
|
This abstract model class represents an object that can be submitted by
|
|
|
|
an explorer.
|
|
|
|
'''
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
|
2020-10-11 21:56:14 +02:00
|
|
|
submitted_when = models.DateTimeField(
|
|
|
|
auto_now_add=True,
|
|
|
|
null=True,
|
|
|
|
verbose_name=_('Submission date')
|
|
|
|
)
|
2020-09-22 21:56:51 +02:00
|
|
|
submitted_by = models.ForeignKey(
|
|
|
|
'Explorer',
|
|
|
|
on_delete=models.SET_NULL,
|
|
|
|
null=True,
|
|
|
|
blank=True,
|
2020-10-11 21:56:14 +02:00
|
|
|
related_name='%(class)ss',
|
|
|
|
verbose_name=_('Submitter')
|
2020-09-22 21:56:51 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
class Expireable(models.Model):
|
|
|
|
"""
|
2020-10-04 22:11:37 +02:00
|
|
|
Base class for things that can expire, i.e. Vouchers
|
2020-09-22 21:56:51 +02:00
|
|
|
"""
|
2020-10-04 22:11:37 +02:00
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
|
2020-10-11 21:56:14 +02:00
|
|
|
created_when = models.DateTimeField(
|
|
|
|
auto_now_add=True,
|
|
|
|
verbose_name=_('Creation date')
|
|
|
|
)
|
|
|
|
expires_when = models.DateTimeField(
|
|
|
|
verbose_name=_('Expiration date')
|
|
|
|
)
|
2020-10-04 22:11:37 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_expired(self):
|
2020-10-11 07:09:59 +02:00
|
|
|
return timezone.now() > self.expires_when
|