summaryrefslogtreecommitdiff
path: root/app/guide
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2014-05-23 11:28:10 -0400
committerluxagraf <sng@luxagraf.net>2014-05-23 11:28:10 -0400
commit518b2d618bc10f93cfa44a83715593b8358eb9ce (patch)
treea07993c3ae31bed42f32c0e00788989568790716 /app/guide
parent4bae11bb25a8e3c43118891d17fd8e981ecf8dc6 (diff)
minor refactor to adoipt pep8 and pyflakes coding styles and clean up
some cruft that's been hangin round for years
Diffstat (limited to 'app/guide')
-rw-r--r--app/guide/admin.py95
-rw-r--r--app/guide/models.py71
-rw-r--r--app/guide/views.py36
3 files changed, 98 insertions, 104 deletions
diff --git a/app/guide/admin.py b/app/guide/admin.py
index cd24ab3..c81a2a5 100644
--- a/app/guide/admin.py
+++ b/app/guide/admin.py
@@ -1,63 +1,60 @@
from django.contrib import admin
-from django import forms
from guide.models import Guide
from django.contrib.gis.admin import OSMGeoAdmin
-from django.contrib.gis.maps.google import GoogleMap
-from django.conf import settings
-
-GMAP = GoogleMap(key=settings.GOOGLE_MAPS_API_KEY)
-
class GuideAdmin(OSMGeoAdmin):
- list_display = ('title', 'pub_date','template_name', 'status','location','photo_gallery')
+ 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')
+ 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')}),
+ ('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'
+ )
+ }),
)
-
- class Media:
- js = ['/media/admin/custom/model.js']
- extra_js = [GMAP.api_url + GMAP.key]
- map_template = 'gis/admin/google.html'
- #map_template = 'gis/admin/google.html'
- # Default GeoDjango OpenLayers map options
- # Uncomment and modify as desired
- # To learn more about this jargon visit:
- # www.openlayers.org
-
- default_lon = -9314310
- default_lat = 3991847
+
+ # options for OSM map Using custom ESRI topo map
+ default_lon = -9285175
+ default_lat = 4025046
default_zoom = 6
- #display_wkt = False
- #display_srid = False
- #extra_js = []
- #num_zoom = 18
- #max_zoom = False
- #min_zoom = False
- #units = False
- #max_resolution = False
- #max_extent = False
- #modifiable = True
- #mouse_position = True
- #scale_text = True
- #layerswitcher = True
+ units = True
scrollable = False
- #admin_media_prefix = settings.ADMIN_MEDIA_PREFIX
map_width = 700
- map_height = 325
- #map_srid = 4326
- #map_template = 'gis/admin/openlayers.html'
- #openlayers_url = 'http://openlayers.org/api/2.6/OpenLayers.js'
- #wms_url = 'http://labs.metacarta.com/wms/vmap0'
- #wms_layer = 'basic'
- #wms_name = 'OpenLayers WMS'
- #debug = False
- #widget = OpenLayersWidget
-
-
+ map_height = 425
+ map_template = 'gis/admin/osm.html'
admin.site.register(Guide, GuideAdmin)
diff --git a/app/guide/models.py b/app/guide/models.py
index 90f63e1..9df83d3 100644
--- a/app/guide/models.py
+++ b/app/guide/models.py
@@ -3,59 +3,60 @@ 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 django.template.defaultfilters import truncatewords_html
from PIL import Image
import markdown
-from taggit.managers import TaggableManager
-from locations.models import Location,Region,Country
+from taggit.managers import TaggableManager
+from locations.models import Location
from blog.models import Entry
from photos.models import PhotoGallery
+
def get_upload_path(self, filename):
- return "images/guide-images/%s/%s" %(datetime.datetime.today().strftime("%Y"), 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)
-
+ 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.markdown(md, ['footnotes'],safe_mode = False)
-PUB_STATUS = (
- (0, 'Draft'),
- (1, 'Published'),
- )
+def markdown_processor(md):
+ return markdown.markdown(md, ['footnotes'], safe_mode=False)
+
-TEMPLATES = (
- (0, 'single'),
- (1, 'double'),
- (2, 'single-dark'),
- (3, 'double-dark'),
- )
-
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)
+ 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)
+ 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.'''
@@ -64,8 +65,8 @@ class Guide(models.Model):
@property
def latitude(self):
'''Get the site's latitude.'''
- return self.point.y
-
+ return self.point.y
+
class Meta:
ordering = ('-pub_date',)
get_latest_by = 'pub_date'
@@ -79,29 +80,30 @@ class Guide(models.Model):
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)
-
+ 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):
+ return '%sguide-images/%s/%s' % (settings.IMAGES_URL, image_dir, img)
+
+ def save(self):
#get image dimensions
if self.image:
img = Image.open(self.image)
- self.image_width, self.image_height = img.size
+ self.image_width, self.image_height = img.size
#same for thumb
img = Image.open(self.thumbnail)
- self.thumb_width, self.thumb_height = img.size
+ self.thumb_width, self.thumb_height = img.size
md = image_url_replace(self.body_markdown)
#run markdown
self.body_html = markdown_processor(md)
- self.dek == markdown.markdown(self.dek, safe_mode = False)
+ self.dek = markdown.markdown(self.dek, safe_mode=False)
super(Guide, self).save()
+
class GuideSitemap(Sitemap):
changefreq = "never"
priority = 1.0
@@ -112,6 +114,7 @@ class GuideSitemap(Sitemap):
def lastmod(self, obj):
return obj.pub_date
+
class GuideFull(Feed):
title = "Luxagraf: Topographical Writings"
link = "/writing/"
diff --git a/app/guide/views.py b/app/guide/views.py
index 50a42d2..c22a6b3 100644
--- a/app/guide/views.py
+++ b/app/guide/views.py
@@ -1,33 +1,30 @@
-from django.shortcuts import render_to_response,get_object_or_404
+from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
-from django.core.exceptions import ObjectDoesNotExist
from guide.models import Guide
-from locations.models import Location
-def guide_list(request,page):
- """
- List of all guides
- """
+
+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,
- }
+ 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={
+
+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={
+ """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))
@@ -35,7 +32,4 @@ def location_list(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))
-
-
-
+ return render_to_response('details/guide.html', {'object': obj}, context_instance=RequestContext(request))