diff options
author | luxagraf <sng@luxagraf.net> | 2017-12-14 18:47:45 -0800 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2017-12-14 18:47:45 -0800 |
commit | 83b7318a4672d32ed77cd3f906f43f5ad1cce854 (patch) | |
tree | 457806693c791360ada99dd9b3d19a5dc9712936 /app/unused_apps/guide | |
parent | adb5c207bea19cedc400b65bd8cd2c54ca0faba0 (diff) |
archived old apps that I'm not using
Diffstat (limited to 'app/unused_apps/guide')
-rw-r--r-- | app/unused_apps/guide/__init__.py | 0 | ||||
-rw-r--r-- | app/unused_apps/guide/admin.py | 61 | ||||
-rw-r--r-- | app/unused_apps/guide/models.py | 129 | ||||
-rw-r--r-- | app/unused_apps/guide/urls.py | 13 | ||||
-rw-r--r-- | app/unused_apps/guide/views.py | 35 |
5 files changed, 238 insertions, 0 deletions
diff --git a/app/unused_apps/guide/__init__.py b/app/unused_apps/guide/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/unused_apps/guide/__init__.py diff --git a/app/unused_apps/guide/admin.py b/app/unused_apps/guide/admin.py new file mode 100644 index 0000000..dfdf45e --- /dev/null +++ b/app/unused_apps/guide/admin.py @@ -0,0 +1,61 @@ +from django.contrib import admin +from guide.models import Guide +from django.contrib.gis.admin import OSMGeoAdmin + + +class GuideAdmin(OSMGeoAdmin): + list_display = ( + 'title', + 'pub_date', + 'template_name', + 'status', + 'location', + 'photo_gallery' + ) + search_fields = ['title', 'body_markdown'] + prepopulated_fields = {"slug": ('title',)} + list_filter = ('pub_date', 'status', 'location__state__country__lux_region', 'location') + fieldsets = ( + ('Note', { + 'fields': ( + 'title', + 'body_markdown', + 'location', + 'pub_date', + 'status', + 'slug', + 'photo_gallery' + ), + 'classes': ( + 'show', + 'extrapretty', + 'wide' + ) + }), + ('Extra', { + 'fields': ( + 'dek', + 'meta_description', + 'template_name', + 'image', + 'thumbnail' + ), + 'classes': ( + 'collapse', + 'wide' + ) + }), + ) + + # options for OSM map Using custom ESRI topo map + default_lon = -9285175 + default_lat = 4025046 + default_zoom = 6 + units = True + scrollable = False + map_width = 700 + map_height = 425 + map_template = 'gis/admin/osm.html' + openlayers_url = '/static/admin/js/OpenLayers.js' + +admin.site.register(Guide, GuideAdmin) diff --git a/app/unused_apps/guide/models.py b/app/unused_apps/guide/models.py new file mode 100644 index 0000000..7f0d501 --- /dev/null +++ b/app/unused_apps/guide/models.py @@ -0,0 +1,129 @@ +import datetime +from django.contrib.gis.db import models +from django.conf import settings +from django.contrib.sitemaps import Sitemap +from django.contrib.syndication.views import Feed +from PIL import Image + +from taggit.managers import TaggableManager +from locations.models import Location +from jrnl.models import Entry +from photos.models import PhotoGallery + +from utils.widgets import markdown_to_html + + +def get_upload_path(self, filename): + return "images/guide-images/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename) + + +def get_tn_path(self, filename): + return "images/guide-thumbnail/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename) + + +def image_url_replace(str): + str = str.replace('[[base_url]]', settings.IMAGES_URL) + return str + + +def markdown_processor(md): + return markdown_to_html(md) + + +class Guide(models.Model): + title = models.CharField(max_length=200) + slug = models.SlugField(unique_for_date='pub_date') + entry = models.ForeignKey(Entry, null=True, blank=True) + body_html = models.TextField(blank=True) + body_markdown = models.TextField() + dek = models.TextField(null=True, blank=True) + pub_date = models.DateTimeField('Date published') + location = models.ForeignKey(Location, null=True, blank=True) + PUB_STATUS = ( + (0, 'Draft'), + (1, 'Published'), + ) + status = models.IntegerField(choices=PUB_STATUS, default=0) + photo_gallery = models.ForeignKey(PhotoGallery, blank=True, null=True, verbose_name='photo set') + meta_description = models.CharField(max_length=256, null=True, blank=True) + TEMPLATES = ( + (0, 'single'), + (1, 'double'), + (2, 'single-dark'), + (3, 'double-dark'), + ) + template_name = models.IntegerField(choices=TEMPLATES, default=0) + tags = TaggableManager(blank=True) + image = models.FileField(upload_to=get_upload_path, null=True, blank=True) + thumbnail = models.FileField(upload_to=get_tn_path, null=True, blank=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 + + class Meta: + ordering = ('-pub_date',) + get_latest_by = 'pub_date' + verbose_name_plural = 'entries' + + def __unicode__(self): + return self.title + + def get_absolute_url(self): + if self.location: + return "/travel-guide/location/%s/%s/" % (self.location.slug, self.slug) + else: + return "/travel-guide/%s/" % (self.slug) + + def get_thumbnail_url(self): + image_dir, img = self.thumbnail.url.split('guide-thumbnail/')[1].split('/') + return '%sguide-thumbnail/%s/%s' % (settings.IMAGES_URL, image_dir, img) + + def get_image_url(self): + image_dir, img = self.image.url.split('guide-images/')[1].split('/') + return '%sguide-images/%s/%s' % (settings.IMAGES_URL, image_dir, img) + + def save(self): + if self.image: + img = Image.open(self.image) + self.image_width, self.image_height = img.size + img = Image.open(self.thumbnail) + self.thumb_width, self.thumb_height = img.size + md = image_url_replace(self.body_markdown) + self.body_html = markdown_to_html(md) + self.dek = markdown_to_html(self.dek) + super(Guide, self).save() + + +class GuideSitemap(Sitemap): + changefreq = "never" + priority = 1.0 + + def items(self): + return Entry.objects.filter(status=1) + + def lastmod(self, obj): + return obj.pub_date + + +class GuideFull(Feed): + title = "Luxagraf: Topographical Writings" + link = "/writing/" + description = "Latest postings to luxagraf.net" + description_template = 'feeds/blog_description.html' + + def items(self): + return Entry.objects.filter(status__exact=1).order_by('-pub_date')[:10] + + +#from django.dispatch import dispatcher +#from django.db.models import signals + +#signals.post_save.connect(update_recent, sender=Entry) + diff --git a/app/unused_apps/guide/urls.py b/app/unused_apps/guide/urls.py new file mode 100644 index 0000000..e701d3e --- /dev/null +++ b/app/unused_apps/guide/urls.py @@ -0,0 +1,13 @@ +from django.conf.urls import * +from django.views.generic.base import RedirectView + +from . import views + +urlpatterns = [ + url(r'location/(?P<location>[-\w]+)/(?P<slug>[-\w]+)/$', views.guide_detail), + url(r'location/(?P<location>[-\w]+)/$', views.guide_list_by_location), + url(r'location/$', views.location_list), + url(r'(?P<page>\d+)/$', views.guide_list), + url(r'(?P<slug>[-\w]+)/$', views.guide_detail), + url(r'', RedirectView.as_view(url="/travel-guide/1/")), +] diff --git a/app/unused_apps/guide/views.py b/app/unused_apps/guide/views.py new file mode 100644 index 0000000..c22a6b3 --- /dev/null +++ b/app/unused_apps/guide/views.py @@ -0,0 +1,35 @@ +from django.shortcuts import render_to_response, get_object_or_404 +from django.template import RequestContext + +from guide.models import Guide + + +def guide_list(request, page): + """List of all guides""" + request.page_url = "/guide/%d/" + request.page = int(page) + context = { + 'object_list': Guide.objects.filter(status__exact=1).order_by('-pub_date').select_related(), + 'page': page, + } + return render_to_response("archives/guide.html", context, context_instance=RequestContext(request)) + + +def guide_list_by_location(request, location): + context = { + "object_list": Guide.objects.filter(location__slug__exact=location), + } + return render_to_response("archives/guide.html", context, context_instance=RequestContext(request)) + + +def location_list(request): + """List of all locations with guides""" + context = { + "object_list": Guide.objects.filter(status__exact=1).order_by('-pub_date').select_related() + } + return render_to_response("archives/guide.html", context, context_instance=RequestContext(request)) + + +def guide_detail(request, slug, location=None): + obj = get_object_or_404(Guide, slug__exact=slug) + return render_to_response('details/guide.html', {'object': obj}, context_instance=RequestContext(request)) |