diff --git a/www/conservancy/apps/blog/urls.py b/www/conservancy/apps/blog/urls.py index 083f3c85..7e77aac7 100644 --- a/www/conservancy/apps/blog/urls.py +++ b/www/conservancy/apps/blog/urls.py @@ -1,8 +1,8 @@ -from django.conf.urls.defaults import * +from django.conf.urls import patterns, url, include from models import Entry, EntryTag # relative import -from views import last_name # relative import from conservancy.apps.staff.models import Person from datetime import datetime +from views import last_name, BlogYearArchiveView, BlogMonthArchiveView, BlogDayArchiveView, BlogDateDetailView extra_context = {} @@ -12,12 +12,17 @@ info_dict = { 'extra_context': extra_context, } -urlpatterns = patterns('django.views.generic.date_based', - (r'^(?P\d{4})/(?P[a-z]{3})/(?P\w{1,2})/(?P[-\w]+)/$', 'object_detail', dict(info_dict, slug_field='slug')), - (r'^(?P\d{4})/(?P[a-z]{3})/(?P\w{1,2})/$', 'archive_day', info_dict), - (r'^(?P\d{4})/(?P[a-z]{3})/$', 'archive_month', info_dict), - (r'^(?P\d{4})/$', 'archive_year', dict(info_dict, - make_object_list=True)), +# urlpatterns = patterns('django.views.generic.date_based', +urlpatterns = patterns('', + # (r'^(?P\d{4})/(?P[a-z]{3})/(?P\w{1,2})/(?P[-\w]+)/$', 'object_detail', dict(info_dict, slug_field='slug')), + # (r'^(?P\d{4})/(?P[a-z]{3})/(?P\w{1,2})/$', 'archive_day', info_dict), + # (r'^(?P\d{4})/(?P[a-z]{3})/$', 'archive_month', info_dict), + # (r'^(?P\d{4})/$', 'archive_year', dict(info_dict, + # make_object_list=True)), + (r'^(?P\d{4})/(?P[a-z]{3})/(?P\w{1,2})/(?P[-\w]+)/$', BlogDateDetailView.as_view(**info_dict)), + (r'^(?P\d{4})/(?P[a-z]{3})/(?P\w{1,2})/$', BlogDayArchiveView.as_view(**info_dict)), + (r'^(?P\d{4})/(?P[a-z]{3})/$', BlogMonthArchiveView.as_view(**info_dict)), + (r'^(?P\d{4})/$', BlogYearArchiveView.as_view(**info_dict)), ) urlpatterns += patterns('conservancy.apps.blog.views', diff --git a/www/conservancy/apps/blog/views.py b/www/conservancy/apps/blog/views.py index 5760ba21..7a95819a 100644 --- a/www/conservancy/apps/blog/views.py +++ b/www/conservancy/apps/blog/views.py @@ -1,5 +1,7 @@ from models import Entry, EntryTag # relative import -from django.views.generic.list_detail import object_list +# from django.views.generic.list_detail import object_list +from django.views.generic import ListView +from django.views.generic.dates import YearArchiveView, MonthArchiveView, DayArchiveView, DateDetailView from conservancy.apps.staff.models import Person from django.shortcuts import get_object_or_404, render_to_response from datetime import datetime @@ -12,6 +14,15 @@ def OR_filter(field_name, objs): def last_name(person): return person.formal_name.rpartition(' ')[2] +class BlogListView(ListView): + extra_context = {} + + def get_context_data(self, **kwargs): + context = super(BlogListView, self).get_context_data(**kwargs) + # context['key'] = 'value' + context.update(self.extra_context) + return context + def custom_index(request, queryset, *args, **kwargs): """Blog list view that allows scrolling and also shows an index by year. @@ -50,7 +61,11 @@ def custom_index(request, queryset, *args, **kwargs): date_list = queryset.dates(date_field, 'year') extra_context['date_list'] = date_list - return object_list(request, queryset, *args, **kwargs) + # return object_list(request, queryset, *args, **kwargs) + kwargs['queryset'] = queryset + kwargs['extra_context'] = extra_context + callable = BlogListView.as_view(**kwargs) + return callable(request) def techblog_redirect(request): """Redirect from the old 'techblog' to the new blog @@ -95,9 +110,46 @@ def relative_redirect(request, path): from django import http from django.conf import settings - host = http.get_host(request) + host = request.get_host() 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) + +class BlogYearArchiveView(YearArchiveView): + make_object_list = True + allow_future = True + extra_context = {} + + def get_context_data(self, **kwargs): + context = super(BlogYearArchiveView, self).get_context_data(**kwargs) + context.update(self.extra_context) + return context + +class BlogMonthArchiveView(MonthArchiveView): + allow_future = True + extra_context = {} + + def get_context_data(self, **kwargs): + context = super(BlogMonthArchiveView, self).get_context_data(**kwargs) + context.update(self.extra_context) + return context + +class BlogDayArchiveView(DayArchiveView): + allow_future = True + extra_context = {} + + def get_context_data(self, **kwargs): + context = super(BlogDayArchiveView, self).get_context_data(**kwargs) + context.update(self.extra_context) + return context + +class BlogDateDetailView(DateDetailView): + allow_future = True + extra_context = {} + + def get_context_data(self, **kwargs): + context = super(BlogDateDetailView, self).get_context_data(**kwargs) + context.update(self.extra_context) + return context diff --git a/www/conservancy/apps/contacts/urls.py b/www/conservancy/apps/contacts/urls.py index 7ff3287b..64d53300 100644 --- a/www/conservancy/apps/contacts/urls.py +++ b/www/conservancy/apps/contacts/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls.defaults import * +from django.conf.urls import patterns, url, include urlpatterns = patterns('conservancy.apps.contacts.views', (r'^/?$', 'subscribe'), diff --git a/www/conservancy/apps/events/models.py b/www/conservancy/apps/events/models.py index 26b478f0..1bd1d20e 100644 --- a/www/conservancy/apps/events/models.py +++ b/www/conservancy/apps/events/models.py @@ -19,14 +19,14 @@ class EventTag(models.Model): 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()) + def get_queryset(self): + return super(PastEventManager, self).get_queryset().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()) + def get_queryset(self): + return super(FutureEventManager, self).get_queryset().filter(date__gte=datetime.today()) class Event(models.Model): """Model for Conservancy staff member events (presentations, etc)""" @@ -78,7 +78,8 @@ class EventMedia(models.Model): ('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, + # verify_exists removed https://docs.djangoproject.com/en/1.7/releases/1.4/ + remote = models.URLField(blank=True, 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.") diff --git a/www/conservancy/apps/events/urls.py b/www/conservancy/apps/events/urls.py index 931dc7a5..650d8b0c 100644 --- a/www/conservancy/apps/events/urls.py +++ b/www/conservancy/apps/events/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls.defaults import * +from django.conf.urls import patterns, url, include from models import Event # relative import info_dict = { @@ -7,13 +7,18 @@ info_dict = { 'allow_future': True, } -urlpatterns = patterns('django.views.generic.date_based', - (r'^(?P\d{4})/$', 'archive_year', dict(info_dict, - make_object_list=True)), -) +# FIXME -- see blog and news for examples +# urlpatterns = patterns('django.views.generic.date_based', +# (r'^(?P\d{4})/$', 'archive_year', dict(info_dict, +# make_object_list=True)), +# ) -urlpatterns += patterns('conservancy.apps.events.views', - (r'^/?$', 'custom_index', dict(info_dict, queryset=Event.past.all(), paginate_by=10)), - (r'^(?P\d{4})/(?P[-\w]+)/$', 'event_detail', dict(info_dict, slug_field='slug')), - (r'^ics/$', 'future_event_ics', info_dict), +# urlpatterns += patterns('conservancy.apps.events.views', +# (r'^/?$', 'custom_index', dict(info_dict, queryset=Event.past.all(), paginate_by=10)), +# (r'^(?P\d{4})/(?P[-\w]+)/$', 'event_detail', dict(info_dict, slug_field='slug')), +# (r'^ics/$', 'future_event_ics', info_dict), +# ) + +urlpatterns = patterns('conservancy.apps.events.views', + (r'^.*$', 'custom_index', dict(info_dict, queryset=Event.past.all(), paginate_by=10)), ) diff --git a/www/conservancy/apps/events/views.py b/www/conservancy/apps/events/views.py index b8d3b49a..f78832c0 100644 --- a/www/conservancy/apps/events/views.py +++ b/www/conservancy/apps/events/views.py @@ -1,9 +1,11 @@ -from django.views.generic.list_detail import object_list +# 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 +# for debugging... +from django.http import HttpResponse def event_detail(request, year, slug, queryset, **kwargs): """This view shows event detail. @@ -35,7 +37,8 @@ def custom_index(request, queryset, *args, **kwargs): del kwargs['date_field'] del kwargs['allow_future'] - return object_list(request, queryset, *args, **kwargs) + # return object_list(request, queryset, *args, **kwargs) + return HttpResponse("FIXME: events must be updated like blog and news.") def future_event_ics(request, queryset, *args, **kwargs): """ICS calendar view of future events diff --git a/www/conservancy/apps/news/models.py b/www/conservancy/apps/news/models.py index d812d33c..8cb1a893 100644 --- a/www/conservancy/apps/news/models.py +++ b/www/conservancy/apps/news/models.py @@ -74,8 +74,8 @@ class ExternalArticleTag(models.Model): return self.label class PublicExternalArticleManager(models.Manager): - def get_query_set(self): - return super(PublicExternalArticleManager, self).get_query_set().filter(visible=True) + def get_queryset(self): + return super(PublicExternalArticleManager, self).get_queryset().filter(visible=True) class ExternalArticle(models.Model): """A system for displaying Conservancy news mentions on the site. @@ -87,7 +87,8 @@ class ExternalArticle(models.Model): 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) + # verify_exists removed https://docs.djangoproject.com/en/1.7/releases/1.4/ + url = models.URLField(blank=True) date = models.DateField() visible = models.BooleanField(help_text="Whether to display on website") diff --git a/www/conservancy/apps/news/urls.py b/www/conservancy/apps/news/urls.py index 1b9d8af9..55a6f3f0 100644 --- a/www/conservancy/apps/news/urls.py +++ b/www/conservancy/apps/news/urls.py @@ -17,9 +17,10 @@ # along with this program in a file in the toplevel directory called # "AGPLv3". If not, see . -from django.conf.urls.defaults import * +from django.conf.urls import patterns, url, include from django.conf import settings from models import PressRelease, ExternalArticle # relative import +from views import NewsYearArchiveView, NewsMonthArchiveView, NewsDayArchiveView, NewsDateDetailView info_dict = { 'queryset': PressRelease.objects.all().filter(sites__id__exact=settings.SITE_ID), @@ -30,12 +31,16 @@ external_article_dict = { 'articles': ExternalArticle.objects.all() } -urlpatterns = patterns('django.views.generic.date_based', - (r'^(?P\d{4})/(?P[a-z]{3})/(?P\w{1,2})/(?P[-\w]+)/$', 'object_detail', dict(info_dict, slug_field='slug')), - (r'^(?P\d{4})/(?P[a-z]{3})/(?P\w{1,2})/$', 'archive_day', info_dict), - (r'^(?P\d{4})/(?P[a-z]{3})/$', 'archive_month', info_dict), - (r'^(?P\d{4})/$', 'archive_year', dict(info_dict, - make_object_list=True)), +urlpatterns = patterns('', +# (r'^(?P\d{4})/(?P[a-z]{3})/(?P\w{1,2})/(?P[-\w]+)/$', 'conservancy.apps.news.views.object_detail', info_dict), + (r'^(?P\d{4})/(?P[a-z]{3})/(?P\w{1,2})/(?P[-\w]+)/$', NewsDateDetailView.as_view(**info_dict)), +# (r'^(?P\d{4})/(?P[a-z]{3})/(?P\w{1,2})/$', 'conservancy.apps.news.views.archive_day', info_dict), + (r'^(?P\d{4})/(?P[a-z]{3})/(?P\w{1,2})/$', NewsDayArchiveView.as_view(**info_dict)), +# (r'^(?P\d{4})/(?P[a-z]{3})/$', 'conservancy.apps.news.views.archive_month', info_dict), + (r'^(?P\d{4})/(?P[a-z]{3})/$', NewsMonthArchiveView.as_view(**info_dict)), +# (r'^(?P\d{4})/$', 'conservancy.apps.news.views.archive_year', +# dict(info_dict, make_object_list=True)), + (r'^(?P\d{4})/$', NewsYearArchiveView.as_view(**info_dict)), ) urlpatterns += patterns('', diff --git a/www/conservancy/apps/news/views.py b/www/conservancy/apps/news/views.py index 13681183..7a6e1cd2 100644 --- a/www/conservancy/apps/news/views.py +++ b/www/conservancy/apps/news/views.py @@ -1,13 +1,32 @@ -from django.views.generic.list_detail import object_list +# from django.views.generic.list_detail import object_list +from django.views.generic import ListView +from django.views.generic.dates import YearArchiveView, MonthArchiveView, DayArchiveView, DateDetailView from conservancy.apps.news.models import ExternalArticle from conservancy.apps.events.models import Event from datetime import datetime +# for debugging... +from django.http import HttpResponse + +class NewsListView(ListView): + extra_context = {} + def get_context_data(self, **kwargs): + context = super(NewsListView, self).get_context_data(**kwargs) + # context['key'] = 'value' + context.update(self.extra_context) + return context + 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. """ + # debug = '
This is news'
+    # debug += '\nqueryset: ' + str(queryset)
+    # debug += '\nargs: ' + str(args)
+    # debug += '\nkwargs: ' + str(kwargs)
+    # debug += '
' + # return HttpResponse(debug) articles = None #if not request.GET.has_key("page"): @@ -28,8 +47,62 @@ def custom_index(request, queryset, *args, **kwargs): 'past_events': past_events}) del kwargs['date_field'] - return object_list(request, queryset, *args, **kwargs) + # return object_list(request, queryset, *args, **kwargs) + # callable = NewsListView.as_view(queryset=queryset, + # extra_context=kwargs, + # paginate_by=kwargs['paginate_by']) + kwargs['queryset'] = queryset + callable = NewsListView.as_view(**kwargs) + return callable(request) # num_navigation = 3 # in each direction # page_navigation = range(max((page - num_navigation), 1), # min((page + num_navigation), page_count) + 1) + +class NewsYearArchiveView(YearArchiveView): + # queryset = Article.objects.all() + # date_field = "pub_date" + make_object_list = True + allow_future = True + +# def archive_year(request, **kwargs): +# callable = NewsYearArchiveView.as_view(**kwargs) +# return callable(request) + +class NewsMonthArchiveView(MonthArchiveView): + allow_future = True + +# def archive_month(request, **kwargs): +# # return HttpResponse("archive_month") +# callable = NewsMonthArchiveView.as_view(**kwargs) +# return callable(request) + +class NewsDayArchiveView(DayArchiveView): + allow_future = True + +# def archive_day(request, **kwargs): +# # return HttpResponse("archive_day") +# callable = NewsDayArchiveView.as_view(**kwargs) +# return callable(request) + +class NewsDateDetailView(DateDetailView): + # extra_context = {} + allow_future = True + # slug_url_kwarg = 'slug' + + # def get_context_data(self, **kwargs): + # context = super(NewsDateDetailView, self).get_context_data(**kwargs) + # context.update(self.extra_context) + # return context + +# def object_detail(request, **kwargs): +# # extra_context = {} +# # extra_context['slug'] = kwargs['slug'] +# # del kwargs['slug'] +# # kwargs['extra_context'] = extra_context +# # return HttpResponse("object_detail: " + str(kwargs)) +# # slug = kwargs['slug'] +# # del kwargs['slug'] +# callable = NewsDateDetailView.as_view(**kwargs) +# return callable(request) + diff --git a/www/conservancy/apps/podcast/admin.py b/www/conservancy/apps/podcast/admin.py deleted file mode 100644 index f6dc6d1b..00000000 --- a/www/conservancy/apps/podcast/admin.py +++ /dev/null @@ -1,18 +0,0 @@ -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) diff --git a/www/conservancy/apps/podcast/models.py b/www/conservancy/apps/podcast/models.py deleted file mode 100644 index 893daa7a..00000000 --- a/www/conservancy/apps/podcast/models.py +++ /dev/null @@ -1,58 +0,0 @@ -from django.db import models -from django.conf import settings -from conservancy.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? diff --git a/www/conservancy/apps/podcast/urls.py b/www/conservancy/apps/podcast/urls.py deleted file mode 100644 index 7694d9e5..00000000 --- a/www/conservancy/apps/podcast/urls.py +++ /dev/null @@ -1,61 +0,0 @@ -from django.conf.urls.defaults import * -from models import Podcast, PodcastTag # relative import -from conservancy.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\d{4})/(?P[a-z]{3})/(?P\w{1,2})/(?P[-\w]+)/$', 'object_detail', dict(info_dict, slug_field='slug')), - (r'^(?P\d{4})/(?P[a-z]{3})/(?P\w{1,2})/$', 'archive_day', info_dict), - (r'^(?P\d{4})/(?P[a-z]{3})/$', 'archive_month', info_dict), - (r'^(?P\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[-\w]+)/$', 'object_detail', dict(info_dict, slug_field='slug')), -) - -urlpatterns += patterns('conservancy.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 diff --git a/www/conservancy/apps/podcast/views.py b/www/conservancy/apps/podcast/views.py deleted file mode 100644 index bd45f483..00000000 --- a/www/conservancy/apps/podcast/views.py +++ /dev/null @@ -1,89 +0,0 @@ -from models import Podcast, PodcastTag # relative import -from django.views.generic.list_detail import object_list -from conservancy.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) diff --git a/www/conservancy/apps/summit_registration/urls.py b/www/conservancy/apps/summit_registration/urls.py index 0a6d5c8b..1597b0ef 100644 --- a/www/conservancy/apps/summit_registration/urls.py +++ b/www/conservancy/apps/summit_registration/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls.defaults import * +from django.conf.urls import patterns, url, include urlpatterns = patterns('conservancy.apps.summit_registration.views', (r'^/?$', 'register'), diff --git a/www/conservancy/apps/supporters/views.py b/www/conservancy/apps/supporters/views.py index bc00d1c9..b6c60aa4 100644 --- a/www/conservancy/apps/supporters/views.py +++ b/www/conservancy/apps/supporters/views.py @@ -1,4 +1,3 @@ from models import Supporter # relative import -from django.views.generic.list_detail import object_list from django.shortcuts import get_object_or_404, render_to_response diff --git a/www/conservancy/middleware.py b/www/conservancy/middleware.py index 2ea8d00a..8f714f5c 100644 --- a/www/conservancy/middleware.py +++ b/www/conservancy/middleware.py @@ -1,5 +1,5 @@ -from django.conf import settings from django import http +from django.conf import settings from django.utils.cache import patch_response_headers class ForceCanonicalHostnameMiddleware(object): @@ -19,7 +19,7 @@ class ForceCanonicalHostnameMiddleware(object): return http.HttpResponseRedirect(url) # Check for a redirect based on settings.APPEND_SLASH - host = http.get_host(request) + host = request.get_host() old_url = [host, request.path] new_url = old_url[:] # Append a slash if append_slash is set and the URL doesn't have a diff --git a/www/conservancy/settings.py b/www/conservancy/settings.py index 6fab2d65..010ae728 100644 --- a/www/conservancy/settings.py +++ b/www/conservancy/settings.py @@ -21,13 +21,28 @@ from djangocommonsettings import * SITE_ID = 2 ROOT_URLCONF = 'conservancy.urls' -FORCE_CANONICAL_HOSTNAME = "sfconservancy.org" + + +# FORCE_CANONICAL_HOSTNAME = "sfconservancy.org" +FORCE_CANONICAL_HOSTNAME = False + +ALLOWED_HOSTS = [ 'aspen.sfconservancy.org', 'sfconservancy.org' ] REDIRECT_TABLE = { 'www.sf-conservancy.org': 'sfconservancy.org', } -try: - from djangodebug import conservancy_hostname as FORCE_CANONICAL_HOSTNAME -except: - pass +# import os +# BASE_DIR = os.path.dirname(os.path.dirname(__file__)) + +# from os.path import join +# TEMPLATE_DIRS = ( +# join(BASE_DIR, 'templates'), +# ) +# NOTE: trailing comma is required to force this to be a tuple +TEMPLATE_DIRS = ( '/var/www/conservancy/templates', '/var/www/conservancy/static', ) + +# try: +# from djangodebug import conservancy_hostname as FORCE_CANONICAL_HOSTNAME +# except: +# pass diff --git a/www/conservancy/apps/podcast/__init__.py b/www/conservancy/static/__init__.py similarity index 100% rename from www/conservancy/apps/podcast/__init__.py rename to www/conservancy/static/__init__.py diff --git a/www/conservancy/static/401error.html b/www/conservancy/static/error/401/index.html similarity index 100% rename from www/conservancy/static/401error.html rename to www/conservancy/static/error/401/index.html diff --git a/www/conservancy/static/403error.html b/www/conservancy/static/error/403/index.html similarity index 100% rename from www/conservancy/static/403error.html rename to www/conservancy/static/error/403/index.html diff --git a/www/conservancy/static/404error.html b/www/conservancy/static/error/404/index.html similarity index 100% rename from www/conservancy/static/404error.html rename to www/conservancy/static/error/404/index.html diff --git a/www/conservancy/static/500error.html b/www/conservancy/static/error/500/index.html similarity index 100% rename from www/conservancy/static/500error.html rename to www/conservancy/static/error/500/index.html diff --git a/www/conservancy/static/views.py b/www/conservancy/static/views.py new file mode 100644 index 00000000..b83b7fa3 --- /dev/null +++ b/www/conservancy/static/views.py @@ -0,0 +1,46 @@ +import os.path +from django.http import HttpResponse +from django.template import RequestContext, loader + +def handler(request, errorcode): + STATIC_ROOT = '/home/www/website/www/conservancy/static/' + path = 'error/' + errorcode + '/index.html' + fullpath = STATIC_ROOT + path + if not os.path.exists(fullpath): + return HttpResponse("Internal error: " + path) + template = loader.get_template(path) + context = RequestContext(request) + return HttpResponse(template.render(context)) + +def handler401(request): + return handler(request, '401') + +def handler403(request): + return handler(request, '403') + +def handler404(request): + return handler(request, '404') + +def handler500(request): + return handler(request, '500') + +def index(request): + # return HttpResponse("Hello, static world: " + request.get_full_path()) + path = request.get_full_path() + path = path.lstrip('/') + if path[-1:] == '/': + path += 'index.html' + STATIC_ROOT = '/home/www/website/www/conservancy/static/' + fullpath = STATIC_ROOT + path + if not os.path.exists(fullpath): + # return HttpResponse("Sorry that's a 404: " + path) + return handler404(request) + template = loader.get_template(path) + context = RequestContext(request) + return HttpResponse(template.render(context)) + +def debug(request): + path = request.get_full_path() + path = path.lstrip('/') + return HttpResponse("Hello, static world: " + path) + diff --git a/www/conservancy/urls.py b/www/conservancy/urls.py index 5b09b308..93d40582 100644 --- a/www/conservancy/urls.py +++ b/www/conservancy/urls.py @@ -17,11 +17,22 @@ # along with this program in a file in the toplevel directory called # "AGPLv3". If not, see . -from django.conf.urls.defaults import * +from django.conf.urls import patterns, url, include from django.contrib import admin -from conservancy.feeds import BlogFeed, PressReleaseFeed, OmnibusFeed -handler404 = 'modpythoncustom.view404' +# import conservancy.settings +from django.conf import settings +from conservancy.feeds import BlogFeed, PressReleaseFeed, OmnibusFeed +# from django.views.static import serve +# from django.conf.urls.static import static +# from django.contrib.staticfiles.urls import staticfiles_urlpatterns +# import conservancy.static.overview.views + +# handler404 = 'modpythoncustom.view404' +# handler401 = 'conservancy.static.views.handler401' +# handler403 = 'conservancy.static.views.handler403' +handler404 = 'conservancy.static.views.handler404' +# handler500 = 'conservancy.static.views.handler500' admin.autodiscover() @@ -38,4 +49,38 @@ urlpatterns = patterns('', (r'^feeds/?$', 'conservancy.feeds.view'), (r'^news(/|$)', include('conservancy.apps.news.urls')), (r'^blog(/|$)', include('conservancy.apps.blog.urls')), + # formerly static templated things... (dirs with templates) + (r'^error', 'conservancy.static.views.index'), + (r'^about', 'conservancy.static.views.index'), + (r'^donate', 'conservancy.static.views.index'), + (r'^linux-compliance', 'conservancy.static.views.index'), + (r'^members', 'conservancy.static.views.index'), + (r'^npoacct', 'conservancy.static.views.index'), + (r'^overview', 'conservancy.static.views.index'), + (r'^privacy-policy', 'conservancy.static.views.index'), + (r'^supporter', 'conservancy.static.views.index'), ) + +# urlpatterns += url(regex = r'^%s(?P.*)$' % conservancy.settings.STATIC_URL[1:], +# urlpatterns += url(regex = r'^/overview', +# view = 'django.views.static.serve', +# kwargs = {'document_root': conservancy.settings.STATIC_ROOT, +# 'show_indexes' : True}) +# urlpatterns += (r'^(?P.*)$', 'django.views.static.serve', +# urlpatterns += (r'^overview/$', 'django.views.static.serve', +# {'document_root': conservancy.settings.STATIC_ROOT, +# 'show_indexes' : True}) + +# https://docs.djangoproject.com/en/1.7/howto/static-files/ +# + static(conservancy.settings.STATIC_URL, document_root=conservancy.settings.STATIC_ROOT) + +# urlpatterns += staticfiles_urlpatterns() + +# urlpatterns += static(settings.STATIC_URL, view='django.contrib.staticfiles.views.serve', +# urlpatterns += static('/', view='django.contrib.staticfiles.views.serve', +# document_root=settings.STATIC_ROOT, +# show_indexes=True) + + + + diff --git a/www/conservancy_ssl_wrapper.py b/www/conservancy_ssl_wrapper.py index fd10266b..218f0823 100644 --- a/www/conservancy_ssl_wrapper.py +++ b/www/conservancy_ssl_wrapper.py @@ -24,4 +24,4 @@ from os import environ environ["DJANGO_SETTINGS_MODULE"] = 'conservancy_ssl.settings' environ["CANONICAL_HOSTNAME"] = 'sfconservancy.org' -from modpythoncustom import * +# from modpythoncustom import * diff --git a/www/conservancy_wrapper.py b/www/conservancy_wrapper.py index eaa760e8..25903d89 100644 --- a/www/conservancy_wrapper.py +++ b/www/conservancy_wrapper.py @@ -5,4 +5,4 @@ from os import environ environ["DJANGO_SETTINGS_MODULE"] = 'conservancy.settings' environ["CANONICAL_HOSTNAME"] = 'sfconservancy.org' -from modpythoncustom import * +# from modpythoncustom import * diff --git a/www/wsgicustom.wsgi b/www/wsgicustom.wsgi new file mode 100644 index 00000000..fa1197c3 --- /dev/null +++ b/www/wsgicustom.wsgi @@ -0,0 +1,10 @@ +# wsgicustom.py + +import os +import sys + +sys.path = ['/var/www'] + sys.path +os.environ['DJANGO_SETTINGS_MODULE'] = 'conservancy.settings' + +from django.core.wsgi import get_wsgi_application +application = get_wsgi_application()