summaryrefslogtreecommitdiff
path: root/app/unused_apps/projects/models/base.py
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2020-08-15 11:58:34 -0400
committerluxagraf <sng@luxagraf.net>2020-08-15 11:58:34 -0400
commitb66d000ee469539ce7aea557b612c0444177e36d (patch)
tree273547921dc6f9ded2a5681b82514c68e28ba448 /app/unused_apps/projects/models/base.py
parentd3e57c1bd17ad3e71810235a672d4782136901a5 (diff)
archived old unused apps and migrated fieldnotes to posts
Diffstat (limited to 'app/unused_apps/projects/models/base.py')
-rw-r--r--app/unused_apps/projects/models/base.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/app/unused_apps/projects/models/base.py b/app/unused_apps/projects/models/base.py
new file mode 100644
index 0000000..aa795d2
--- /dev/null
+++ b/app/unused_apps/projects/models/base.py
@@ -0,0 +1,67 @@
+import datetime
+from django.contrib.gis.db import models
+from django.contrib.sitemaps import Sitemap
+from django.conf import settings
+
+
+def get_upload_path(self, filename):
+ return "images/project-thumbs/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename)
+
+
+class Project(models.Model):
+ title = models.CharField(max_length=200)
+ subtitle = models.CharField(max_length=200, null=True, blank=True)
+ slug = models.CharField(max_length=50)
+ lede = models.TextField(blank=True)
+ pub_date = models.DateTimeField('Date published')
+ PUB_STATUS = (
+ (0, 'Draft'),
+ (1, 'Published'),
+ )
+ status = models.IntegerField(choices=PUB_STATUS, default=0)
+ image = models.FileField(upload_to=get_upload_path, null=True, blank=True)
+ model_name = models.CharField(max_length=200, null=True)
+
+ @property
+ def longitude(self):
+ '''Get the site's longitude.'''
+ return self.point.x
+
+ @property
+ def latitude(self):
+ '''Get the site's latitude.'''
+ return self.point.y
+
+ @property
+ def get_project_image(self):
+ return "%s%s" % (settings.IMAGES_URL, self.image.name[7:])
+
+
+ class Meta:
+ ordering = ('-pub_date',)
+ get_latest_by = 'pub_date'
+ app_label = 'projects'
+
+ def __str__(self):
+ return self.title
+
+ def get_absolute_url(self):
+ return "/%s/" % (self.slug)
+
+ def get_previous_published(self):
+ return self.get_previous_by_pub_date(status__exact=1)
+
+ def get_next_published(self):
+ return self.get_next_by_pub_date(status__exact=1)
+
+
+class ProjectSitemap(Sitemap):
+ changefreq = "monthly"
+ priority = 0.5
+ protocol = "https"
+
+ def items(self):
+ return Project.objects.filter(status=1)
+
+ def lastmod(self, obj):
+ return obj.pub_date