Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
http permanent redirect to committees-next static pages
Browse files Browse the repository at this point in the history
  • Loading branch information
OriHoch committed Nov 29, 2017
1 parent cf32fdc commit cfb953f
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 69 deletions.
95 changes: 27 additions & 68 deletions committees/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,86 +5,45 @@
MeetingsListView, MeetingDetailView, MeetingTagListView,
CommitteeListView, CommitteeDetailView, TopicListView, TopicsMoreView,
TopicDetailView, delete_topic, delete_topic_rating, meeting_list_by_date,
edit_topic, CommitteeMMMDocuments, UnpublishedProtocolslistView, FutureMeetingslistView)
# from django.http.response import HttpResponse, Http404
# import os
edit_topic, CommitteeMMMDocuments, UnpublishedProtocolslistView, FutureMeetingslistView,
static_committee_detail_redirect, static_committee_redirect, static_committee_meeting_redirect
)


meetings_list = MeetingsListView.as_view()
unpublished_protocols_list = UnpublishedProtocolslistView.as_view()
future_meetings_list = FutureMeetingslistView.as_view()


# def static_committees_index_view(request):
# filepath = "/oknesset_web/committees/dist/committees/index.html"
# if os.path.exists(filepath):
# with open(filepath) as f:
# return HttpResponse(f.read())
# else:
# return CommitteeListView.as_view()(request)
#
#
# def static_committees_page_view(request, *args):
# filepath = "/oknesset_web/committees/dist/{}".format(request.path)
# if os.path.exists(filepath):
# with open(filepath) as f:
# return HttpResponse(f.read())
# else:
# return Http404()


committeesurlpatterns = patterns('',
# static committee pages
# url(r'^committee/$', static_committees_index_view, name='committee-list'),
# url(r'^committees/knesset-(\d+).html', static_committees_page_view),
# url(r'^committees/(\d+).html', static_committees_page_view),
# url(r'^meetings/(\d+)/(\d+)/(\d+).html', static_committees_page_view),
# url(r'^committees/index.html', static_committees_page_view),

url(r'^committee/$', CommitteeListView.as_view(), name='committee-list'),
url(r'^committee/more-topics/$', TopicsMoreView.as_view(),
name='committee-topics-more'),
url(r'^committee/(?P<pk>\d+)/$', CommitteeDetailView.as_view(),
committeesurlpatterns = patterns('',
url(r'^committee/$', static_committee_redirect('committees/index.html'),
name='committee-list'),
url(r'^committee/(?P<pk>\d+)/$', static_committee_detail_redirect(),
name='committee-detail'),
url(r'^committee/all_meetings/$', meetings_list, name='committee-all-meetings'),
url(r'^committee/(?P<committee_id>\d+)/all_meetings/$', meetings_list,
url(r'^committee/all_meetings/$', static_committee_redirect('committees/index.html'),
name='committee-all-meetings'),
url(r'^committee/(?P<pk>\d+)/all_meetings/$', static_committee_detail_redirect(),
name='committee-all-meetings'),
url(r'^committee/(?P<committee_id>\d+)/all_unpublished_protocols/$',
unpublished_protocols_list, name='committee-all-unpublished-protocols'),
url(r'^committee/(?P<committee_id>\d+)/all_future_meetings/$', future_meetings_list,
name='committee-all-future-meetings'),
url(r'^committee/date/(?P<date>[\d\-]+)/$', meeting_list_by_date,
name='committee-meetings-by-date'),
url(r'^committee/(?P<committee_id>\d+)/date/(?P<date>[\d\-]+)/$', meeting_list_by_date,
name='committee-meetings-by-date'),
url(r'^committee/(?P<committee_id>\d+)/date/$', meeting_list_by_date,
name='committee-meetings-by-date'),
url(r'^committee/(?P<committee_id>\d+)/topic/$', TopicListView.as_view(),
name='committee-topic-list'),
url(r'^committee/(?P<committee_id>\d+)/topic/add/$',
edit_topic,
name='edit-committee-topic'),
url(r'^committee/(?P<committee_id>\d+)/topic/edit/(?P<topic_id>\d+)/$',
edit_topic,
name='edit-committee-topic'),
url(r'^committee/meeting/(?P<pk>\d+)/$', MeetingDetailView.as_view(),
url(r'^committee/(?P<pk>\d+)/all_unpublished_protocols/$',
static_committee_detail_redirect(), name='committee-all-unpublished-protocols'),
url(r'^committee/(?P<pk>\d+)/all_future_meetings/$',
static_committee_detail_redirect(), name='committee-all-future-meetings'),
url(r'^committee/date/(?P<date>[\d\-]+)/$',
static_committee_redirect('committees/index.html'), name='committee-meetings-by-date'),
url(r'^committee/(?P<pk>\d+)/date/(?P<date>[\d\-]+)/$',
static_committee_detail_redirect(), name='committee-meetings-by-date'),
url(r'^committee/(?P<pk>\d+)/date/$',
static_committee_detail_redirect(), name='committee-meetings-by-date'),
url(r'^committee/(?P<pk>\d+)/topic/$',
static_committee_detail_redirect(), name='committee-topic-list'),
url(r'^committee/meeting/(?P<pk>\d+)/$', static_committee_meeting_redirect(),
name='committee-meeting'),
url(r'^committee/meeting/tag/(?P<tag>.*)/$', MeetingTagListView.as_view(),
name='committeemeeting-tag'),
url(r'^committee/topic/$', TopicListView.as_view(), name='topic-list'),
url(r'^committee/topic/(?P<pk>\d+)/delete/$', delete_topic,
name='delete-committee-topic'),
url(r'^committee/topic/(?P<pk>\d+)/$', TopicDetailView.as_view(), name='topic-detail'),
url(r'^committee/topic/(?P<object_id>\d+)/(?P<score>\d+)/$',
AddRatingFromModel(),
{'app_label': 'committees', 'model': 'topic', 'field_name': 'rating'},
name='rate-topic'),
url(r'^committee/topic/(?P<object_id>\d+)/null/$', delete_topic_rating,
name='delete-topic-rating'),
url(r'^committee/(?P<committee_id>\d+)/mmm_documents/$',
CommitteeMMMDocuments.as_view(),
name='committee-mmm-documents-list'),
url(r'^committee/(?P<committee_id>\d+)/mmm_documents/date/(?P<date>[\d\-]+)/$',
CommitteeMMMDocuments.as_view(),
url(r'^committee/(?P<pk>\d+)/mmm_documents/$',
static_committee_detail_redirect(), name='committee-mmm-documents-list'),
url(r'^committee/(?P<pk>\d+)/mmm_documents/date/(?P<date>[\d\-]+)/$',
static_committee_detail_redirect(),
name='committee-mmm-documents-list-by-date'),
)
51 changes: 50 additions & 1 deletion committees/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import json
import logging
import re
import os
import csv

import waffle

Expand All @@ -19,7 +21,7 @@
from django.core.urlresolvers import reverse
from django.db.models import Q
from django.http import (HttpResponse, HttpResponseRedirect, Http404,
HttpResponseForbidden)
HttpResponseForbidden, HttpResponsePermanentRedirect)
from django.shortcuts import get_object_or_404, render_to_response
from django.template import RequestContext
from django.utils.decorators import method_decorator
Expand Down Expand Up @@ -760,3 +762,50 @@ def get_context_data(self, **kwargs):
context['committee_id'] = self.c_id
context['committee_url'] = committee.get_absolute_url()
return context


def static_committee_redirect(distpath):
def view(*args, **kwargs):
return HttpResponsePermanentRedirect("https://committees-next.oknesset.org/" + distpath)
return view


def static_committee_detail_redirect():
def view(*args, **kwargs):
if os.path.exists("/oknesset_web/kns_committee.csv"):
try:
committee = Committee.objects.get(pk=kwargs["pk"])
except ObjectDoesNotExist:
committee = None
if committee:
latest_committee_knesset_num, latest_committee_kns_id = -1, None
for i, line in enumerate(csv.reader(open("/oknesset_web/kns_committee.csv"))):
if i == 0: continue
kns_id = int(line[0])
category_id = int(line[2]) if line[2] else None
knesset_num = int(line[4])
if category_id and committee.knesset_id \
and category_id == committee.knesset_id \
and knesset_num and knesset_num > latest_committee_knesset_num:
latest_committee_knesset_num = knesset_num
latest_committee_kns_id = kns_id
if latest_committee_kns_id:
return HttpResponsePermanentRedirect("https://committees-next.oknesset.org/committees/{}.html".format(latest_committee_kns_id))
return HttpResponseRedirect("https://committees-next.oknesset.org/committees/index.html")
return view


def static_committee_meeting_redirect():
def view(*args, **kwargs):
try:
meeting = CommitteeMeeting.objects.get(pk=kwargs["pk"])
except ObjectDoesNotExist:
meeting = None
if meeting and meeting.knesset_id:
knesset_id = str(meeting.knesset_id)
return HttpResponsePermanentRedirect(
"https://committees-next.oknesset.org/meetings/{}/{}/{}.html".format(knesset_id[0],
knesset_id[1],
knesset_id))
return HttpResponseRedirect("https://committees-next.oknesset.org/committees/index.html")
return view

0 comments on commit cfb953f

Please sign in to comment.