Changeset - f6bbcc7ee328
[Not reviewed]
0 18 0
Bradley Kuhn (bkuhn) - 9 years ago 2015-03-09 00:54:05
bkuhn@ebb.org
Just quit it with this relative import stuff.

While I think these relative imports seem to be valid for the running
application, I am having trouble with the django-admin applications
regarding them. I don't see this syntactic sugar as absolutely
essential, so I'm just going to change it now.
18 files changed with 20 insertions and 20 deletions:
0 comments (0 inline, 0 general)
www/conservancy/apps/blog/admin.py
Show inline comments
 
from django.contrib import admin
 
from models import EntryTag, Entry
 
from conservancy.apps.blog.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)
www/conservancy/apps/blog/urls.py
Show inline comments
 
from django.conf.urls import patterns, url, include
 
from models import Entry, EntryTag # relative import
 
from conservancy.apps.blog.models import Entry, EntryTag # relative import
 
from conservancy.apps.staff.models import Person
 
from datetime import datetime
 
from views import last_name, BlogYearArchiveView, BlogMonthArchiveView, BlogDayArchiveView, BlogDateDetailView
 
from conservancy.apps.blog.views import last_name, BlogYearArchiveView, BlogMonthArchiveView, BlogDayArchiveView, BlogDateDetailView
 

	
 
extra_context = {}
 

	
 
info_dict = {
 
    'queryset': Entry.objects.all(),
 
    'date_field': 'pub_date',
 
    'extra_context': extra_context,
 
}
 

	
 
# urlpatterns = patterns('django.views.generic.date_based',
 
urlpatterns = patterns('',
 
   # (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)),
 
   (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?P<slug>[-\w]+)/$', BlogDateDetailView.as_view(**info_dict)),
 
   (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/$', BlogDayArchiveView.as_view(**info_dict)),
 
   (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/$', BlogMonthArchiveView.as_view(**info_dict)),
 
   (r'^(?P<year>\d{4})/$', BlogYearArchiveView.as_view(**info_dict)),
 
)
 

	
 
urlpatterns += patterns('conservancy.apps.blog.views',
 
                        (r'^/?$', 'custom_index', dict(info_dict, paginate_by=4)),
 
   (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:
www/conservancy/apps/blog/views.py
Show inline comments
 
from models import Entry, EntryTag # relative import
 
from conservancy.apps.blog.models import Entry, EntryTag # relative import
 
# 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 django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
 
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):
 
    """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])
www/conservancy/apps/contacts/admin.py
Show inline comments
 
from django.contrib import admin
 
from models import ContactEntry
 
from conservancy.apps.contacts.models import ContactEntry
 

	
 
class ContactEntryAdmin(admin.ModelAdmin):
 
    list_display = ('email', 'subscribe_conservancy')
 

	
 

	
 
admin.site.register(ContactEntry, ContactEntryAdmin)
www/conservancy/apps/contacts/views.py
Show inline comments
 
from django.shortcuts import render_to_response
 
from django import forms
 
from models import ContactEntry
 
from conservancy.app.contacts.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_conservancy'].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})
www/conservancy/apps/events/admin.py
Show inline comments
 
from django.contrib import admin
 
from models import EventTag, Event, EventMedia
 
from conservancy.apps.event.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)
 

	
 

	
www/conservancy/apps/events/urls.py
Show inline comments
 
from django.conf.urls import patterns, url, include
 
from models import Event # relative import
 
from conservancy.apps.events.models import Event
 

	
 
info_dict = {
 
    'queryset': Event.objects.all(),
 
    'date_field': 'date',
 
    'allow_future': True,
 
}
 

	
 
# FIXME -- see blog and news for examples
 
# urlpatterns = patterns('django.views.generic.date_based',
 
#     (r'^(?P<year>\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<year>\d{4})/(?P<slug>[-\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)),
 
)
www/conservancy/apps/events/views.py
Show inline comments
 
# 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
 
from conservancy.apps.events.models import Event
 
# for debugging...
 
from django.http import HttpResponse
 

	
 
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)
 
    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
 

	
 
    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.
 
    """
 

	
www/conservancy/apps/fundgoal/admin.py
Show inline comments
 
from django.contrib import admin
 
from models import FundraisingGoal
 
from conservancy.apps.fundgoal.models import FundraisingGoal
 

	
 
class FundraisingGoalAdmin(admin.ModelAdmin):
 
    list_display = ('display_name', 'display_until_date')
 

	
 
admin.site.register(FundraisingGoal, FundraisingGoalAdmin)
www/conservancy/apps/fundgoal/views.py
Show inline comments
 
from models import FundraisingGoal # relative import
 
from conservancy.apps.fundgoal.models import FundraisingGoal
 
from django.shortcuts import get_object_or_404, render_to_response
www/conservancy/apps/news/admin.py
Show inline comments
 
from django.contrib import admin
 
from models import PressRelease, ExternalArticleTag, ExternalArticle
 
from conservancy.apps.news.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)
 

	
 

	
 

	
www/conservancy/apps/news/urls.py
Show inline comments
 
# Copyright 2005-2008, James Garrison
 
# Copyright 2010, Bradley M. Kuhn
 

	
 
# This software's license gives you freedom; you can copy, convey,
 
# propagate, redistribute, modify and/or redistribute modified versions of
 
# this program under the terms of the GNU Affero General Public License
 
# (AGPL) as published by the Free Software Foundation (FSF), either
 
# version 3 of the License, or (at your option) any later version of the
 
# AGPL published by the FSF.
 
#
 
# This program is distributed in the hope that it will be useful, but
 
# WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero
 
# General Public License for more details.
 
#
 
# You should have received a copy of the GNU Affero General Public License
 
# along with this program in a file in the toplevel directory called
 
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
 

	
 
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
 
from conservancy.app.news.models import PressRelease, ExternalArticle
 
from conservancy.apps.news.views import NewsYearArchiveView, NewsMonthArchiveView, NewsDayArchiveView, NewsDateDetailView
 

	
 
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('',
 
#    (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?P<slug>[-\w]+)/$', 'conservancy.apps.news.views.object_detail', info_dict),
 
   (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/(?P<slug>[-\w]+)/$', NewsDateDetailView.as_view(**info_dict)),
 
#   (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/$', 'conservancy.apps.news.views.archive_day', info_dict),
 
   (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/(?P<day>\w{1,2})/$', NewsDayArchiveView.as_view(**info_dict)),
 
#   (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/$', 'conservancy.apps.news.views.archive_month', info_dict),
 
   (r'^(?P<year>\d{4})/(?P<month>[a-z]{3})/$', NewsMonthArchiveView.as_view(**info_dict)),
 
#   (r'^(?P<year>\d{4})/$', 'conservancy.apps.news.views.archive_year',
 
#    dict(info_dict, make_object_list=True)),
 
   (r'^(?P<year>\d{4})/$', NewsYearArchiveView.as_view(**info_dict)),
 
)
 

	
 
urlpatterns += patterns('',
 
   (r'^/?$', 'conservancy.apps.news.views.listing', dict(info_dict, paginate_by=6)),
 
)
www/conservancy/apps/staff/admin.py
Show inline comments
 
from django.contrib import admin
 
from models import Person
 
from conservancy.apps.staff.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)
www/conservancy/apps/summit_registration/admin.py
Show inline comments
 
from django.contrib import admin
 
from models import SummitRegistration
 
from conservancy.apps.summit_registration.models import SummitRegistration
 

	
 
class SummitRegistrationAdmin(admin.ModelAdmin):
 
    list_display = ('name', 'email', 'affiliation', 'cle_credit')
 

	
 
admin.site.register(SummitRegistration, SummitRegistrationAdmin)
 

	
www/conservancy/apps/summit_registration/views.py
Show inline comments
 
from django.shortcuts import render_to_response
 
from django import forms
 
from models import SummitRegistration
 
from conervancy.apps.summit_registration.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})
www/conservancy/apps/supporters/admin.py
Show inline comments
 
from django.contrib import admin
 
from models import Supporter
 
from conservancy.app.Supporter.models import Supporter
 

	
 
class SupporterAdmin(admin.ModelAdmin):
 
    list_display = ('display_name', 'display_until_date')
 

	
 
admin.site.register(Supporter, SupporterAdmin)
www/conservancy/apps/supporters/views.py
Show inline comments
 
from models import Supporter # relative import
 
from conservancy.apps.supporters.models import Supporter
 
from django.shortcuts import get_object_or_404, render_to_response
 

	
www/conservancy/apps/worldmap/admin.py
Show inline comments
 
from django.contrib import admin
 
from models import EarthLocation
 
from conservancy.apps.worldmap.models import EarthLocation
 

	
 
class EarthLocationAdmin(admin.ModelAdmin):
 
    list_display = ("label", "html_map_link")
 

	
 
admin.site.register(EarthLocation, EarthLocationAdmin)
0 comments (0 inline, 0 general)