summaryrefslogtreecommitdiff
path: root/apps/blog
diff options
context:
space:
mode:
Diffstat (limited to 'apps/blog')
-rw-r--r--apps/blog/__init__.py0
-rw-r--r--apps/blog/admin.py80
-rw-r--r--apps/blog/fields.py7
-rw-r--r--apps/blog/models.py180
-rw-r--r--apps/blog/signals.py21
-rw-r--r--apps/blog/urls.py15
-rw-r--r--apps/blog/views.py80
-rw-r--r--apps/blog/widgets.py32
8 files changed, 0 insertions, 415 deletions
diff --git a/apps/blog/__init__.py b/apps/blog/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/apps/blog/__init__.py
+++ /dev/null
diff --git a/apps/blog/admin.py b/apps/blog/admin.py
deleted file mode 100644
index cae0b59..0000000
--- a/apps/blog/admin.py
+++ /dev/null
@@ -1,80 +0,0 @@
-from django.contrib import admin
-from django import forms
-from blog.models import Entry, PostImage, Topic
-from blog.widgets import AdminImageWidget
-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 EntryAdmin(OSMGeoAdmin):
- def formfield_for_dbfield(self, db_field, **kwargs):
- if db_field.name == 'thumbnail':
- field = forms.FileField(widget=AdminImageWidget)
- else:
- field = super(EntryAdmin,self).formfield_for_dbfield(db_field,**kwargs)
- return field
- 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', 'enable_comments', 'status','region','location')
- fieldsets = (
- ('Entry', {'fields': ('title','body_markdown', ('location','region'), 'pub_date', ('status','enable_comments'), 'slug','photo_gallery'), 'classes': ('show','extrapretty','wide')}),
- ('Pub Location', {'fields': ('point',('image','thumbnail',),'dek', 'topics', '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
-
-
-
-
-
-class PostImageAdmin(admin.ModelAdmin):
- list_display = ('title', 'output_tags')
-
-class TopicAdmin(admin.ModelAdmin):
- list_display = ('name', 'slug')
-
-admin.site.register(Topic, TopicAdmin)
-admin.site.register(PostImage, PostImageAdmin)
-admin.site.register(Entry, EntryAdmin)
diff --git a/apps/blog/fields.py b/apps/blog/fields.py
deleted file mode 100644
index bab8ad3..0000000
--- a/apps/blog/fields.py
+++ /dev/null
@@ -1,7 +0,0 @@
-from django import forms
-from blog.widgets import AdminImageWidget
-
-
-class FileUploadForm(forms.ModelForm):
- upload = forms.FileField(widget=AdminImageWidget)
-
diff --git a/apps/blog/models.py b/apps/blog/models.py
deleted file mode 100644
index 37841fe..0000000
--- a/apps/blog/models.py
+++ /dev/null
@@ -1,180 +0,0 @@
-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 PIL import Image
-
-from utils import markdown2 as markdown
-
-from photos.models import PhotoGallery
-from locations.models import Location,Region
-#from locations.signals import create_location_item
-from blog.signals import update_recent
-
-def get_upload_path(self, filename):
- return "images/post-images/%s/%s" %(datetime.datetime.today().strftime("%Y"), filename)
-
-def get_tn_path(self, filename):
- return "images/post-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):
- processed = markdown.markdown(md, ['footnotes'],safe_mode = False).split('<break>')
- html = processed[0]+processed[1]
- lede = processed[0]
- return html, lede
-
-PUB_STATUS = (
- (0, 'Draft'),
- (1, 'Published'),
- )
-
-TEMPLATES = (
- (0, 'single'),
- (1, 'double'),
- (2, 'single-dark'),
- (3, 'double-dark'),
- )
-class PostImage(models.Model):
- title = models.CharField(max_length=100)
- image = models.ImageField(upload_to="%s%s" %(settings.IMAGES_ROOT, datetime.datetime.today().strftime("%Y")))
-
- def __unicode__(self):
- return self.title
-
- def output_tags(self):
- return force_unicode('<img src="%s%s" alt="%s" class="postpic"/>' % \
- (settings.IMAGES_URL, self.image.url.split('images')[1].split('/',1)[1], self.title))
-
-
-class Topic(models.Model):
- name = models.CharField(max_length=100)
- slug = models.SlugField()
-
- def __unicode__(self):
- return self.name
-
- def get_absolute_url(self):
- return "/topics/%s/" % (self.slug)
-
-class Entry(models.Model):
- title = models.CharField(max_length=200)
- slug = models.SlugField(unique_for_date='pub_date')
- lede = models.TextField(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')
- enable_comments = models.BooleanField(default=True)
- point = models.PointField(null=True, blank=True)
- location = models.ForeignKey(Location, null=True)
- region = models.ForeignKey(Region, null=True)
- status = models.IntegerField(choices=PUB_STATUS, default=0)
- photo_gallery = models.ForeignKey(PhotoGallery, blank=True, null=True, verbose_name='photo set')
- image = models.FileField(upload_to=get_upload_path, null=True,blank=True)
- image_height = models.CharField(max_length=20, null=True,blank=True)
- image_width = models.CharField(max_length=20, null=True,blank=True)
- thumbnail = models.FileField(upload_to=get_tn_path, null=True,blank=True)
- thumb_height = models.CharField(max_length=20, null=True,blank=True)
- thumb_width = models.CharField(max_length=20, null=True,blank=True)
- meta_description = models.CharField(max_length=256, null=True, blank=True)
- topics = models.ManyToManyField(Topic, blank=True)
- template_name = models.IntegerField(choices=TEMPLATES, default=0)
- location_name = models.CharField(max_length=200, null=True,blank=True)
- state_name = models.CharField(max_length=200, null=True,blank=True)
- country_name = models.CharField(max_length=200, null=True,blank=True)
- state_iso = models.CharField(max_length=2, null=True,blank=True)
- country_iso = models.CharField(max_length=2, 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):
- return "/%s/%s/" % (self.pub_date.strftime("%Y/%b/%d").lower(), self.slug)
-
- @property
- def get_previous_published(self):
- return self.get_previous_by_pub_date(status__exact=1)
-
- @property
- def get_next_published(self):
- return self.get_next_by_pub_date(status__exact=1)
-
-
- def comment_period_open(self):
- return self.enable_comments and datetime.datetime.today() - datetime.timedelta(30) <= self.pub_date
-
- def get_thumbnail_url(self):
- image_dir, img = self.thumbnail.url.split('post-thumbnail/')[1].split('/')
- return '%spost-thumbnail/%s/%s' %(settings.IMAGES_URL, image_dir, img)
-
- def get_image_url(self):
- image_dir, img = self.image.url.split('post-images/')[1].split('/')
- return '%spost-images/%s/%s' %(settings.IMAGES_URL, image_dir, img)
-
- def save(self):
- #get image dimensions
- img = Image.open(self.image)
- self.image_width, self.image_height = img.size
- #same for thumb
- img = Image.open(self.thumbnail)
- self.thumb_width, self.thumb_height = img.size
- #find and replace image urls
- md = image_url_replace(self.body_markdown)
- #run markdown
- html,lede = markdown_processor(md)
- self.body_html = html
- self.lede = lede
- self.dek == markdown.markdown(self.dek, safe_mode = False)
- self.location_name = self.location.name
- self.state_name = self.location.state.name
- self.country_name = self.location.state.country.name
- self.state_iso = self.location.state.code
- self.country_iso = self.location.state.country.iso2
- super(Entry, self).save()
-
-class BlogSitemap(Sitemap):
- changefreq = "never"
- priority = 1.0
-
- def items(self):
- return Entry.objects.filter(status=1)
-
- def lastmod(self, obj):
- return obj.pub_date
-
-class LatestFull(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/blog/signals.py b/apps/blog/signals.py
deleted file mode 100644
index a8c0556..0000000
--- a/apps/blog/signals.py
+++ /dev/null
@@ -1,21 +0,0 @@
-from django.template.loader import render_to_string
-from django.conf import settings
-from django.template import Context
-from django.db.models import get_model
-from django.conf import settings
-
-from locations.models import Region,Country,Route
-
-from build.base import BuildWriting,BuildMap
-
-def update_recent(sender, instance, signal, *args, **kwargs):
- if not settings.DEVELOPMENT:
- if instance.status == 1:
- #update homepage, archives and details
- b = BuildWriting()
- b.build_homepage()
- b.build_archive_pages()
- b.build_detail_pages()
- #update map
- b = BuildMap()
- b.build() \ No newline at end of file
diff --git a/apps/blog/urls.py b/apps/blog/urls.py
deleted file mode 100644
index 57a3e7a..0000000
--- a/apps/blog/urls.py
+++ /dev/null
@@ -1,15 +0,0 @@
-from django.conf.urls.defaults import *
-from django.views.generic.list_detail import object_list
-from django.views.generic.simple import redirect_to
-
-from blog.models import Entry
-
-
-
-urlpatterns = patterns('',
-
- (r'(?P<slug>[-\w]+)/(?P<page>\d+)/$', 'blog.views.entry_list_by_area'),
- (r'(?P<page>\d+)/$', 'blog.views.entry_list'),
- (r'(?P<slug>[-\w]+)/$', redirect_to, {'url': '/writing/%(slug)s/1/'}),
- (r'', redirect_to, {'url': '/writing/1/'}),
-)
diff --git a/apps/blog/views.py b/apps/blog/views.py
deleted file mode 100644
index 72c769e..0000000
--- a/apps/blog/views.py
+++ /dev/null
@@ -1,80 +0,0 @@
-from django.shortcuts import render_to_response,get_object_or_404
-from django.template import RequestContext
-from django.views.generic.date_based import object_detail
-from django.views.generic.list_detail import object_list
-from django.http import Http404
-from django.conf import settings
-
-
-from blog.models import Entry, Topic
-from locations.models import Region, Country
-from photos.models import Photo, PhotoGallery
-from chunks.models import Chunk
-
-def home(request):
- featured = Entry.objects.filter(status__exact=1).select_related().latest()
- #gallery = PhotoGallery.objects.latest()
- context = {
- 'featured': featured,
- #'gallery': gallery
- }
- return render_to_response('archives/homepage.html', context, context_instance = RequestContext(request))
-
-
-def entry_detail(request, year, month, day, slug):
- obj = get_object_or_404(Entry, slug__exact=slug)
- photos = {}
- #if obj.photo_gallery:
- # photos = Photo.objects.filter(set__exact=obj.get().photo_gallery.id)[:9]
- extra = {'photos':photos,}
- return render_to_response('details/entry.html', {'object': obj,'photos':photos}, context_instance=RequestContext(request))
-
-
-"""
-List of all writing
-"""
-def entry_list(request,page):
- request.page_url = '/writing/%d/'
- request.page = int(page)
- qs = Entry.objects.filter(status__exact=1).order_by('-pub_date').select_related()
- return object_list(request, queryset=qs, template_name='archives/writing.html', extra_context={'page':page})
-
-
-"""
-List of all writing
-"""
-def topic_list(request,slug,page):
- request.page_url = '/topics/'+slug+'/%d/'
- request.page = int(page)
- topic = Topic.objects.get(slug=slug)
- qs = Entry.objects.filter(status__exact=1,topics=topic).order_by('-pub_date').select_related()
- return object_list(request, queryset=qs, template_name='archives/topics.html',extra_context={'page':page})
-
-
-"""
-Grabs entries by region or country
-"""
-def entry_list_by_area(request,slug,page):
- request.page_url = '/writing/'+slug+'/%d/'
- request.page = int(page)
- try:
- region = Region.objects.get(slug__exact=slug)
- qs = Entry.objects.filter(status__exact=1,region = region).order_by('-pub_date')
- except:
- region = Country.objects.get(slug__exact=slug)
- qs = Entry.objects.filter(status__exact=1,location__state__country = region).order_by('-pub_date')
- if not region:
- raise Http404
- context = {
- 'region': region,
- }
- return object_list(request, queryset=qs, template_name='archives/writing.html',
- extra_context=context)
-
-def about(request):
- qs = Chunk.objects.filter(key__in=['about_top','about_middle','about_bottom'])
- context = {
- 'object_list':qs,
- 'IMAGES_URL' : settings.IMAGES_URL
- }
- return render_to_response('details/about.html', context, context_instance=RequestContext(request)) \ No newline at end of file
diff --git a/apps/blog/widgets.py b/apps/blog/widgets.py
deleted file mode 100644
index a9451e7..0000000
--- a/apps/blog/widgets.py
+++ /dev/null
@@ -1,32 +0,0 @@
-from django.contrib.admin.widgets import AdminFileWidget
-from django.utils.translation import ugettext as _
-from django.utils.safestring import mark_safe
-from django.conf import settings
-from PIL import Image
-import os
-
-try:
- from sorl.thumbnail.main import DjangoThumbnail
- def thumbnail(image_path):
- t = DjangoThumbnail(relative_source=image_path, requested_size=(200,200))
- return u'<img src="%s" alt="%s" />' % (t.absolute_url, image_path)
-except ImportError:
- def thumbnail(image_path):
- absolute_url = os.path.join(settings.IMAGES_URL, image_path)
- return u'<img src="%s" alt="%s" />' % (absolute_url, image_path)
-
-class AdminImageWidget(AdminFileWidget):
- """
- A FileField Widget that displays an image instead of a file path
- if the current file is an image.
- """
- def render(self, name, value, attrs=None):
- output = []
- file_name = str(value)
- if file_name:
- file_path = '%s' % (file_name)
- output.append('<a target="_blank" href="%s">%s</a><br />%s <a target="_blank" href="%s">%s</a><br />%s ' % \
- (file_path, thumbnail(file_name), _('Currently:'), file_path, file_name, _('Change:')))
-
- output.append(super(AdminFileWidget, self).render(name, value, attrs))
- return mark_safe(u''.join(output))