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

Commit

Permalink
Merge pull request #728 from alonisser/bugfix_724_726_727
Browse files Browse the repository at this point in the history
Bugfix 724 726 727
  • Loading branch information
alonisser authored Oct 1, 2016
2 parents ac588b1 + 22438b9 commit 3a67ab7
Show file tree
Hide file tree
Showing 15 changed files with 295 additions and 115 deletions.
31 changes: 17 additions & 14 deletions committees/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def annotations(self):
committee_tn = Committee._meta.db_table
annotation_tn = Annotation._meta.db_table
protocol_part_ct = ContentType.objects.get_for_model(ProtocolPart)
ret = Annotation.objects.filter(content_type=protocol_part_ct)
ret = Annotation.objects.select_related().filter(content_type=protocol_part_ct)
return ret.extra(tables=[protocol_part_tn,
meeting_tn, committee_tn],
where=["%s.object_id=%s.id" % (annotation_tn, protocol_part_tn),
Expand Down Expand Up @@ -277,9 +277,9 @@ def __unicode__(self):
@models.permalink
def get_absolute_url(self):
if self.committee.type == 'plenum':
return ('plenum-meeting', [str(self.id)])
return 'plenum-meeting', [str(self.id)]
else:
return ('committee-meeting', [str(self.id)])
return 'committee-meeting', [str(self.id)]

def _get_tags(self):
tags = Tag.objects.get_for_object(self)
Expand All @@ -300,7 +300,7 @@ def create_protocol_parts(self, delete_existing=False, mks=None, mk_names=None):
delete them, a ValidationError will be thrown, because
it doesn't make sense to create the parts again.
"""
logger.debug('create_protocol_parts %s'%delete_existing)
logger.debug('create_protocol_parts %s' % delete_existing)
if delete_existing:
ppct = ContentType.objects.get_for_model(ProtocolPart)
annotations = Annotation.objects.filter(content_type=ppct, object_id__in=self.parts.all)
Expand All @@ -320,18 +320,19 @@ def create_protocol_parts(self, delete_existing=False, mks=None, mk_names=None):
return
else:
def get_protocol_part(i, part):
logger.debug('creating protocol part %s'%i)
logger.debug('creating protocol part %s' % i)
return ProtocolPart(meeting=self, order=i, header=part.header, body=part.body)

with KnessetDataCommitteeMeetingProtocol.get_from_text(self.protocol_text) as protocol:
# TODO: use bulk_create (I had a strange error when using it)
# ProtocolPart.objects.bulk_create(
# for testing, you could just save one part:
# get_protocol_part(1, protocol.parts[0]).save()
list([
get_protocol_part(i, part).save()
for i, part
in zip(range(1, len(protocol.parts)+1), protocol.parts)
])
get_protocol_part(i, part).save()
for i, part
in zip(range(1, len(protocol.parts) + 1), protocol.parts)
])
self.protocol_parts_update_date = datetime.now()
self.save()

Expand All @@ -347,7 +348,7 @@ def redownload_protocol(self):
self.protocol_text = protocol.text
self.protocol_text_update_date = datetime.now()
self.save()
except AntiwordException, e:
except AntiwordException as e:
logger.error(
e.message,
exc_info=True,
Expand All @@ -373,14 +374,16 @@ def update_from_dataservice(self, dataservice_object=None):
if dataservice_object is None:
ds_meetings = [
ds_meeting for ds_meeting
in DataserviceCommitteeMeeting.get(self.committee.knesset_id, self.date - timedelta(days=1), self.date + timedelta(days=1))
in DataserviceCommitteeMeeting.get(self.committee.knesset_id, self.date - timedelta(days=1),
self.date + timedelta(days=1))
if str(ds_meeting.id) == str(self.knesset_id)
]
]
if len(ds_meetings) != 1:
raise Exception('could not found corresponding dataservice meeting')
dataservice_object = ds_meetings[0]
meeting_transformed = ScrapeCommitteeMeetingCommand().get_committee_meeting_fields_from_dataservice(dataservice_object)
[setattr(self, k, v) for k,v in meeting_transformed.iteritems()]
meeting_transformed = ScrapeCommitteeMeetingCommand().get_committee_meeting_fields_from_dataservice(
dataservice_object)
[setattr(self, k, v) for k, v in meeting_transformed.iteritems()]
self.save()

@property
Expand Down
52 changes: 42 additions & 10 deletions committees/tests/test_committee_meeting_detail_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
APP = 'committees'


class CommitteeMeetingDetailViewTest(TestCase):
class CommitteeMeetingDetailViewTestCase(TestCase):
def setUp(self):
super(CommitteeMeetingDetailViewTest, self).setUp()
super(CommitteeMeetingDetailViewTestCase, self).setUp()
self.knesset = Knesset.objects.create(number=1,
start_date=datetime.today() - timedelta(days=1))
self.committee_1 = Committee.objects.create(name='c1')
Expand Down Expand Up @@ -54,10 +54,13 @@ def setUp(self):
self.topic = self.committee_1.topic_set.create(creator=self.jacob,
title="hello", description="hello world")
self.tag_1 = Tag.objects.create(name='tag1')
self.meeting_1.mks_attended.add(self.mk_1)
self.given_mk_attended_meeting(self.meeting_1, self.mk_1)

def given_mk_attended_meeting(self, meeting, mk):
meeting.mks_attended.add(mk)

def tearDown(self):
super(CommitteeMeetingDetailViewTest, self).tearDown()
super(CommitteeMeetingDetailViewTestCase, self).tearDown()
self.client.logout()
self.meeting_1.delete()
self.meeting_2.delete()
Expand Down Expand Up @@ -158,19 +161,35 @@ def test_committee_meeting_returns_correct_members(self):
self.assertEqual(res.status_code, 200)
self.assertTemplateUsed(res,
'committees/committeemeeting_detail.html')
members = res.context['members']
self.assertEqual(map(just_id, members),
[self.mk_1.id],
'members has wrong objects: %s' % members)
self._verify_expected_members_in_context(res, [self.mk_1.id])

def test_mk_from_current_knesset_that_are_not_current_members_are_not_displayed(self):
not_current_mk = Member.objects.create(name='mk 1', is_current=False)
self.given_mk_attended_meeting(self.meeting_1, not_current_mk)
self._given_mk_added_to_meeting(self.meeting_1, not_current_mk)
res = self.client.get(self.meeting_1.get_absolute_url())
self.assertEqual(res.status_code, 200)
self._verify_expected_members_in_context(res, [self.mk_1.id])
self._verify_unexpected_members_not_in_context(res, [not_current_mk.id])

def test_user_can_add_a_bill_to_meetings_if_not_login(self):
def test_user_can_not_add_a_bill_to_meetings_if_not_login(self):
res = self.client.post(reverse('committee-meeting',
kwargs={'pk': self.meeting_1.id}))
self._verify_bill_not_in_meeting(self.bill_1, self.meeting_1)
self.assertEqual(res.status_code, 302)
self.assertTrue(res['location'].startswith('%s%s' %
('http://testserver', settings.LOGIN_URL)))

def _verify_expected_members_in_context(self, res, expected_mks):
members = res.context['members']
self.assertEqual(map(just_id, members),
expected_mks,
'members has wrong objects: %s' % members)

def _verify_unexpected_members_not_in_context(self, res, unexpected_members):
members = res.context['members']
self.assertNotIn(unexpected_members, map(just_id, members), 'members has wrong objects: %s' % members)

def test_post_removing_and_adding_mk_to_committee_meetings(self):
mk_1 = self.mk_1
meeting = self.meeting_1
Expand All @@ -197,7 +216,6 @@ def test_post_removing_and_adding_mk_without_params_get_404_response(self):
res = self._given_mk_added_to_meeting(meeting, mk_1)
self.assertEqual(res.status_code, 404)


def test_post_adds_bill_to_committee_meeting(self):
bill_1 = self.bill_1
meeting = self.meeting_1
Expand Down Expand Up @@ -238,6 +256,20 @@ def test_adding_non_existent_lobbyist_returns_404(self):
res = self._given_lobbyist_added_to_meeting(meeting, lobbyist_name='non existing')
self.assertEqual(res.status_code, 404)

def test_committee_meetings_handles_missing_lobbyist_data(self):
lobbyist = self._setup_lobbyist()

meeting = self.meeting_1

self.assertTrue(self.client.login(username='jacob', password='JKM'))
self._given_lobbyist_added_to_meeting(meeting, lobbyist=lobbyist)
res = self.client.get(self.meeting_1.get_absolute_url())
self.assertEqual(res.status_code, 200)

lobbyist.data.all().delete()

res = self.client.get(self.meeting_1.get_absolute_url())
self.assertEqual(res.status_code, 200)

def test_add_tag_committee_login_required(self):
url = reverse('add-tag-to-object',
Expand Down
86 changes: 48 additions & 38 deletions committees/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#encoding: UTF-8
# encoding: UTF-8
from django.conf.urls import url, patterns
from djangoratings.views import AddRatingFromModel
from views import (
Expand All @@ -7,45 +7,55 @@
TopicDetailView, delete_topic, delete_topic_rating, meeting_list_by_date,
edit_topic, CommitteeMMMDocuments, UnpublishedProtocolslistView, FutureMeetingslistView)


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

committeesurlpatterns = patterns('',
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(), 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, 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(), 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(),
name='committee-mmm-documents-list-by-date'),
)
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(),
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,
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(),
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(),
name='committee-mmm-documents-list-by-date'),
)
Loading

0 comments on commit 3a67ab7

Please sign in to comment.