diff options
author | luxagraf@c63593aa-01b0-44d9-8516-4b9c7e931d7f <luxagraf@c63593aa-01b0-44d9-8516-4b9c7e931d7f> | 2010-04-04 23:30:30 +0000 |
---|---|---|
committer | luxagraf@c63593aa-01b0-44d9-8516-4b9c7e931d7f <luxagraf@c63593aa-01b0-44d9-8516-4b9c7e931d7f> | 2010-04-04 23:30:30 +0000 |
commit | f8cda18e218cf9849ea7b70fc39b505420c930b9 (patch) | |
tree | 43eecea66befb5d84dac316f4ca9de7944855a1b /apps | |
parent | a1138b560308e043de00c2211293583515def19e (diff) |
started work on the 5x5 project, models, views, templates
Diffstat (limited to 'apps')
-rw-r--r-- | apps/projects/models.py | 142 | ||||
-rw-r--r-- | apps/projects/models/__init__.py | 2 | ||||
-rw-r--r-- | apps/projects/models/base.py | 63 | ||||
-rw-r--r-- | apps/projects/models/fiveby.py | 58 | ||||
-rw-r--r-- | apps/projects/urls.py | 15 | ||||
-rw-r--r-- | apps/projects/views.py | 22 |
6 files changed, 153 insertions, 149 deletions
diff --git a/apps/projects/models.py b/apps/projects/models.py deleted file mode 100644 index bdbcd82..0000000 --- a/apps/projects/models.py +++ /dev/null @@ -1,142 +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 - - -import markdown2 as markdown -from tagging.fields import TagField -from tagging.models import Tag - -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-thumbs/%s/%s" %(datetime.datetime.today().strftime("%Y"), filename) - -def markdown_processor(md): - processed = markdown.markdown(md, safe_mode = False).split('<break>') - html = processed[0]+processed[1] - lede = processed[0] - return html, lede - -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') - tags = TagField() - enable_comments = models.BooleanField(default=True) - point = models.PointField(null=True) - location = models.ForeignKey(Location, null=True) - region = models.ForeignKey(Region, null=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') - thumbnail = models.FileField(upload_to=get_upload_path, null=True,blank=True) - title_keywords = models.CharField(max_length=200, null=True, blank=True) - topics = models.ManyToManyField(Topic, 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) - - 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) - - def get_tags(self): - return Tag.objects.get_for_object(self) - - def comment_period_open(self): - return self.enable_comments and datetime.datetime.today() - datetime.timedelta(30) <= self.pub_date - - def get_thumbnail_url(self): - if settings.DEVELOPMENT == True: - return '%s%s' %(settings.IMAGES_URL, self.thumbnail.url[35:]) - else: - return '%s%s' %(settings.IMAGES_URL, self.thumbnail.url[33:]) - - def save(self): - html,lede = markdown_processor(self.body_markdown) - self.body_html = html - self.lede = lede - self.dek == markdown.markdown(self.dek, safe_mode = False) - 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/projects/models/__init__.py b/apps/projects/models/__init__.py new file mode 100644 index 0000000..b29933a --- /dev/null +++ b/apps/projects/models/__init__.py @@ -0,0 +1,2 @@ +from base import Project +from fiveby import FiveBy
\ No newline at end of file diff --git a/apps/projects/models/base.py b/apps/projects/models/base.py new file mode 100644 index 0000000..bc42918 --- /dev/null +++ b/apps/projects/models/base.py @@ -0,0 +1,63 @@ +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 + + +import markdown2 as markdown + + +from photos.models import PhotoGallery +from locations.models import Location,Region + + +def get_upload_path(self, filename): + return "images/project-thumbs/%s/%s" %(datetime.datetime.today().strftime("%Y"), filename) + +def markdown_processor(md): + html = markdown.markdown(md, safe_mode = False).split('<break>') + return html + + + +class Project(models.Model): + title = models.CharField(max_length=200) + subtitle = models.CharField(max_length=200, null=True, blank=True) + slug = models.SlugField(unique_for_date='pub_date') + 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) + + @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' + app_label = 'projects' + + def __unicode__(self): + return self.title + + def get_absolute_url(self): + return "/%s/%s/" % ('projects', 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)
\ No newline at end of file diff --git a/apps/projects/models/fiveby.py b/apps/projects/models/fiveby.py new file mode 100644 index 0000000..5415ee7 --- /dev/null +++ b/apps/projects/models/fiveby.py @@ -0,0 +1,58 @@ +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 locations.models import Location,Region + +def get_upload_path(self, filename): + return "images/projects/videos/5x5/%s/%s" %(datetime.datetime.today().strftime("%Y"), filename) + +def get_image_upload_path(self, filename): + return "images/projects/5x5/%s/%s" %(datetime.datetime.today().strftime("%Y"), filename) + +class FiveBy(models.Model): + title = models.CharField(max_length=200) + slug = models.SlugField(unique_for_date='pub_date') + lede = models.TextField(blank=True) + image = models.FileField(upload_to=get_image_upload_path, null=True,blank=True) + videoh264 = models.FileField(upload_to=get_upload_path, null=True,blank=True) + videoogg = models.FileField(upload_to=get_upload_path, null=True,blank=True) + vimeo_link = models.CharField(max_length=200) + youtube_link = models.CharField(max_length=200) + pub_date = models.DateTimeField('Date published') + PUB_STATUS = ( + (0, 'Draft'), + (1, 'Published'), + ) + status = models.IntegerField(choices=PUB_STATUS, default=0) + point = models.PointField(null=True) + location = models.ForeignKey(Location, null=True) + region = models.ForeignKey(Region, null=True) + + + + class Meta: + ordering = ('-pub_date',) + get_latest_by = 'pub_date' + app_label = 'projects' + verbose_name_plural = '5x5' + + def __unicode__(self): + return self.title + + def get_absolute_url(self): + return "/%s/%s/%s/" % ('projects', '5x5', self.slug) + + @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 +
\ No newline at end of file diff --git a/apps/projects/urls.py b/apps/projects/urls.py index ed2dbfb..3ea4b45 100644 --- a/apps/projects/urls.py +++ b/apps/projects/urls.py @@ -1,15 +1,16 @@ from django.conf.urls.defaults import * from django.views.generic.list_detail import object_list from django.views.generic.simple import redirect_to,direct_to_template +from django.views.generic import list_detail -#from blog.models import Entry - +from projects.models.base import Project +projects = { + 'queryset': Project.objects.filter(status__exact=1).order_by('-pub_date'), +} 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'^$', direct_to_template, {'template': 'projects/base.html'}), + (r'(?P<slug>[-\w]+)/$', 'projects.views.detail'), + (r'^$',list_detail.object_list, dict(projects, template_name='archives/projects.html')), ) + diff --git a/apps/projects/views.py b/apps/projects/views.py new file mode 100644 index 0000000..8103270 --- /dev/null +++ b/apps/projects/views.py @@ -0,0 +1,22 @@ +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.db.models import get_model + + +from projects.models.base import Project +from projects.models.fiveby import FiveBy + +projects = {'5x5':'FiveBy','6x6':'SixBy'} + +""" +Projects by slug +""" +def detail(request,slug): + name = projects[slug] + model = get_model('projects', name) + qs = model.objects.filter(status__exact=1) + template = 'details/%s.html' %(slug) + return object_list(request, queryset=qs, template_name=template,) + + |