1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
import datetime
from django.contrib.gis.db import models
from django.conf import settings
from django.contrib.sitemaps import Sitemap
from django.template.defaultfilters import truncatewords_html
from django.contrib.syndication.views import Feed
from utils 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)
model_name = models.CharField(max_length=200, null=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)
class ProjectSitemap(Sitemap):
changefreq = "monthly"
priority = 0.5
def items(self):
return Project.objects.filter(status=1)
def lastmod(self, obj):
return obj.pub_date
|