Skip to content

Commit

Permalink
Merge cfa/master into opencity/master
Browse files Browse the repository at this point in the history
Conflicts:
	councilmatic/static/main/css/screen.css
	  - Keep the old styles -- these are going to change completely anyway.
	councilmatic/templates/base.html
	  - Add in the page footer, but leave the compress tag commented out for now.
	councilmatic/templates/phillyleg/legfile_detail.html
	  - Check for sponsors before rendering the sponsors header.
	  - Put the comment block back. Consider turning off through configuration.
  • Loading branch information
mjumbewu committed Mar 28, 2013
2 parents e9f1a5b + a2b7747 commit 609f4ad
Show file tree
Hide file tree
Showing 60 changed files with 2,135 additions and 1,017 deletions.
1 change: 1 addition & 0 deletions councilmatic/cm/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.core.serializers.json import DjangoJSONEncoder
from django.views import generic as views
from cm_api.resources import SubscriberResource
from phillyleg import models

class ProfileAdminView (views.TemplateView):
template_name = 'cm/profile_admin.html'
Expand Down
28 changes: 23 additions & 5 deletions councilmatic/main/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_last_updated_time(self):

def get_params(self):
return {}

def get_label(self):
return 'Newly introduced legislation'

Expand Down Expand Up @@ -87,7 +87,7 @@ def get_last_updated_time_for_file(self, legfile):

def get_params(self):
return self.selectors

def get_label(self):
return 'Updates to legislation'

Expand Down Expand Up @@ -159,12 +159,27 @@ def __init__(self, search_filter):

def get_content(self):
qs = SearchQuerySet()
search_fields = {
'q': 'text',
'controlling_bodies': 'controlling_body',
'statuses': 'status',
'file_types': 'file_type',
}

for key, val in self.filter.iteritems():
if key in search_fields:
field = search_fields[key]
else:
field = key

if val in ([], {}, '', (), None):
continue

if isinstance(val, list):
for item in val:
qs = qs.filter(**{key: item})
qs = qs.filter(**{field: item})
else:
qs = qs.filter(**{key: val})
qs = qs.filter(**{field: val})

return qs.order_by('order_date')

Expand All @@ -184,7 +199,7 @@ def get_updates_since(self, datetime):

def get_params(self):
return {'search_filter': json.dumps(self.filter)}

def get_label(self):
label = 'New '

Expand All @@ -197,6 +212,9 @@ def get_label(self):
is_plural = (' ' in self.filter['q'])
label += ' containing the keyword' + ('s' if is_plural else '') + ' "' + self.filter['q'] + '"'

if 'sponsors' in self.filter:
label += ' sponsored by ' + ' or '.join(self.filter['sponsors'])

return label


Expand Down
67 changes: 49 additions & 18 deletions councilmatic/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,39 +63,70 @@ def get_context_data(self, **kwargs):
return context_data


class AppDashboardView (SearchBarMixin,
bookmarks.views.BaseBookmarkMixin,
views.TemplateView):
template_name = 'main/app_dashboard.html'

def get_recent_locations(self):
return list(phillyleg.models.MetaData_Location.objects.\
all().filter(valid=True).order_by('-pk')[:10].\
prefetch_related('references_in_legislation'))
class BaseDashboardMixin (SearchBarMixin,
bookmarks.views.BaseBookmarkMixin):

def get_recent_legislation(self):
return list(phillyleg.models.LegFile.objects.\
all().exclude(title='').order_by('-key')[:3])
legfiles = self.get_filtered_legfiles()
return list(legfiles.exclude(title='').order_by('-key')[:3])

def get_context_data(self, **kwargs):
search_form = forms.FullSearchForm()

legfiles = self.get_recent_legislation()
bookmark_data = self.get_bookmarks_data(legfiles)
locations = self.get_recent_locations()

context_data = super(AppDashboardView, self).get_context_data(
context_data = super(BaseDashboardMixin, self).get_context_data(
**kwargs)
context_data.update({
'legfiles': legfiles,
'bookmark_data': bookmark_data,
'search_form': search_form,
'locations': locations
})

return context_data


class AppDashboardView (BaseDashboardMixin,
views.TemplateView):
template_name = 'main/app_dashboard.html'

def get_filtered_legfiles(self):
return phillyleg.models.LegFile.objects

def get_recent_locations(self):
return list(phillyleg.models.MetaData_Location.objects.\
all().filter(valid=True).order_by('-pk')[:10].\
prefetch_related('references_in_legislation'))

def get_context_data(self, **kwargs):
locations = self.get_recent_locations()
context_data = super(AppDashboardView, self).get_context_data(**kwargs)
context_data['locations'] = locations
return context_data


class CouncilMemberDetailView (BaseDashboardMixin,
subscriptions.views.SingleSubscriptionMixin,
views.DetailView):
queryset = phillyleg.models.CouncilMember.objects.prefetch_related('tenures', 'tenures__district')

def get_content_feed(self):
return feeds.SearchResultsFeed(search_filter={'sponsors': [self.object.name]})

def get_filtered_legfiles(self):
return self.object.legislation

def get_district(self):
return self.object.district

def get_context_data(self, **kwargs):
district = self.get_district()
context_data = super(CouncilMemberDetailView, self).get_context_data(**kwargs)
context_data['district'] = district
return context_data


class SearcherMixin (object):
def _init_haystack_searchview(self, request):
# Construct and run a haystack SearchView so that we can use the
Expand Down Expand Up @@ -199,9 +230,9 @@ def get_context_data(self, **kwargs):
if page_obj.has_previous():
context['previous_url'] = self.paginated_url(
page_obj.previous_page_number(), query_params)

page_urls = []
start_num = max(1, min(page_obj.number - 5,
start_num = max(1, min(page_obj.number - 5,
page_obj.paginator.num_pages - 9))
end_num = min(start_num + 10, page_obj.paginator.num_pages + 1)

Expand All @@ -212,10 +243,10 @@ def get_context_data(self, **kwargs):
url = None
page_urls.append((page_num, url))
context['page_urls'] = page_urls

log.debug(context)
return context

def paginated_url(self, page_num, query_params):
url = '{0}?page={1}'.format(self.request.path, page_num)
if query_params:
Expand Down
12 changes: 12 additions & 0 deletions councilmatic/phillyleg/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib.gis import admin
from django.db.models import Max
from phillyleg.models import *

class LegActionInline(admin.StackedInline):
Expand Down Expand Up @@ -45,6 +46,17 @@ class CouncilMemberTenureInline (admin.TabularInline):

class CouncilMemberAdmin (admin.ModelAdmin):
inlines = [CouncilMemberTenureInline]
list_display = ('name', 'tenure_begin')

def queryset(self, request):
qs = super(CouncilMemberAdmin, self).queryset(request)
qs = qs.annotate(tenure_begin=Max('tenures__begin'))
return qs

def tenure_begin(self, instance):
return instance.tenure_begin
tenure_begin.short_description = 'Began tenure...'



admin.site.register(LegFile, LegFileAdmin)
Expand Down
Loading

0 comments on commit 609f4ad

Please sign in to comment.