summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/guide/__init__.py0
-rw-r--r--apps/guide/admin.py63
-rw-r--r--apps/guide/models.py108
-rw-r--r--apps/guide/urls.py11
-rw-r--r--apps/guide/views.py34
-rw-r--r--templates/archives/guide.html42
-rw-r--r--templates/details/guide.html65
7 files changed, 323 insertions, 0 deletions
diff --git a/apps/guide/__init__.py b/apps/guide/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/apps/guide/__init__.py
diff --git a/apps/guide/admin.py b/apps/guide/admin.py
new file mode 100644
index 0000000..efdc7cd
--- /dev/null
+++ b/apps/guide/admin.py
@@ -0,0 +1,63 @@
+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','region','location','photo_gallery')
+ search_fields = ['title', 'body_markdown']
+ prepopulated_fields = {"slug" : ('title',)}
+ list_filter = ('pub_date', 'status','region','location')
+ fieldsets = (
+ ('Note', {'fields': ('title','body_markdown', ('location','region'), 'pub_date', 'status', 'slug','photo_gallery'), 'classes': ('show','extrapretty','wide')}),
+ ('Pub Location', {'fields': ('dek', 'meta_description','template_name'), '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
+ 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
+ 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
+
+
+
+admin.site.register(Guide, GuideAdmin)
diff --git a/apps/guide/models.py b/apps/guide/models.py
new file mode 100644
index 0000000..16c44fe
--- /dev/null
+++ b/apps/guide/models.py
@@ -0,0 +1,108 @@
+import datetime
+from django.contrib.gis.db import models
+from django.conf import settings
+from django.contrib.syndication.feeds import Feed
+from django.contrib.sitemaps import Sitemap
+from django.template.defaultfilters import truncatewords_html
+
+
+from utils import markdown2 as markdown
+from taggit.managers import TaggableManager
+from locations.models import Location,Region,Country
+from blog.models import Entry
+from photos.models import PhotoGallery
+
+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'),
+ )
+
+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)
+ pub_date = models.DateTimeField('Date published')
+ location = models.ForeignKey(Location, null=True, blank=True)
+ country = models.ForeignKey(Country, null=True, blank=True)
+ region = models.ForeignKey(Region, null=True, blank=True)
+ 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)
+ template_name = models.IntegerField(choices=TEMPLATES, default=0)
+ tags = TaggableManager(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 "/guide/location/%s/%s/" % (self.location.slug, self.slug)
+ else:
+ return "/guide/%s/" % (self.slug)
+
+
+ def save(self):
+ md = image_url_replace(self.body_markdown)
+ #run markdown
+ self.body_html = markdown_processor(md)
+ self.dek == markdown.markdown(self.dek, safe_mode = False)
+ 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/apps/guide/urls.py b/apps/guide/urls.py
new file mode 100644
index 0000000..b15e7ab
--- /dev/null
+++ b/apps/guide/urls.py
@@ -0,0 +1,11 @@
+from django.conf.urls.defaults import *
+from django.views.generic.simple import redirect_to
+
+urlpatterns = patterns('',
+ (r'location/(?P<location>[-\w]+)/(?P<slug>[-\w]+)/$', 'guide.views.guide_detail'),
+ (r'location/(?P<location>[-\w]+)/$', 'guide.views.guide_list_by_location'),
+ (r'location/$', 'guide.views.location_list'),
+ (r'(?P<page>\d+)/$', 'guide.views.guide_list'),
+ (r'(?P<slug>[-\w]+)/$', 'guide.views.guide_detail'),
+ (r'', redirect_to, {'url': '/guide/1/'}),
+)
diff --git a/apps/guide/views.py b/apps/guide/views.py
new file mode 100644
index 0000000..dc63fc5
--- /dev/null
+++ b/apps/guide/views.py
@@ -0,0 +1,34 @@
+from django.shortcuts import render_to_response,get_object_or_404
+from django.template import RequestContext
+from django.views.generic.list_detail import object_list
+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
+ """
+ request.page_url = '/guide/%d/'
+ request.page = int(page)
+ qs = Guide.objects.filter(status__exact=1).order_by('-pub_date').select_related()
+ return object_list(request, queryset=qs, template_name='archives/guide.html', extra_context={'page':page})
+
+def guide_list_by_location(request,location):
+ qs = Guide.objects.filter(location__slug__exact=location)
+ return object_list(request, queryset=qs, template_name='archives/writing.html')
+
+def location_list(request):
+ """
+ List of all locations with guides
+ """
+ qs = Guide.objects.filter(status__exact=1).order_by('-pub_date').select_related()
+ return object_list(request, queryset=qs, template_name='archives/guide.html')
+
+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))
+
+
+
diff --git a/templates/archives/guide.html b/templates/archives/guide.html
new file mode 100644
index 0000000..e880343
--- /dev/null
+++ b/templates/archives/guide.html
@@ -0,0 +1,42 @@
+{% extends 'base.html' %}
+{% load typogrify %}
+{% load pagination_tags %}
+
+{% block pagetitle %}Luxagraf | {% if region %}Travel Writing from {{region.name|title|smartypants|safe}}{%else%}Travel Writing from Around the World {%endif%} Page {{page}}{% endblock %}
+{% block metadescription %}{% if region %}Travel writing, essays and dispatches from {{region.name|title|smartypants|safe}}{%else%}Travel writing, essays and dispatches from around the world{%endif%} Page {{page}}{% endblock %}
+{%block bodyid%}id="writing"{%endblock%}
+
+
+{% block primary %}<section id="page-header">
+ <h1 class="hide">{% if region %}Writings from {%if region.name == 'United States'%}the United States{%else%}{{region.name|title|smartypants|safe}}{%endif%}{%else%}Writing {%endif%}</h1>
+ <nav class="bl">
+ <ul id="breadcrumbs" itemscope itemtype="http://data-vocabulary.org/Breadcrumb">
+ <li><a href="/" title="luxagraf homepage" itemprop="url"><span itemprop="title">Home</span></a> &rarr; </li>
+ {% if region %}{%if region.name == 'United States'%} <li><a href="/writing/" title="See all Writing" itemprop="url"><span itemprop="title">Writing</span></a> &rarr;</li>
+ <li itemprop="title">the United States</li>{%else%}<li><a href="/writing/" title="See all Writing" itemprop="url"><span>Writing</span></a> &rarr;</li>
+ <li>{{region.name|title|smartypants|safe}}</li>{%endif%}{%else%}<li>Writing </li>{%endif%}
+ </ul>
+ </nav>
+ </section>
+ <section id="writing-archive" class="archive"> {% autopaginate object_list 10 %} {% for object in object_list %}
+ <article>
+ <h1><a href="{{object.get_absolute_url}}" title="{%if object.title_keywords%}{{object.title_keywords}}{%else%}{{object.title}}{%endif%}">{{object.title|smartypants|widont|safe}}</a></h1>
+ <div class="img">
+ <a href="{{object.get_absolute_url}}" title="{{object.title}}"><img src="{{object.get_image_url}}" alt="{{ object.title }}" width="{{object.image_width}}" height="{{object.image_height}}" class="post-image" /></a>
+ </div>
+ <div class="dateline">
+ <p class="location bl" itemprop="geo" itemscope itemtype="http://data-vocabulary.org/​Geo">{% if object.country_name == "United States" %}{{object.location_name|smartypants|safe}}, <a href="/writing/united-states/1/" title="travel writing from the United States">{{object.state_name}}</a>{%else%}{{object.location_name|smartypants|safe}}, <a href="/writing/{{object.country_name|slugify}}/1/" title="travel writing from {{object.country_name}}">{{object.country_name}}</a>{%endif%}
+ <meta itemprop="latitude" content="{{object.latitude}}" />
+ <meta itemprop="longitude" content="{{object.longitude}}" /></p>
+ <time datetime="{{object.pub_date|date:'c'}}">{{object.pub_date|date:"m/d/y"}}</time>
+ </div>
+ <p class="hyphenate">{{object.dek|safe}}</p>
+ </article> {% endfor %}
+ </section>
+ <nav id="pagination">{% paginate %}
+ </nav>
+{% endblock %}
+
+
+
+{% block js %}<script src="{{MEDIA_URL}}js/hyphenate.min.js" type="text/javascript"></script>{% endblock%} \ No newline at end of file
diff --git a/templates/details/guide.html b/templates/details/guide.html
new file mode 100644
index 0000000..c5dc80f
--- /dev/null
+++ b/templates/details/guide.html
@@ -0,0 +1,65 @@
+{% extends 'base.html' %}
+{% load typogrify %}
+
+{% block pagetitle %}{{object.title|title|smartypants|safe}} | Luxagraf, a travelogue | {% if object.country_name == "United States" %}{{object.location_name|smartypants|safe}}, {{object.state_name}}{%else%}{{object.location_name|smartypants|safe}}, {{object.country_name}}{%endif%}){% endblock %}
+
+{% block metadescription %}{{object.meta_description|striptags|safe}}{% endblock %}
+{%block extrahead%}
+ <link rel="canonical" href="http://luxagraf.net{{object.get_absolute_url}}" />
+ <meta name="ICBM" content="{{object.latitude}}, {{object.longitude}}" />
+ <meta name="geo.position" content="{{object.latitude}}; {{object.longitude}}" />
+ <meta name="geo.placename" content="{% if object.country_name == "United States" %}{{object.location_name|smartypants|safe}}, {{object.state_name}}{%else%}{{object.location_name|smartypants|safe}}, {{object.country_name}}{%endif%}">
+ <meta name="geo.region" content="{{object.country_iso}}{%if object.state_iso != None %}-{{object.state_iso}}{%endif%}">
+{%endblock%}
+{%block htmlclass%}{% with object.template_name as t %}
+class="{%if t == 0 or t == 2 %}single{%endif%}{%if t == 1 or t == 3 %}double{%endif%}{%if t == 2 or t == 3 %} dark{%endif%}"{%endwith%}{%endblock%}
+
+
+{% block primary %}
+ <article role="main">
+ <header>
+ <h1>{%if object.template_name == 1 or object.template_name == 3 %}{{object.title|smartypants|safe}}{%else%}{{object.title|smartypants|widont|safe}}{%endif%}</h1>
+ <aside class="geo bl">
+ <span class="location" itemprop="geo" itemscope itemtype="http://data-vocabulary.org/​Geo">{% if object.country_name == "United States" %}{{object.location_name|smartypants|safe}}, <a href="/writing/united-states/1/" title="travel writing from the United States">{{object.state_name}}</a>{%else%}{{object.location_name|smartypants|safe}}, <a href="/writing/{{object.country_name|slugify}}/1/" title="travel writing from {{object.country_name}}">{{object.country_name}}</a>{%endif%}
+ <meta itemprop="latitude" content="{{object.latitude}}" />
+ <meta itemprop="longitude" content="{{object.longitude}}" /></span>
+ {%comment%} &nbsp;&nbsp;(<a href="" title="">Map</a>, <a href="" title="">Photos</a>){%endcomment%}
+ </aside>
+ <time datetime="{{object.pub_date|date:'c'}}" pubdate>{{object.pub_date|date:"F"}} <span>{{object.pub_date|date:"j, Y"}}</span></time>
+ </header>
+ <div class="post-body{% with object.template_name as t %}{%if t == 0 or t == 2 %}-single{%endif%}{%if t == 1 or t == 3 %}-double{%endif%}{%endwith%}">
+ {{object.body_html|smartypants|widont|safe}}
+ </div>{%if object.template_name == 1 %}
+ <div class="clearfix"></div>{%endif%}{%if object.template_name == 3 %}<div class="clearfix"></div>{%endif%}
+ {%comment%}
+ <footer id="post-metadata">
+ <h4 class="hide">About {{object.title|smartypants|safe}}</h4>
+ <p>Posted <time datetime="{{object.pub_date|date:'c'}}">{{object.pub_date|date:"F j, Y"}}</time>, from {% if object.country_name == "United States" %}{{object.location_name|smartypants|safe}}, <a href="/writing/united-states/1/" title="travel writing from the United States">{{object.state_name}}</a>{%else%}{{object.location_name|smartypants|safe}}, <a href="/writing/{{object.country_name|slugify}}/1/" title="travel writing from {{object.country_name}}">{{object.country_name}}</a>{%endif%}.
+ Follow along on <a href="http://twitter.com/luxagraf" title="twitter" rel="me">Twitter</a> or by subscribing to the <a href="http://feeds.feedburner.com/luxagraf/blog" title="writing RSS 2.0 feed">RSS Feed</a>. For more about me, see the <a href="/about/" title="about luxagraf">about page</a>. To get in touch please use the <a href="/contact/" title="contact me">contact form</a> or leave a comment below.</p>
+ </footer>
+ {% endcomment %}
+ {% with object.get_next_published as next %}
+ {% with object.get_previous_published as prev %}
+ <nav id="page-navigation">
+ <ul>{% if prev%}
+ <li id="next"><span class="bl">Previous:</span>
+ <a href="{{ prev.get_absolute_url }}" title=" {{prev.title}}">{{prev.title|safe}}</a>
+ </li>{%endif%}{% if next%}
+ <li id="prev"><span class="bl">Next:</span>
+ <a href="{{ next.get_absolute_url }}" title=" {{next.title}}">{{next.title|safe}}</a>
+ </li>{%endif%}
+ </ul>
+ </nav>{%endwith%}{%endwith%}
+
+ {%comment%}
+ <section id="comments">
+ <h4><a class="disqus-link-count" href="{{object.get_absolute_url}}#disqus_thread">Comments</a></h4>
+ <div id="disqus_thread"></div><script type="text/javascript" src="http://disqus.com/forums/luxagraf/embed.js"></script><noscript><a href="http://luxagraf.disqus.com/?url=ref">View the discussion thread.</a></noscript><a href="http://disqus.com" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a>
+ </section>
+ {%endcomment%}
+ </article>
+{% endblock %}
+{% block js %}
+{% with object.template_name as t %}{%if t == 1 or t == 3 %}
+<script src="{{MEDIA_URL}}js/hyphenate.min.js" type="text/javascript"></script>
+{%endif%}{%endwith%}{%endblock%}