Applications directory from SFLC website; About to adapt it for Conservancy website to run on its own
This commit is contained in:
parent
48cba465ea
commit
8e6ea8ad71
42 changed files with 1107 additions and 0 deletions
0
www/conservancy/apps/__init__.py
Normal file
0
www/conservancy/apps/__init__.py
Normal file
0
www/conservancy/apps/blog/__init__.py
Normal file
0
www/conservancy/apps/blog/__init__.py
Normal file
18
www/conservancy/apps/blog/admin.py
Normal file
18
www/conservancy/apps/blog/admin.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
from django.contrib import admin
|
||||
from models import EntryTag, Entry
|
||||
|
||||
class EntryTagAdmin(admin.ModelAdmin):
|
||||
prepopulated_fields = {'slug': ('label',)}
|
||||
|
||||
admin.site.register(EntryTag, EntryTagAdmin)
|
||||
|
||||
class EntryAdmin(admin.ModelAdmin):
|
||||
list_display = ('pub_date', 'headline', 'author')
|
||||
list_filter = ['pub_date']
|
||||
date_hierarchy = 'pub_date'
|
||||
search_fields = ['headline', 'summary', 'body']
|
||||
prepopulated_fields = {'slug': ("headline",)}
|
||||
filter_horizontal = ('tags',)
|
||||
|
||||
|
||||
admin.site.register(Entry, EntryAdmin)
|
76
www/conservancy/apps/blog/models.py
Normal file
76
www/conservancy/apps/blog/models.py
Normal file
|
@ -0,0 +1,76 @@
|
|||
from django.db import models
|
||||
from django.conf import settings
|
||||
from sflc.apps.staff.models import Person
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
class EntryTag(models.Model):
|
||||
"""Tagging for blog entries"""
|
||||
|
||||
label = models.CharField(max_length=100)
|
||||
slug = models.SlugField()
|
||||
|
||||
class Meta:
|
||||
db_table = 'techblog_entrytag' # legacy
|
||||
|
||||
def __unicode__(self):
|
||||
return self.label
|
||||
|
||||
def get_absolute_url(self):
|
||||
return u"/blog/?tag=%s" % self.slug
|
||||
|
||||
class Entry(models.Model):
|
||||
"""Blog entry"""
|
||||
|
||||
headline = models.CharField(max_length=200)
|
||||
slug = models.SlugField(unique_for_date='pub_date')
|
||||
summary = models.TextField(help_text="Use raw HTML. Unlike in the press release model, this summary is not included at the beginning of the body when the entry is displayed.")
|
||||
body = models.TextField(help_text="Use raw HTML. Include the full body of the post.")
|
||||
pub_date = models.DateTimeField()
|
||||
author = models.ForeignKey(Person)
|
||||
tags = models.ManyToManyField(EntryTag, null=True, blank=True)
|
||||
|
||||
date_created = models.DateTimeField(auto_now_add=True)
|
||||
date_last_modified = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
db_table = 'techblog_entries' # legacy
|
||||
verbose_name_plural = 'entries'
|
||||
ordering = ('-pub_date',)
|
||||
get_latest_by = 'pub_date'
|
||||
|
||||
def __unicode__(self):
|
||||
return self.headline
|
||||
|
||||
def get_absolute_url(self):
|
||||
return (u"/blog/%s/%s/"
|
||||
% (self.pub_date.strftime("%Y/%b/%d").lower(),
|
||||
self.slug))
|
||||
|
||||
def is_recent(self):
|
||||
return self.pub_date > (datetime.now() - timedelta(days=14))
|
||||
# question: does datetime.now() do a syscall each time is it called?
|
||||
|
||||
# Ping google blogs and technorati. Taken from
|
||||
# http://blog.foozia.com/blog/2007/apr/21/ping-technorati-your-django-blog-using-xml-rpc/
|
||||
def save(self):
|
||||
if settings.SFLC_DEVEL or True: # "or True" means it is disabled always
|
||||
super(Entry, self).save()
|
||||
return
|
||||
|
||||
blog_name = 'Software Freedom Law Center Blog'
|
||||
blog_url = 'http://www.softwarefreedom.org/blog/'
|
||||
post_url = ('http://www.softwarefreedom.org'
|
||||
+ self.get_absolute_url())
|
||||
|
||||
import xmlrpclib
|
||||
|
||||
# Ping Technorati
|
||||
j = xmlrpclib.Server('http://rpc.technorati.com/rpc/ping')
|
||||
reply = j.weblogUpdates.ping(blog_name, blog_url)
|
||||
|
||||
# Ping Google Blog Search
|
||||
j = xmlrpclib.Server('http://blogsearch.google.com/ping/RPC2')
|
||||
reply = j.weblogUpdates.ping(blog_name, blog_url, post_url)
|
||||
|
||||
# Call any superclass's method
|
||||
super(Entry, self).save()
|
65
www/conservancy/apps/blog/urls.py
Normal file
65
www/conservancy/apps/blog/urls.py
Normal file
|
@ -0,0 +1,65 @@
|
|||
from django.conf.urls.defaults import *
|
||||
from models import Entry, EntryTag # relative import
|
||||
from views import last_name # relative import
|
||||
from sflc.apps.staff.models import Person
|
||||
from datetime import datetime
|
||||
|
||||
extra_context = {}
|
||||
|
||||
info_dict = {
|
||||
'queryset': Entry.objects.all(),
|
||||
'date_field': 'pub_date',
|
||||
'extra_context': extra_context,
|
||||
}
|
||||
|
||||
urlpatterns = patterns('django.views.generic.date_based',
|
||||
(r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?P<slug>[-\w]+)/$', 'object_detail', dict(info_dict, slug_field='slug')),
|
||||
(r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/$', 'archive_day', info_dict),
|
||||
(r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/$', 'archive_month', info_dict),
|
||||
(r'^(?P<year>\d{4})/$', 'archive_year', dict(info_dict,
|
||||
make_object_list=True)),
|
||||
)
|
||||
|
||||
urlpatterns += patterns('sflc.apps.blog.views',
|
||||
(r'^/?$', 'custom_index', dict(info_dict, paginate_by=10)),
|
||||
(r'^query/$', 'query'),
|
||||
)
|
||||
|
||||
# Code to display authors and tags on each blog page
|
||||
|
||||
def all_tags_by_use_amount():
|
||||
"""Returns all tags with an added 'cnt' attribute (how many times used)
|
||||
|
||||
Also sorts the tags so most-used tags appear first.
|
||||
"""
|
||||
|
||||
# tally use amount
|
||||
retval = []
|
||||
current = None
|
||||
for obj in EntryTag.objects.filter(entry__pub_date__lte=datetime.now(),
|
||||
entry__isnull=False).order_by('label'):
|
||||
if current is not None and obj.id == current.id:
|
||||
current.cnt += 1
|
||||
else:
|
||||
if current is not None:
|
||||
retval.append(current)
|
||||
current = obj
|
||||
current.cnt = 1
|
||||
if current is not None:
|
||||
retval.append(current)
|
||||
|
||||
# sort and return
|
||||
retval.sort(key=lambda x: -x.cnt)
|
||||
return retval
|
||||
|
||||
def all_authors():
|
||||
return sorted(Person.objects.filter(entry__isnull=False).distinct(),
|
||||
key=last_name)
|
||||
|
||||
# The functions are passed to the context uncalled so they will be
|
||||
# called for each web request. If we want to only make these database
|
||||
# queries a single time when a web server process begins, call both
|
||||
# functions below (i.e. make both lines below end in '()')
|
||||
|
||||
extra_context['all_authors'] = all_authors
|
||||
extra_context['all_tags'] = all_tags_by_use_amount
|
103
www/conservancy/apps/blog/views.py
Normal file
103
www/conservancy/apps/blog/views.py
Normal file
|
@ -0,0 +1,103 @@
|
|||
from models import Entry, EntryTag # relative import
|
||||
from django.views.generic.list_detail import object_list
|
||||
from sflc.apps.staff.models import Person
|
||||
from django.shortcuts import get_object_or_404, render_to_response
|
||||
from datetime import datetime
|
||||
|
||||
def OR_filter(field_name, objs):
|
||||
from django.db.models import Q
|
||||
return reduce(lambda x, y: x | y,
|
||||
[Q(**{field_name: x.id}) for x in objs])
|
||||
|
||||
def last_name(person):
|
||||
return person.formal_name.rpartition(' ')[2]
|
||||
|
||||
def custom_index(request, queryset, *args, **kwargs):
|
||||
"""Blog list view that allows scrolling and also shows an index by
|
||||
year.
|
||||
"""
|
||||
|
||||
kwargs = kwargs.copy()
|
||||
kwargs['extra_context'] = kwargs.get('extra_context', {}).copy()
|
||||
extra_context = kwargs['extra_context']
|
||||
|
||||
date_field = kwargs['date_field']
|
||||
del kwargs['date_field']
|
||||
|
||||
if not kwargs.get('allow_future', False):
|
||||
queryset = queryset.filter(**{'%s__lte' % date_field: datetime.now()})
|
||||
|
||||
authors = []
|
||||
if 'author' in request.GET:
|
||||
authors = [get_object_or_404(Person, username=author)
|
||||
for author in request.GET.getlist('author')]
|
||||
extra_context['authors'] = authors
|
||||
queryset = queryset.filter(OR_filter('author', authors))
|
||||
|
||||
tags = []
|
||||
if 'tag' in request.GET:
|
||||
tags = [get_object_or_404(EntryTag, slug=tag)
|
||||
for tag in request.GET.getlist('tag')]
|
||||
extra_context['tags'] = tags
|
||||
queryset = queryset.filter(OR_filter('tags', tags))
|
||||
|
||||
if authors or tags:
|
||||
query_string = '&'.join(['author=%s' % a.username for a in authors]
|
||||
+ ['tag=%s' % t.slug for t in tags])
|
||||
extra_context['query_string'] = query_string
|
||||
|
||||
else:
|
||||
date_list = queryset.dates(date_field, 'year')
|
||||
extra_context['date_list'] = date_list
|
||||
|
||||
return object_list(request, queryset, *args, **kwargs)
|
||||
|
||||
def techblog_redirect(request):
|
||||
"""Redirect from the old 'techblog' to the new blog
|
||||
"""
|
||||
|
||||
path = request.path[len('/technology'):]
|
||||
if path == '/blog/':
|
||||
path += "?author=bkuhn"
|
||||
|
||||
return relative_redirect(request, path)
|
||||
|
||||
def query(request):
|
||||
"""Page to query the blog based on authors and tags
|
||||
"""
|
||||
|
||||
if request.GET:
|
||||
d = request.GET.copy()
|
||||
if 'authors' in d.getlist('all'):
|
||||
d.setlist('author', []) # remove author queries
|
||||
if 'tags' in d.getlist('all'):
|
||||
d.setlist('tag', []) # remove tag queries
|
||||
d.setlist('all', []) # remove "all" from the query string
|
||||
|
||||
base_url = '/blog/'
|
||||
if 'rss' in d:
|
||||
base_url = '/feeds/blog/'
|
||||
d.setlist('rss', []) # remove it
|
||||
|
||||
query_string = d.urlencode()
|
||||
|
||||
return relative_redirect(request, '%s%s%s' % (base_url, '?' if query_string else '', query_string))
|
||||
|
||||
else:
|
||||
authors = sorted(Person.objects.filter(currently_employed=True,
|
||||
entry__isnull=False).distinct(),
|
||||
key=last_name)
|
||||
tags = EntryTag.objects.all().order_by('label')
|
||||
return render_to_response('blog/query.html',
|
||||
{'authors': authors, 'tags': tags})
|
||||
|
||||
def relative_redirect(request, path):
|
||||
from django import http
|
||||
from django.conf import settings
|
||||
|
||||
host = http.get_host(request)
|
||||
if settings.FORCE_CANONICAL_HOSTNAME:
|
||||
host = settings.FORCE_CANONICAL_HOSTNAME
|
||||
|
||||
url = "%s://%s%s" % (request.is_secure() and 'https' or 'http', host, path)
|
||||
return http.HttpResponseRedirect(url)
|
0
www/conservancy/apps/contacts/__init__.py
Normal file
0
www/conservancy/apps/contacts/__init__.py
Normal file
8
www/conservancy/apps/contacts/admin.py
Normal file
8
www/conservancy/apps/contacts/admin.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
from django.contrib import admin
|
||||
from models import ContactEntry
|
||||
|
||||
class ContactEntryAdmin(admin.ModelAdmin):
|
||||
list_display = ('email', 'subscribe_sflc', 'subscribe_sfc')
|
||||
|
||||
|
||||
admin.site.register(ContactEntry, ContactEntryAdmin)
|
14
www/conservancy/apps/contacts/models.py
Normal file
14
www/conservancy/apps/contacts/models.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
from django.db import models
|
||||
|
||||
class ContactEntry(models.Model):
|
||||
"""SFLC contact system
|
||||
|
||||
Hopefully this will be deprecated soon"""
|
||||
|
||||
email = models.EmailField() # should make it unique, but we really cannot
|
||||
subscribe_sflc = models.BooleanField()
|
||||
subscribe_sfc = models.BooleanField()
|
||||
|
||||
class Meta:
|
||||
ordering = ('email',)
|
||||
|
5
www/conservancy/apps/contacts/urls.py
Normal file
5
www/conservancy/apps/contacts/urls.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from django.conf.urls.defaults import *
|
||||
|
||||
urlpatterns = patterns('sflc.apps.contacts.views',
|
||||
(r'^/?$', 'subscribe'),
|
||||
)
|
27
www/conservancy/apps/contacts/views.py
Normal file
27
www/conservancy/apps/contacts/views.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
from django.shortcuts import render_to_response
|
||||
from django import forms
|
||||
from models import ContactEntry
|
||||
from django.forms import ModelForm
|
||||
|
||||
def subscribe(request):
|
||||
"""Mailing list subscription form
|
||||
"""
|
||||
|
||||
class ContactEntryForm(ModelForm):
|
||||
class Meta:
|
||||
model = ContactEntry
|
||||
|
||||
ContactEntryForm.base_fields['subscribe_sflc'].label = 'Receive Software Freedom Law Center updates'
|
||||
ContactEntryForm.base_fields['subscribe_sfc'].label = 'Receive Software Freedom Conservancy updates'
|
||||
|
||||
if request.method == 'POST':
|
||||
form = ContactEntryForm(request.POST)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return render_to_response('contacts/subscribe_success.html',
|
||||
{'form': form.cleaned_data})
|
||||
else:
|
||||
form = ContactEntryForm()
|
||||
|
||||
return render_to_response('contacts/subscribe.html',
|
||||
{'form': form})
|
0
www/conservancy/apps/events/__init__.py
Normal file
0
www/conservancy/apps/events/__init__.py
Normal file
20
www/conservancy/apps/events/admin.py
Normal file
20
www/conservancy/apps/events/admin.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
from django.contrib import admin
|
||||
from models import EventTag, Event, EventMedia
|
||||
|
||||
admin.site.register(EventTag)
|
||||
|
||||
class EventAdmin(admin.ModelAdmin):
|
||||
list_display = ("title", "date", "date_tentative", "location")
|
||||
list_filter = ['date']
|
||||
date_hierarchy = 'date'
|
||||
search_fields = ["title", "description", "earth_location"]
|
||||
prepopulated_fields = {'slug' : ("title",) }
|
||||
|
||||
admin.site.register(Event, EventAdmin)
|
||||
|
||||
class EventMediaAdmin(admin.ModelAdmin):
|
||||
list_display = ("event", "format", "novel")
|
||||
|
||||
admin.site.register(EventMedia, EventMediaAdmin)
|
||||
|
||||
|
93
www/conservancy/apps/events/models.py
Normal file
93
www/conservancy/apps/events/models.py
Normal file
|
@ -0,0 +1,93 @@
|
|||
from django.db import models
|
||||
from sflc.apps.staff.models import Person
|
||||
from sflc.apps.worldmap.models import EarthLocation
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
class EventTag(models.Model):
|
||||
"""Tagging for events
|
||||
|
||||
(currently unused)
|
||||
"""
|
||||
|
||||
label = models.CharField(max_length=100)
|
||||
|
||||
date_created = models.DateField(auto_now_add=True)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.label
|
||||
|
||||
class PastEventManager(models.Manager):
|
||||
"""Returns all past events"""
|
||||
|
||||
def get_query_set(self):
|
||||
return super(PastEventManager, self).get_query_set().filter(date__lt=datetime.today())
|
||||
|
||||
class FutureEventManager(models.Manager):
|
||||
"""Returns all future events"""
|
||||
|
||||
def get_query_set(self):
|
||||
return super(FutureEventManager, self).get_query_set().filter(date__gte=datetime.today())
|
||||
|
||||
class Event(models.Model):
|
||||
"""Model for SFLC staff member events (presentations, etc)"""
|
||||
|
||||
title = models.CharField(max_length=400)
|
||||
date = models.DateField()
|
||||
date_tentative = models.BooleanField()
|
||||
datetime = models.CharField("Date and Time", max_length=300, blank=True)
|
||||
slug = models.SlugField(unique_for_year='date')
|
||||
description = models.TextField(blank=True)
|
||||
people = models.ManyToManyField(Person, null=True, blank=True)
|
||||
location = models.CharField(max_length=1000)
|
||||
earth_location = models.ForeignKey(EarthLocation, null=True, blank=True,
|
||||
help_text="Label will not be displayed")
|
||||
tags = models.ManyToManyField(EventTag, null=True, blank=True)
|
||||
|
||||
date_created = models.DateTimeField(auto_now_add=True)
|
||||
date_last_modified = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ("-date",)
|
||||
|
||||
def __unicode__(self):
|
||||
return u"%s (%s)" % (self.title, self.date)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return u"/events/%s/%s/" % (self.date.strftime("%Y"), self.slug)
|
||||
|
||||
def day_after(self):
|
||||
return self.date + timedelta(days=1)
|
||||
|
||||
# for aggregate feed
|
||||
pub_date = property(lambda self: self.date_created)
|
||||
|
||||
objects = models.Manager()
|
||||
past = PastEventManager()
|
||||
future = FutureEventManager()
|
||||
|
||||
class EventMedia(models.Model):
|
||||
"""Media from an event
|
||||
|
||||
includes transcripts, audio, and video pieces
|
||||
"""
|
||||
|
||||
event = models.ForeignKey(Event)
|
||||
format = models.CharField(max_length=1,
|
||||
choices=(('T', 'Transcript'),
|
||||
('A', 'Audio'),
|
||||
('V', 'Video')))
|
||||
local = models.CharField(max_length=300, blank=True,
|
||||
help_text="Local filename of the resource. File should be uploaded into the static directory that corresponds to the event.")
|
||||
remote = models.URLField(blank=True, verify_exists=False,
|
||||
help_text="Remote URL of the resource. Required if 'local' is not given.")
|
||||
novel = models.BooleanField(help_text="Is it a new piece of media or another form of an old one? If it is new it will be included in the event-media RSS feed and shown on the front page for a bit.")
|
||||
|
||||
date_created = models.DateTimeField(auto_now_add=True)
|
||||
date_last_modified = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = 'event media'
|
||||
|
||||
def __unicode__(self):
|
||||
return u"%s media: %s" % (self.event, self.format)
|
||||
|
19
www/conservancy/apps/events/urls.py
Normal file
19
www/conservancy/apps/events/urls.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
from django.conf.urls.defaults import *
|
||||
from models import Event # relative import
|
||||
|
||||
info_dict = {
|
||||
'queryset': Event.objects.all(),
|
||||
'date_field': 'date',
|
||||
'allow_future': True,
|
||||
}
|
||||
|
||||
urlpatterns = patterns('django.views.generic.date_based',
|
||||
(r'^(?P<year>\d{4})/$', 'archive_year', dict(info_dict,
|
||||
make_object_list=True)),
|
||||
)
|
||||
|
||||
urlpatterns += patterns('sflc.apps.events.views',
|
||||
(r'^/?$', 'custom_index', dict(info_dict, queryset=Event.past.all(), paginate_by=10)),
|
||||
(r'^(?P<year>\d{4})/(?P<slug>[-\w]+)/$', 'event_detail', dict(info_dict, slug_field='slug')),
|
||||
(r'^ics/$', 'future_event_ics', info_dict),
|
||||
)
|
20
www/conservancy/apps/events/view_helpers.py
Normal file
20
www/conservancy/apps/events/view_helpers.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
def organize_media_by_event(eventmedia_queryset):
|
||||
"""Organizes event media by event.
|
||||
|
||||
Given a queryset of event media, it returns a list of 'objects'
|
||||
with the following properties:
|
||||
|
||||
* event (event object)
|
||||
* date (date object for most recently posted media from event)
|
||||
* media_list (a string of the available media types)
|
||||
"""
|
||||
|
||||
media_by_event = {}
|
||||
for media in eventmedia_queryset:
|
||||
media_by_event.setdefault(media.event.id, []).append(media)
|
||||
mbe = [{'event': x[0].event,
|
||||
'date': max(y.date_created for y in x),
|
||||
'media_list': ', '.join(set(y.get_format_display() for y in x))}
|
||||
for x in media_by_event.values()]
|
||||
mbe.sort(key=(lambda x: x['date']), reverse=True) # sort by date
|
||||
return mbe
|
56
www/conservancy/apps/events/views.py
Normal file
56
www/conservancy/apps/events/views.py
Normal file
|
@ -0,0 +1,56 @@
|
|||
from django.views.generic.list_detail import object_list
|
||||
from django.shortcuts import render_to_response
|
||||
from django.http import Http404, HttpResponse
|
||||
from django.template import loader
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from models import Event # relative import
|
||||
|
||||
def event_detail(request, year, slug, queryset, **kwargs):
|
||||
"""This view shows event detail.
|
||||
|
||||
Nothing special, but it is necessary because
|
||||
django.views.generic.date_based.object_detail only works with
|
||||
slugs that are unique and specified by day, but we make slugs
|
||||
unique by year.
|
||||
"""
|
||||
|
||||
try:
|
||||
event = queryset.get(date__year=year, slug__exact=slug)
|
||||
except ObjectDoesNotExist:
|
||||
raise Http404, "Event does not exist"
|
||||
return render_to_response('events/event_detail.html', {'event': event})
|
||||
|
||||
def custom_index(request, queryset, *args, **kwargs):
|
||||
"""Scrollable index of future and past events, with date index.
|
||||
"""
|
||||
|
||||
future_events = None
|
||||
if not request.GET.has_key("page"):
|
||||
future_events = Event.future.all().order_by("date")
|
||||
|
||||
date_list = queryset.dates(kwargs['date_field'], 'year')
|
||||
|
||||
kwargs = dict(kwargs, extra_context={'date_list': date_list,
|
||||
'future_events': future_events})
|
||||
del kwargs['date_field']
|
||||
del kwargs['allow_future']
|
||||
|
||||
return object_list(request, queryset, *args, **kwargs)
|
||||
|
||||
def future_event_ics(request, queryset, *args, **kwargs):
|
||||
"""ICS calendar view of future events
|
||||
|
||||
This view just renders information into a template that looks like
|
||||
an ics file. If in the future we want a 'real' implementation of
|
||||
this function, there is a python 'vobject' library that can be
|
||||
used. Search google for details, or see
|
||||
http://www.technobabble.dk/2008/mar/06/exposing-calendar-events-using-icalendar-django/
|
||||
Hopefully at some point this functionality is integrated into
|
||||
django.contrib.
|
||||
"""
|
||||
|
||||
future_events = Event.future.all().order_by("date")
|
||||
|
||||
return HttpResponse(loader.render_to_string('events/calendar.ics',
|
||||
{'events': future_events}),
|
||||
mimetype='text/calendar')
|
0
www/conservancy/apps/news/__init__.py
Normal file
0
www/conservancy/apps/news/__init__.py
Normal file
23
www/conservancy/apps/news/admin.py
Normal file
23
www/conservancy/apps/news/admin.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
from django.contrib import admin
|
||||
from models import PressRelease, ExternalArticleTag, ExternalArticle
|
||||
|
||||
class PressReleaseAdmin(admin.ModelAdmin):
|
||||
list_display = ("headline", "pub_date")
|
||||
list_filter = ['pub_date']
|
||||
date_hierarchy = 'pub_date'
|
||||
search_fields = ['headline', 'summary', 'body']
|
||||
prepopulated_fields = { 'slug' : ("headline",), }
|
||||
|
||||
admin.site.register(PressRelease, PressReleaseAdmin)
|
||||
admin.site.register(ExternalArticleTag)
|
||||
|
||||
class ExternalArticleAdmin(admin.ModelAdmin):
|
||||
list_display = ("title", "publication", "visible", "date")
|
||||
list_filter = ['date']
|
||||
date_hierarchy = 'date'
|
||||
search_fields = ["title", "info", "publication"]
|
||||
|
||||
admin.site.register(ExternalArticle, ExternalArticleAdmin)
|
||||
|
||||
|
||||
|
110
www/conservancy/apps/news/models.py
Normal file
110
www/conservancy/apps/news/models.py
Normal file
|
@ -0,0 +1,110 @@
|
|||
from django.db import models
|
||||
from django.conf import settings
|
||||
from sflc.apps.staff.models import Person
|
||||
from sflc.apps.events.models import Event
|
||||
from django.contrib.sites.models import Site
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
class PressRelease(models.Model):
|
||||
"""News release model"""
|
||||
|
||||
headline = models.CharField(max_length=300)
|
||||
subhead = models.CharField(max_length=300, blank=True)
|
||||
slug = models.SlugField(unique_for_date="pub_date",
|
||||
help_text=("automatically built from headline"))
|
||||
summary = models.TextField(help_text="First paragraph (raw HTML)")
|
||||
body = models.TextField(help_text="Remainder of post (raw HTML)",
|
||||
blank=True)
|
||||
pub_date = models.DateTimeField("date [to be] published")
|
||||
sites = models.ManyToManyField(Site)
|
||||
|
||||
date_last_modified = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ("-pub_date",)
|
||||
get_latest_by = "pub_date"
|
||||
|
||||
def __unicode__(self):
|
||||
return self.headline
|
||||
|
||||
def get_absolute_url(self):
|
||||
return u"/news/%s/%s/" % (self.pub_date.strftime("%Y/%b/%d").lower(),
|
||||
self.slug)
|
||||
|
||||
def is_recent(self):
|
||||
return self.pub_date > (datetime.now() - timedelta(days=5))
|
||||
# question: does datetime.now() do a syscall each time is it called?
|
||||
|
||||
def is_in_past_month(self):
|
||||
# This function is deprecated. Use the date_within template
|
||||
# filter instead (example in sflc/templates/frontpage.html)
|
||||
return self.pub_date > (datetime.now() - timedelta(days=30))
|
||||
|
||||
def save(self):
|
||||
if settings.SFLC_DEVEL or True:
|
||||
super(PressRelease, self).save()
|
||||
return
|
||||
|
||||
blog_name = 'Software Freedom Law Center News'
|
||||
blog_url = 'http://www.softwarefreedom.org/news/'
|
||||
post_url = ('http://www.softwarefreedom.org'
|
||||
+ self.get_absolute_url())
|
||||
|
||||
import xmlrpclib
|
||||
|
||||
# Ping Technorati
|
||||
j = xmlrpclib.Server('http://rpc.technorati.com/rpc/ping')
|
||||
reply = j.weblogUpdates.ping(blog_name, blog_url)
|
||||
|
||||
# Ping Google Blog Search
|
||||
j = xmlrpclib.Server('http://blogsearch.google.com/ping/RPC2')
|
||||
reply = j.weblogUpdates.ping(blog_name, blog_url, post_url)
|
||||
|
||||
# Call any superclass's method
|
||||
super(PressRelease, self).save()
|
||||
|
||||
class ExternalArticleTag(models.Model):
|
||||
"""A way to tag external articles"""
|
||||
|
||||
label = models.CharField(max_length=100)
|
||||
|
||||
date_created = models.DateField(auto_now_add=True)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.label
|
||||
|
||||
class PublicExternalArticleManager(models.Manager):
|
||||
def get_query_set(self):
|
||||
return super(PublicExternalArticleManager, self).get_query_set().filter(visible=True)
|
||||
|
||||
class ExternalArticle(models.Model):
|
||||
"""A system for displaying SFLC news mentions on the site.
|
||||
|
||||
(Currently unused)
|
||||
"""
|
||||
|
||||
title = models.CharField(max_length=400)
|
||||
info = models.CharField(help_text="subscribers only? audio? pdf warning?",
|
||||
blank=True, max_length=300)
|
||||
publication = models.CharField("source of article", max_length=300)
|
||||
url = models.URLField(blank=True, verify_exists=False)
|
||||
date = models.DateField()
|
||||
visible = models.BooleanField(help_text="Whether to display on website")
|
||||
|
||||
tags = models.ManyToManyField(ExternalArticleTag, null=True, blank=True)
|
||||
people = models.ManyToManyField(Person, null=True, blank=True)
|
||||
event = models.ForeignKey(Event, null=True, blank=True)
|
||||
press_release = models.ForeignKey(PressRelease, null=True, blank=True)
|
||||
|
||||
date_created = models.DateField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ("-date_created",)
|
||||
get_latest_by = "date_created"
|
||||
|
||||
def __unicode__(self):
|
||||
return u"%s (%s)" % (self.title, self.publication)
|
||||
|
||||
objects = models.Manager()
|
||||
public = PublicExternalArticleManager()
|
||||
|
0
www/conservancy/apps/news/templatetags/__init__.py
Normal file
0
www/conservancy/apps/news/templatetags/__init__.py
Normal file
9
www/conservancy/apps/news/templatetags/date_within.py
Normal file
9
www/conservancy/apps/news/templatetags/date_within.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from django import template
|
||||
from datetime import timedelta, datetime
|
||||
|
||||
register = template.Library()
|
||||
|
||||
@register.filter
|
||||
def date_within_past_days(value, arg):
|
||||
# question: does datetime.now() do a syscall each time is it called?
|
||||
return value > (datetime.now() - timedelta(days=int(arg)))
|
24
www/conservancy/apps/news/urls.py
Normal file
24
www/conservancy/apps/news/urls.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
from django.conf.urls.defaults import *
|
||||
from django.conf import settings
|
||||
from models import PressRelease, ExternalArticle # relative import
|
||||
|
||||
info_dict = {
|
||||
'queryset': PressRelease.objects.all().filter(sites__id__exact=settings.SITE_ID),
|
||||
'date_field': 'pub_date',
|
||||
}
|
||||
|
||||
external_article_dict = {
|
||||
'articles': ExternalArticle.objects.all()
|
||||
}
|
||||
|
||||
urlpatterns = patterns('django.views.generic.date_based',
|
||||
(r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?P<slug>[-\w]+)/$', 'object_detail', dict(info_dict, slug_field='slug')),
|
||||
(r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/$', 'archive_day', info_dict),
|
||||
(r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/$', 'archive_month', info_dict),
|
||||
(r'^(?P<year>\d{4})/$', 'archive_year', dict(info_dict,
|
||||
make_object_list=True)),
|
||||
)
|
||||
|
||||
urlpatterns += patterns('',
|
||||
(r'^/?$', 'sflc.apps.news.views.custom_index', dict(info_dict, paginate_by=6)),
|
||||
)
|
35
www/conservancy/apps/news/views.py
Normal file
35
www/conservancy/apps/news/views.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
from django.views.generic.list_detail import object_list
|
||||
from sflc.apps.news.models import ExternalArticle
|
||||
from sflc.apps.events.models import Event
|
||||
from datetime import datetime
|
||||
|
||||
def custom_index(request, queryset, *args, **kwargs):
|
||||
"""News index. Calls a generic list view, but passes additional
|
||||
context including past and future events, and an index of news by
|
||||
year.
|
||||
"""
|
||||
|
||||
articles = None
|
||||
#if not request.GET.has_key("page"):
|
||||
# articles = ExternalArticle.public.all().order_by("-date")[:10]
|
||||
|
||||
if (not kwargs.has_key('allow_future')) or not kwargs['allow_future']:
|
||||
queryset = queryset.filter(**{'%s__lte' % kwargs['date_field']:
|
||||
datetime.now()})
|
||||
|
||||
future_events = Event.future.all().filter(date_tentative=False).order_by("date")
|
||||
past_events = Event.past.all().order_by("-date")[:6]
|
||||
|
||||
date_list = queryset.dates(kwargs['date_field'], 'year')
|
||||
|
||||
kwargs = dict(kwargs, extra_context={'articles': articles,
|
||||
'date_list': date_list,
|
||||
'future_events': future_events,
|
||||
'past_events': past_events})
|
||||
del kwargs['date_field']
|
||||
|
||||
return object_list(request, queryset, *args, **kwargs)
|
||||
|
||||
# num_navigation = 3 # in each direction
|
||||
# page_navigation = range(max((page - num_navigation), 1),
|
||||
# min((page + num_navigation), page_count) + 1)
|
0
www/conservancy/apps/podcast/__init__.py
Normal file
0
www/conservancy/apps/podcast/__init__.py
Normal file
18
www/conservancy/apps/podcast/admin.py
Normal file
18
www/conservancy/apps/podcast/admin.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
from django.contrib import admin
|
||||
from models import PodcastTag, Podcast
|
||||
|
||||
class PodcastTagAdmin(admin.ModelAdmin):
|
||||
prepopulated_fields = {'slug': ('label',)}
|
||||
|
||||
admin.site.register(PodcastTag, PodcastTagAdmin)
|
||||
|
||||
class PodcastAdmin(admin.ModelAdmin):
|
||||
list_display = ('pub_date', 'title')
|
||||
list_filter = ['pub_date']
|
||||
date_hierarchy = 'pub_date'
|
||||
search_fields = ['title', 'summary', 'body']
|
||||
prepopulated_fields = {'slug': ("title",)}
|
||||
filter_horizontal = ('tags',)
|
||||
|
||||
|
||||
admin.site.register(Podcast, PodcastAdmin)
|
58
www/conservancy/apps/podcast/models.py
Normal file
58
www/conservancy/apps/podcast/models.py
Normal file
|
@ -0,0 +1,58 @@
|
|||
from django.db import models
|
||||
from django.conf import settings
|
||||
from sflc.apps.staff.models import Person
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
class PodcastTag(models.Model):
|
||||
"""Tagging for podcasts"""
|
||||
|
||||
label = models.CharField(max_length=100)
|
||||
slug = models.SlugField()
|
||||
|
||||
class Meta:
|
||||
db_table = 'podcast_tags' # legacy
|
||||
|
||||
def __unicode__(self):
|
||||
return self.label
|
||||
|
||||
def get_absolute_url(self):
|
||||
return u"/podcast/?tag=%s" % self.slug
|
||||
|
||||
class Podcast(models.Model):
|
||||
"""Podcast"""
|
||||
|
||||
title = models.CharField(max_length=200)
|
||||
slug = models.SlugField(unique=True)
|
||||
summary = models.TextField(help_text="Use raw HTML. This summary is not included at the beginning of the body when the entry is displayed. It used only for the material on the front page.")
|
||||
body = models.TextField(help_text="Use raw HTML. Include the full body of any show notes or other information about this episode. It will be labelled on the site as Show Notes. It is included on the detail entry, and in the description data on the podcast RSS feed.")
|
||||
pub_date = models.DateTimeField()
|
||||
poster = models.ForeignKey(Person)
|
||||
tags = models.ManyToManyField(PodcastTag, null=True, blank=True)
|
||||
ogg_path = models.CharField(max_length=300, blank=True,
|
||||
help_text="Local filename of the Ogg file, relative to webroot. File should be uploaded into the static media area for podcasts.")
|
||||
mp3_path = models.CharField(max_length=300, blank=True,
|
||||
help_text="Local filename of the mp3 file, relative to webroot. File should be uploaded into the static media area for podcasts.")
|
||||
ogg_length = models.IntegerField(blank=False, help_text="size in bytes of ogg file")
|
||||
mp3_length = models.IntegerField(blank=False, help_text="size in bytes of mp3 file")
|
||||
duration = models.CharField(max_length=8, blank=False, help_text="length in hh:mm:ss of mp3 file")
|
||||
date_created = models.DateTimeField(auto_now_add=True)
|
||||
date_last_modified = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
db_table = 'podcasts_entries' # legacy
|
||||
verbose_name_plural = 'podcasts'
|
||||
ordering = ('-pub_date',)
|
||||
get_latest_by = 'pub_date'
|
||||
|
||||
def __unicode__(self):
|
||||
return self.title
|
||||
|
||||
def get_absolute_url(self):
|
||||
return u"/podcast/%s/%s/" % (self.pub_date.strftime("%Y/%b/%d").lower(),
|
||||
self.slug)
|
||||
# FIXME
|
||||
# return (u"/podcast/%s/" % (self.slug))
|
||||
|
||||
def is_recent(self):
|
||||
return self.pub_date > (datetime.now() - timedelta(days=14))
|
||||
# question: does datetime.now() do a syscall each time is it called?
|
61
www/conservancy/apps/podcast/urls.py
Normal file
61
www/conservancy/apps/podcast/urls.py
Normal file
|
@ -0,0 +1,61 @@
|
|||
from django.conf.urls.defaults import *
|
||||
from models import Podcast, PodcastTag # relative import
|
||||
from sflc.apps.staff.models import Person
|
||||
from datetime import datetime
|
||||
|
||||
extra_context = {}
|
||||
|
||||
info_dict = {
|
||||
'queryset': Podcast.objects.all(),
|
||||
'date_field': 'pub_date',
|
||||
'extra_context': extra_context,
|
||||
}
|
||||
|
||||
urlpatterns = patterns('django.views.generic.date_based',
|
||||
(r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?P<slug>[-\w]+)/$', 'object_detail', dict(info_dict, slug_field='slug')),
|
||||
(r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/$', 'archive_day', info_dict),
|
||||
(r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/$', 'archive_month', info_dict),
|
||||
(r'^(?P<year>\d{4})/$', 'archive_year', dict(info_dict,
|
||||
make_object_list=True)),
|
||||
# FIXME HOW DO I MAKE THE SLUG WORK WITH NO DATES IN IT.
|
||||
# (r'^(?P<slug>[-\w]+)/$', 'object_detail', dict(info_dict, slug_field='slug')),
|
||||
)
|
||||
|
||||
urlpatterns += patterns('sflc.apps.podcast.views',
|
||||
(r'^/?$', 'custom_index', dict(info_dict, paginate_by=20)),
|
||||
(r'^query/$', 'query'),
|
||||
)
|
||||
|
||||
# Code to display authors and tags on each blog page
|
||||
|
||||
def all_tags_by_use_amount():
|
||||
"""Returns all tags with an added 'cnt' attribute (how many times used)
|
||||
|
||||
Also sorts the tags so most-used tags appear first.
|
||||
"""
|
||||
|
||||
# tally use amount
|
||||
retval = []
|
||||
current = None
|
||||
for obj in PodcastTag.objects.filter(podcast__pub_date__lte=datetime.now(),
|
||||
podcast__isnull=False).order_by('label'):
|
||||
if current is not None and obj.id == current.id:
|
||||
current.cnt += 1
|
||||
else:
|
||||
if current is not None:
|
||||
retval.append(current)
|
||||
current = obj
|
||||
current.cnt = 1
|
||||
if current is not None:
|
||||
retval.append(current)
|
||||
|
||||
# sort and return
|
||||
retval.sort(key=lambda x: -x.cnt)
|
||||
return retval
|
||||
|
||||
# The functions are passed to the context uncalled so they will be
|
||||
# called for each web request. If we want to only make these database
|
||||
# queries a single time when a web server process begins, call both
|
||||
# functions below (i.e. make both lines below end in '()')
|
||||
|
||||
extra_context['all_tags'] = all_tags_by_use_amount
|
89
www/conservancy/apps/podcast/views.py
Normal file
89
www/conservancy/apps/podcast/views.py
Normal file
|
@ -0,0 +1,89 @@
|
|||
from models import Podcast, PodcastTag # relative import
|
||||
from django.views.generic.list_detail import object_list
|
||||
from sflc.apps.staff.models import Person
|
||||
from django.shortcuts import get_object_or_404, render_to_response
|
||||
from datetime import datetime
|
||||
|
||||
def OR_filter(field_name, objs):
|
||||
from django.db.models import Q
|
||||
return reduce(lambda x, y: x | y,
|
||||
[Q(**{field_name: x.id}) for x in objs])
|
||||
|
||||
def last_name(person):
|
||||
return person.formal_name.rpartition(' ')[2]
|
||||
|
||||
def custom_index(request, queryset, *args, **kwargs):
|
||||
"""Podcast list view that allows scrolling and also shows an index by
|
||||
year.
|
||||
"""
|
||||
|
||||
kwargs = kwargs.copy()
|
||||
kwargs['extra_context'] = kwargs.get('extra_context', {}).copy()
|
||||
extra_context = kwargs['extra_context']
|
||||
|
||||
date_field = kwargs['date_field']
|
||||
del kwargs['date_field']
|
||||
|
||||
if not kwargs.get('allow_future', False):
|
||||
queryset = queryset.filter(**{'%s__lte' % date_field: datetime.now()})
|
||||
|
||||
authors = []
|
||||
if 'author' in request.GET:
|
||||
authors = [get_object_or_404(Person, username=author)
|
||||
for author in request.GET.getlist('author')]
|
||||
extra_context['authors'] = authors
|
||||
queryset = queryset.filter(OR_filter('author', authors))
|
||||
|
||||
tags = []
|
||||
if 'tag' in request.GET:
|
||||
tags = [get_object_or_404(PodcastTag, slug=tag)
|
||||
for tag in request.GET.getlist('tag')]
|
||||
extra_context['tags'] = tags
|
||||
queryset = queryset.filter(OR_filter('tags', tags))
|
||||
|
||||
if authors or tags:
|
||||
query_string = '&'.join(['author=%s' % a.username for a in authors]
|
||||
+ ['tag=%s' % t.slug for t in tags])
|
||||
extra_context['query_string'] = query_string
|
||||
|
||||
else:
|
||||
date_list = queryset.dates(date_field, 'year')
|
||||
extra_context['date_list'] = date_list
|
||||
|
||||
return object_list(request, queryset, *args, **kwargs)
|
||||
|
||||
def query(request):
|
||||
"""Page to query the podcast based on and tags
|
||||
"""
|
||||
|
||||
if request.GET:
|
||||
d = request.GET.copy()
|
||||
if 'authors' in d.getlist('all'):
|
||||
d.setlist('author', []) # remove author queries
|
||||
if 'tags' in d.getlist('all'):
|
||||
d.setlist('tag', []) # remove tag queries
|
||||
d.setlist('all', []) # remove "all" from the query string
|
||||
|
||||
base_url = '/podcast/'
|
||||
if 'rss' in d:
|
||||
base_url = '/feeds/podcast/'
|
||||
d.setlist('rss', []) # remove it
|
||||
|
||||
query_string = d.urlencode()
|
||||
|
||||
return relative_redirect(request, '%s%s%s' % (base_url, '?' if query_string else '', query_string))
|
||||
|
||||
else:
|
||||
tags = PodcastTag.objects.all().order_by('label')
|
||||
return render_to_response('podcast/query.html', {'tags': tags})
|
||||
|
||||
def relative_redirect(request, path):
|
||||
from django import http
|
||||
from django.conf import settings
|
||||
|
||||
host = http.get_host(request)
|
||||
if settings.FORCE_CANONICAL_HOSTNAME:
|
||||
host = settings.FORCE_CANONICAL_HOSTNAME
|
||||
|
||||
url = "%s://%s%s" % (request.is_secure() and 'https' or 'http', host, path)
|
||||
return http.HttpResponseRedirect(url)
|
0
www/conservancy/apps/staff/__init__.py
Normal file
0
www/conservancy/apps/staff/__init__.py
Normal file
9
www/conservancy/apps/staff/admin.py
Normal file
9
www/conservancy/apps/staff/admin.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from django.contrib import admin
|
||||
from models import Person
|
||||
|
||||
class PersonAdmin(admin.ModelAdmin):
|
||||
list_display = ("username", "formal_name", "casual_name",
|
||||
"currently_employed")
|
||||
list_filter = ["currently_employed"]
|
||||
|
||||
admin.site.register(Person, PersonAdmin)
|
30
www/conservancy/apps/staff/models.py
Normal file
30
www/conservancy/apps/staff/models.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
from django.db import models
|
||||
|
||||
class Person(models.Model):
|
||||
"""Staff members
|
||||
|
||||
Referenced from other models (blog, events, etc)
|
||||
"""
|
||||
|
||||
username = models.CharField(max_length=20)
|
||||
formal_name = models.CharField(max_length=200)
|
||||
casual_name = models.CharField(max_length=200)
|
||||
# title = models.CharField(max_length=200, blank=True)
|
||||
# biography = models.TextField(blank=True)
|
||||
# phone = models.CharField(max_length=30, blank=True)
|
||||
# gpg_key = models.TextField(blank=True)
|
||||
# gpg_fingerprint = models.CharField(max_length=100, blank=True)
|
||||
currently_employed = models.BooleanField(default=True)
|
||||
|
||||
date_created = models.DateTimeField(auto_now_add=True)
|
||||
date_last_modified = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = 'people'
|
||||
|
||||
def __unicode__(self):
|
||||
return self.username
|
||||
|
||||
def biography_url(self):
|
||||
return u"/about/team/#%s" % self.username
|
||||
|
0
www/conservancy/apps/summit_registration/__init__.py
Normal file
0
www/conservancy/apps/summit_registration/__init__.py
Normal file
8
www/conservancy/apps/summit_registration/admin.py
Normal file
8
www/conservancy/apps/summit_registration/admin.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
from django.contrib import admin
|
||||
from models import SummitRegistration
|
||||
|
||||
class SummitRegistrationAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'email', 'affiliation', 'cle_credit')
|
||||
|
||||
admin.site.register(SummitRegistration, SummitRegistrationAdmin)
|
||||
|
16
www/conservancy/apps/summit_registration/models.py
Normal file
16
www/conservancy/apps/summit_registration/models.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
from django.db import models
|
||||
|
||||
class SummitRegistration(models.Model):
|
||||
"""Form fields for summit registrants"""
|
||||
|
||||
name = models.CharField(max_length=300)
|
||||
affiliation = models.CharField(max_length=700, blank=True)
|
||||
address = models.TextField(blank=True)
|
||||
email = models.EmailField(blank=True)
|
||||
phone = models.CharField(max_length=100, blank=True)
|
||||
date_created = models.DateField(auto_now_add=True)
|
||||
cle_credit = models.BooleanField(null=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ('name',)
|
||||
|
5
www/conservancy/apps/summit_registration/urls.py
Normal file
5
www/conservancy/apps/summit_registration/urls.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from django.conf.urls.defaults import *
|
||||
|
||||
urlpatterns = patterns('sflc.apps.summit_registration.views',
|
||||
(r'^/?$', 'register'),
|
||||
)
|
28
www/conservancy/apps/summit_registration/views.py
Normal file
28
www/conservancy/apps/summit_registration/views.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
from django.shortcuts import render_to_response
|
||||
from django import forms
|
||||
from models import SummitRegistration
|
||||
|
||||
def register(request):
|
||||
"""Summit registration form view
|
||||
"""
|
||||
|
||||
class SummitForm(ModelForm):
|
||||
class Meta:
|
||||
model = SummitRegistration
|
||||
|
||||
SummitForm.base_fields['email'].label = 'Email address'
|
||||
SummitForm.base_fields['phone'].label = 'Phone number'
|
||||
SummitForm.base_fields['address'].label = 'Mailing address'
|
||||
SummitForm.base_fields['cle_credit'].label = 'Attending for CLE credit?'
|
||||
|
||||
if request.method == 'POST':
|
||||
form = SummitForm(request.POST)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
return render_to_response('summit_registration/register_success.html',
|
||||
{'form': form.cleaned_data})
|
||||
else:
|
||||
form = SummitForm()
|
||||
|
||||
return render_to_response('summit_registration/register.html',
|
||||
{'form': form})
|
9
www/conservancy/apps/worldmap/README
Normal file
9
www/conservancy/apps/worldmap/README
Normal file
|
@ -0,0 +1,9 @@
|
|||
map comes from http://en.wikipedia.org/wiki/Image:BlankMap-World6.svg
|
||||
on jan 19, 2007. It is said to be in the public domain, and it is said
|
||||
to use Robinson projection.
|
||||
|
||||
permalink:
|
||||
http://en.wikipedia.org/w/index.php?title=Image:BlankMap-World6.svg&oldid=90903834
|
||||
|
||||
A more colorful version is at:
|
||||
http://en.wikipedia.org/wiki/Image:Robinson-projection.jpg
|
0
www/conservancy/apps/worldmap/__init__.py
Normal file
0
www/conservancy/apps/worldmap/__init__.py
Normal file
7
www/conservancy/apps/worldmap/admin.py
Normal file
7
www/conservancy/apps/worldmap/admin.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
from django.contrib import admin
|
||||
from models import EarthLocation
|
||||
|
||||
class EarthLocationAdmin(admin.ModelAdmin):
|
||||
list_display = ("label", "html_map_link")
|
||||
|
||||
admin.site.register(EarthLocation, EarthLocationAdmin)
|
28
www/conservancy/apps/worldmap/models.py
Normal file
28
www/conservancy/apps/worldmap/models.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
from django.db import models
|
||||
|
||||
class EarthLocation(models.Model):
|
||||
"""Represents latitude and longitude, with a label"""
|
||||
|
||||
label = models.CharField(max_length=300, unique=True)
|
||||
latitude = models.DecimalField(max_digits=9, decimal_places=6)
|
||||
longitude = models.DecimalField(max_digits=9, decimal_places=6)
|
||||
|
||||
date_created = models.DateTimeField(auto_now_add=True)
|
||||
date_last_modified = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
unique_together = (("latitude", "longitude"),)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.label
|
||||
|
||||
def google_maps_link(self):
|
||||
return ("http://maps.google.com/maps?ll=%s,%s&z=15"
|
||||
% (self.latitude, self.longitude))
|
||||
|
||||
default_map_link = google_maps_link
|
||||
|
||||
def html_map_link(self): # for Admin, fixme: fix_ampersands
|
||||
return '<a href="%s">map link</a>' % self.default_map_link()
|
||||
html_map_link.allow_tags = True
|
||||
|
16
www/conservancy/apps/worldmap/templates/kml
Normal file
16
www/conservancy/apps/worldmap/templates/kml
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<kml xmlns="http://earth.google.com/kml/2.1">
|
||||
<Document>
|
||||
<Placemark>
|
||||
<name>{{ location.name }}</name>
|
||||
<description>
|
||||
<![CDATA[
|
||||
{{ location.html_description }}
|
||||
]]>
|
||||
</description>
|
||||
<Point>
|
||||
<coordinates>{{ location.latitude }},{{ location.longitude }}</coordinates>
|
||||
</Point>
|
||||
</Placemark>
|
||||
</Document>
|
||||
</kml>
|
Loading…
Reference in a new issue