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 #597 from alonisser/master
Browse files Browse the repository at this point in the history
hotfix for missing code in pr (adding removing mk) and more issues
  • Loading branch information
OriHoch committed Mar 8, 2016
2 parents ef6abc1 + b92b0ca commit abbe9d6
Show file tree
Hide file tree
Showing 18 changed files with 198 additions and 129 deletions.
17 changes: 9 additions & 8 deletions committees/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
from django.contrib.contenttypes.generic import GenericTabularInline
from django.db.models import Q
from django.contrib import admin
from import_export.admin import ImportExportModelAdmin

from video.models import Video
from models import Committee, CommitteeMeeting, Topic
from links.models import Link
from django.utils.translation import ugettext_lazy as _
from mks.utils import get_all_mk_names
import logging


logger = logging.getLogger(__name__)



class CommitteeRelatedVideosInline(generic.GenericTabularInline):
model = Video
ct_fk_field = 'object_pk'
Expand All @@ -29,7 +29,7 @@ def queryset(self, request):
return qs


class CommitteeAdmin(admin.ModelAdmin):
class CommitteeAdmin(ImportExportModelAdmin):
ordering = ('name',)
filter_horizontal = ('members', 'chairpersons', 'replacements')
inlines = (CommitteeRelatedVideosInline,)
Expand Down Expand Up @@ -76,7 +76,7 @@ def queryset(self, request, queryset):
return queryset


class CommitteeMeetingAdmin(admin.ModelAdmin):
class CommitteeMeetingAdmin(ImportExportModelAdmin):
ordering = ('-date',)
list_display = ('__unicode__', 'date', 'committee_type', 'protocol_parts')
list_filter = ('committee', 'committee__type', MissingProtocolListFilter)
Expand All @@ -93,14 +93,15 @@ def redownload_and_reparse_protocol(self, request, qs):
mks, mk_names = get_all_mk_names()
for meeting in qs:
meeting.reparse_protocol(mks=mks, mk_names=mk_names)
self.message_user(request, "successfully redownloaded & reparsed %s meetings"%qs.count())
self.message_user(request, "successfully redownloaded & reparsed %s meetings" % qs.count())

def reparse_protocol(self, request, qs):
mks, mk_names = get_all_mk_names()
for meeting in qs:
logger.debug('reparsing meeting %s'%meeting.pk)
logger.debug('reparsing meeting %s' % meeting.pk)
meeting.reparse_protocol(redownload=False, mks=mks, mk_names=mk_names)
self.message_user(request, "successfully reparsed %s meetings"%qs.count())
self.message_user(request, "successfully reparsed %s meetings" % qs.count())


admin.site.register(CommitteeMeeting, CommitteeMeetingAdmin)

Expand All @@ -111,7 +112,7 @@ class LinksTable(GenericTabularInline):
ct_fk_field = 'object_pk'


class TopicAdmin(admin.ModelAdmin):
class TopicAdmin(ImportExportModelAdmin):
ordering = ('-created',)
list_select_related = True
exclude = ('meetings',)
Expand Down
2 changes: 1 addition & 1 deletion committees/tests/test_committee_meeting_detail_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def _given_mk_removed_from_meeting(self, meeting, mk):
return self.client.post(reverse('committee-meeting',
kwargs={'pk': meeting.id}),
{'user_input_type': 'remove-mk',
'mk_name': mk.name})
'mk_name_to_remove': mk.name})

def _given_lobbyist_added_to_meeting(self, meeting, lobbyist):
return self.client.post(reverse('committee-meeting',
Expand Down
24 changes: 15 additions & 9 deletions committees/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def get_context_data(self, *args, **kwargs):
return context

def _resolve_handler_by_user_input_type(self, user_input_type):
handler = self._action_handlers.get(user_input_type)
handler = self._action_handlers.get(user_input_type)
return getattr(self, handler)

@hashnav_method_decorator(login_required)
Expand Down Expand Up @@ -197,10 +197,13 @@ def _handle_add_lobbyist(self, cm, request):
cm.lobbyists_mentioned.add(l)

def _handle_remove_mk(self, cm, request):
mk_names = Member.objects.values_list('name', flat=True)
mk_name = difflib.get_close_matches(request.POST.get('mk_name'),
mk_names)[0]
mk = Member.objects.get(name=mk_name)
if not request.POST.get('mk_id'):
mk_names = Member.objects.values_list('name', flat=True)
mk_name = difflib.get_close_matches(request.POST.get('mk_name_to_remove'),
mk_names)[0]
mk = Member.objects.get(name=mk_name)
else:
mk = Member.objects.get(id=request.POST.get('mk_id'))
cm.mks_attended.remove(mk)
cm.save() # just to signal, so the attended Action gets created.
action.send(request.user,
Expand All @@ -210,10 +213,13 @@ def _handle_remove_mk(self, cm, request):
timestamp=datetime.datetime.now())

def _handle_add_mk(self, cm, request):
mk_names = Member.objects.values_list('name', flat=True)
mk_name = difflib.get_close_matches(request.POST.get('mk_name'),
mk_names)[0]
mk = Member.objects.get(name=mk_name)
if not request.POST.get('mk_id'):
mk_names = Member.objects.values_list('name', flat=True)
mk_name = difflib.get_close_matches(request.POST.get('mk_name'),
mk_names)[0]
mk = Member.objects.get(name=mk_name)
else:
mk = Member.objects.get(id=request.POST.get('mk_id'))
cm.mks_attended.add(mk)
cm.save() # just to signal, so the attended Action gets created.
action.send(request.user,
Expand Down
3 changes: 2 additions & 1 deletion events/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib import admin
from django.contrib.contenttypes import generic
from import_export.admin import ImportExportModelAdmin

from links.models import Link
from models import Event
Expand All @@ -12,7 +13,7 @@ class EventLinksInline(generic.GenericTabularInline):
extra = 1


class EventAdmin(admin.ModelAdmin):
class EventAdmin(ImportExportModelAdmin):

ordering = ('when',)
list_display = ('when', 'what', 'where')
Expand Down
29 changes: 15 additions & 14 deletions events/scrapers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,25 @@
import json
import dateutil.parser


class PersonsEventsScraper(BaseScraper):
"""
runs the MkEventsScraper for each mk with a calendar url
"""
"""

def __init__(self):
super(PersonsEventsScraper, self).__init__(self)
self.source = BaseSource()
self.storage = BaseStorage()

def _get_google_cal_page(self, calendar_id, sync_token, page_token=None):
api_key = settings.GOOGLE_CALENDAR_API_KEY
if page_token is not None:
param = '&pageToken=%s'%quote(page_token)
param = '&pageToken=%s' % quote(page_token)
else:
param = '&syncToken=%s'%quote(sync_token) if sync_token is not None else ''
url = 'https://content.googleapis.com/calendar/v3/calendars/%s/events?showDeleted=true&singleEvents=true%s&key=%s' % (quote(calendar_id), param, quote(api_key))
param = '&syncToken=%s' % quote(sync_token) if sync_token is not None else ''
url = 'https://content.googleapis.com/calendar/v3/calendars/%s/events?showDeleted=true&singleEvents=true%s&key=%s' % (
quote(calendar_id), param, quote(api_key))
response = urllib2.urlopen(url)
data = json.load(response)
self._getLogger().debug(data)
Expand All @@ -38,22 +40,24 @@ def _get_google_cal_page(self, calendar_id, sync_token, page_token=None):
res['nextPageToken'] = data['nextPageToken'] if 'nextPageToken' in data else None
res['items'] = data['items'] if 'items' in data else []
return res

def _process_items(self, person, items):
self._getLogger().info('processing %s items' % len(items))
for item in items:
status = item.get('status', None)
icaluid = item.get('iCalUID', None)
start_date = dateutil.parser.parse(item['start']['dateTime']) if 'start' in item and 'dateTime' in item['start'] else None
end_date = dateutil.parser.parse(item['end']['dateTime']) if 'end' in item and 'dateTime' in item['end'] else None
start_date = dateutil.parser.parse(item['start']['dateTime']) if 'start' in item and 'dateTime' in item[
'start'] else None
end_date = dateutil.parser.parse(item['end']['dateTime']) if 'end' in item and 'dateTime' in item[
'end'] else None
if not all([start_date, end_date, status, icaluid]):
self._getLogger().error('invalid start / end date / status / iCalUID')
elif status == 'cancelled':
res = Event.objects.filter(icaluid=icaluid)
if res.count() == 1:
self._getLogger().info('deleted event')
res = res[0]
res.cancelled=True
res.cancelled = True
res.save()
else:
self._getLogger().info('failed to delete event')
Expand All @@ -69,7 +73,7 @@ def _process_items(self, person, items):
colorId = item['colorId'] if 'colorId' in item else None
data = unicode(item)
kwargs = {
'when':start_date, 'when_over':end_date, 'link':link, 'what':summary, 'why':description,
'when': start_date, 'when_over': end_date, 'link': link, 'what': summary, 'why': description,
'update_date': update_date,
}
res = Event.objects.filter(icaluid=icaluid)
Expand Down Expand Up @@ -100,6 +104,3 @@ def _scrape(self):
else:
person.calendar_sync_token = res['nextSyncToken']
person.save()



1 change: 1 addition & 0 deletions knesset/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
'corsheaders',
'sslserver',
'waffle',
'import_export',
# 'knesset',
'auxiliary', # knesset apps
'mks',
Expand Down
6 changes: 4 additions & 2 deletions laws/admin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from import_export.admin import ImportExportModelAdmin

from models import Vote, Law, PrivateProposal, KnessetProposal, GovProposal, Bill, GovLegislationCommitteeDecision
from laws.management.commands.scrape_votes import Command as ScrapeVotesCommand
from django.utils.translation import ugettext_lazy as _
from django.contrib import admin


class VoteAdmin(admin.ModelAdmin):
class VoteAdmin(ImportExportModelAdmin):
# filter_horizontal = ('voted_for','voted_against','voted_abstain','didnt_vote')
list_display = (
'__unicode__', 'short_summary', 'full_text_link', 'votes_count', 'for_votes_count', 'against_votes_count',
Expand Down Expand Up @@ -33,7 +35,7 @@ def recreate_vote(self, request, queryset):
admin.site.register(Vote, VoteAdmin)


class LawAdmin(admin.ModelAdmin):
class LawAdmin(ImportExportModelAdmin):
pass


Expand Down
23 changes: 11 additions & 12 deletions laws/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def __init__(self, vote, *args, **kwargs):
self.fields['vote_model'].initial = vote
self.fields['vote_type'].initial = self.get_default_vote_type(vote)


def clean(self):
cleaned_data = super(AttachBillFromVoteForm, self).clean()
vote_type = cleaned_data.get('vote_type')
Expand All @@ -60,8 +59,8 @@ def clean(self):
code="cannot-link")

vote = cleaned_data.get('vote_model')
vote_already_linked = Bill.objects\
.filter(approval_vote=vote).count() > 0
vote_already_linked = Bill.objects \
.filter(approval_vote=vote).count() > 0

if vote_already_linked:
raise forms.ValidationError(
Expand All @@ -70,7 +69,6 @@ def clean(self):

return cleaned_data


def get_default_vote_type(self, vote):
for h in CONVERT_TO_DISCUSSION_HEADERS:
if vote.title.find(h) >= 0:
Expand All @@ -90,22 +88,22 @@ class BudgetEstimateForm(forms.Form):
be_yearly_gov = forms.IntegerField(label=_('Yearly costs to government'), required=False)
be_one_time_ext = forms.IntegerField(label=_('One-time costs to external bodies'), required=False)
be_yearly_ext = forms.IntegerField(label=_('Yearly costs to external bodies'), required=False)
be_summary = forms.CharField(label=_('Summary of the estimation'),widget=forms.Textarea,required=False)
be_summary = forms.CharField(label=_('Summary of the estimation'), widget=forms.Textarea, required=False)

def __init__(self, bill, user, *args, **kwargs):
super(BudgetEstimateForm, self).__init__(*args, **kwargs)

if bill is not None and user is not None:
try:
be = BillBudgetEstimation.objects.get(bill=bill,estimator__username=str(user))
be = BillBudgetEstimation.objects.get(bill=bill, estimator__username=str(user))
self.fields['be_one_time_gov'].initial = be.one_time_gov
self.fields['be_yearly_gov'].initial = be.yearly_gov
self.fields['be_one_time_ext'].initial = be.one_time_ext
self.fields['be_yearly_ext'].initial = be.yearly_ext
self.fields['be_summary'].initial = be.summary
except BillBudgetEstimation.DoesNotExist:
pass
#self.fields['tagged'].choices = new_choices
# self.fields['tagged'].choices = new_choices


class VoteSelectForm(forms.Form):
Expand Down Expand Up @@ -149,18 +147,19 @@ class BillSelectForm(forms.Form):
"""Bill filtering form"""

stage = forms.ChoiceField(label=_('Bill Stage'), choices=BILL_STAGE_CHOICES,
required=False, initial='all')
required=False, initial='all')
bill_type = forms.ChoiceField(label=_('Bill type'), choices=(
('all', _('All')),
('private', _('Private Proposal')),
('knesset', _('Knesset Proposal')),
('government', _('Government Proposal')),
), required=False)
tagged = forms.ChoiceField(label=_('Tags'), choices=BILL_TAGGED_CHOICES,
required=False, initial='all')
required=False, initial='all')
changed_after = forms.DateField(label=_('Stage Changed After:'), required=False,
input_formats=["%d/%m/%Y", "%d/%m/%y"])
input_formats=["%d/%m/%Y", "%d/%m/%y"])
changed_before = forms.DateField(label=_('Stage Chaged Before:'), required=False,
input_formats=["%d/%m/%Y", "%d/%m/%y"])
input_formats=["%d/%m/%Y", "%d/%m/%y"])

pp_id = forms.IntegerField(required=False,
label=_('Private proposal ID'))
Expand Down Expand Up @@ -191,7 +190,7 @@ def __init__(self, *args, **kwargs):
def clean(self):
super(BillSelectForm, self).clean()

#override stage error on aggregate stages (when accessing from mk page)
# override stage error on aggregate stages (when accessing from mk page)
if ((self.data.get('stage') in BILL_AGRR_STAGES) and
('stage' in self._errors)):
del self._errors['stage']
Expand Down
22 changes: 13 additions & 9 deletions laws/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re, logging, random, sys, traceback
from datetime import date, timedelta

from django.contrib.comments import Comment
from django.db import models, IntegrityError
from django.contrib.contenttypes import generic
from django import forms
Expand Down Expand Up @@ -597,28 +598,31 @@ def filter_and_order(self, *args, **kwargs):
elif bill_type == 'knesset':
qs = qs.exclude(knesset_proposal=None)

elif bill_type == 'private':
qs = qs.exclude(proposals=None)

if pp_id:
pps = PrivateProposal.objects.filter(
private_proposals = PrivateProposal.objects.filter(
proposal_id=pp_id).values_list(
'id', flat=True)
if pps:
qs = qs.filter(proposals__in=pps)
if private_proposals:
qs = qs.filter(proposals__in=private_proposals)
else:
qs = qs.none()

if knesset_booklet:
kps = KnessetProposal.objects.filter(
knesset_proposals = KnessetProposal.objects.filter(
booklet_number=knesset_booklet).values_list(
'id', flat=True)
if kps:
qs = qs.filter(knesset_proposal__in=kps)
if knesset_proposals:
qs = qs.filter(knesset_proposal__in=knesset_proposals)
else:
qs = qs.none()
if gov_booklet:
gps = GovProposal.objects.filter(
government_proposals = GovProposal.objects.filter(
booklet_number=gov_booklet).values_list('id', flat=True)
if gps:
qs = qs.filter(gov_proposal__in=gps)
if government_proposals:
qs = qs.filter(gov_proposal__in=government_proposals)
else:
qs = qs.none()

Expand Down
Loading

0 comments on commit abbe9d6

Please sign in to comment.