<s> import json <EOL> from django import template <EOL> from django . conf import settings <EOL> register = template . Library ( ) <EOL> @ register . inclusion_tag ( '<STR_LIT>' ) <EOL> def bill_full_name ( bill ) : <EOL> return { '<STR_LIT>' : bill } <EOL> @ register . inclusion_tag ( '<STR_LIT>' ) <EOL> def bill_list_item ( bill , add_li = True , show_tags = True ) : <EOL> return { '<STR_LIT>' : bill , '<STR_LIT>' : add_li , '<STR_LIT>' : show_tags } <EOL> @ register . inclusion_tag ( '<STR_LIT>' ) <EOL> def item_tags ( tags ) : <EOL> return { '<STR_LIT>' : tags } <EOL> def split_member_vote_list_by_party ( member_vote_list ) : <EOL> '''<STR_LIT>''' <EOL> list_by_party = [ ] <EOL> if len ( member_vote_list ) > <NUM_LIT:0> : <EOL> '''<STR_LIT>''' <EOL> curr_party = { '<STR_LIT>' : member_vote_list [ <NUM_LIT:0> ] . member . current_party . name , <EOL> '<STR_LIT>' : [ ] } <EOL> for vote in member_vote_list : <EOL> member = { '<STR_LIT:name>' : vote . member . name , <EOL> '<STR_LIT:url>' : vote . member . get_absolute_url ( ) , <EOL> '<STR_LIT>' : vote . member . img_url , <EOL> '<STR_LIT:id>' : vote . member . id } <EOL> if vote . member . current_party . name == curr_party [ '<STR_LIT>' ] : <EOL> curr_party [ '<STR_LIT>' ] . append ( member ) <EOL> else : <EOL> list_by_party . append ( curr_party ) <EOL> curr_party = { '<STR_LIT>' : vote . member . current_party . name , <EOL> '<STR_LIT>' : [ member ] } <EOL> '''<STR_LIT>''' <EOL> list_by_party . append ( curr_party ) <EOL> return list_by_party <EOL> def create_vote_dict ( vote ) : <EOL> for_vote_sorted = vote . for_votes ( ) . order_by ( '<STR_LIT>' ) . select_related ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> for_vote_sorted = list ( for_vote_sorted ) <EOL> for_votes_grouped = split_member_vote_list_by_party ( for_vote_sorted ) <EOL> against_vote_sorted = vote . against_votes ( ) . order_by ( '<STR_LIT>' ) . select_related ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> against_vote_sorted = list ( against_vote_sorted ) <EOL> against_votes_grouped = split_member_vote_list_by_party ( against_vote_sorted ) <EOL> vote_drill_data = dict ( { '<STR_LIT>' : dict ( { '<STR_LIT:count>' : len ( against_vote_sorted ) , <EOL> '<STR_LIT>' : against_votes_grouped } ) , <EOL> '<STR_LIT>' : dict ( { '<STR_LIT:count>' : len ( for_vote_sorted ) , <EOL> '<STR_LIT>' : for_votes_grouped } ) } ) <EOL> vote_dict = dict ( { '<STR_LIT>' : vote , <EOL> '<STR_LIT>' : json . dumps ( vote_drill_data ) , <EOL> '<STR_LIT>' : vote . for_votes_count > vote . against_votes_count , <EOL> '<STR_LIT>' : { '<STR_LIT>' : vote . time . day , <EOL> '<STR_LIT>' : vote . time . month , <EOL> '<STR_LIT>' : vote . time . year } } ) <EOL> return vote_dict <EOL> def get_explanation ( bill , proposals ) : <EOL> if hasattr ( bill , '<STR_LIT>' ) : <EOL> if bill . knesset_proposal . get_explanation ( ) != '<STR_LIT>' : <EOL> return bill . knesset_proposal . get_explanation ( ) <EOL> if hasattr ( bill , '<STR_LIT>' ) : <EOL> if bill . gov_proposal . get_explanation ( ) != '<STR_LIT>' : <EOL> return bill . gov_proposal . get_explanation ( ) <EOL> for proposal in proposals : <EOL> if proposal . get_explanation ( ) != '<STR_LIT>' : <EOL> return proposal . get_explanation ( ) <EOL> @ register . inclusion_tag ( '<STR_LIT>' ) <EOL> def bill_inabox ( bill ) : <EOL> """<STR_LIT>""" <EOL> proposals = list ( bill . proposals . all ( ) ) <EOL> proposers = bill . proposers . all ( ) <EOL> bill_inabox_dict = { <EOL> '<STR_LIT>' : bill , <EOL> '<STR_LIT>' : '<STR_LIT>' % bill . get_absolute_url ( ) , <EOL> '<STR_LIT>' : proposers [ : <NUM_LIT:3> ] , <EOL> '<STR_LIT>' : len ( proposers ) - <NUM_LIT:3> , <EOL> '<STR_LIT>' : get_explanation ( bill , proposals ) , <EOL> } <EOL> if proposals : <EOL> proposal = proposals [ - <NUM_LIT:1> ] <EOL> bill_inabox_dict [ '<STR_LIT>' ] = dict ( { '<STR_LIT>' : proposal . date . day , <EOL> '<STR_LIT>' : proposal . date . month , <EOL> '<STR_LIT>' : proposal . date . year } ) <EOL> pre_votes = list ( bill . pre_votes . all ( ) ) <EOL> pre_vote = None <EOL> if pre_votes : <EOL> pre_vote = pre_votes [ - <NUM_LIT:1> ] <EOL> bill_inabox_dict [ '<STR_LIT>' ] = create_vote_dict ( pre_vote ) <EOL> cms = list ( bill . first_committee_meetings . all ( ) ) <EOL> if cms : <EOL> first_committee_meetings = cms [ - <NUM_LIT:1> ] <EOL> bill_inabox_dict [ '<STR_LIT>' ] = dict ( { '<STR_LIT>' : first_committee_meetings . date . day , <EOL> '<STR_LIT>' : first_committee_meetings . date . month , <EOL> '<STR_LIT>' : first_committee_meetings . date . year , <EOL> '<STR_LIT:url>' : first_committee_meetings . get_absolute_url ( ) } ) <EOL> fv = bill . first_vote <EOL> if fv : <EOL> bill_inabox_dict [ '<STR_LIT>' ] = create_vote_dict ( fv ) <EOL> cms = list ( bill . second_committee_meetings . all ( ) ) <EOL> if cms : <EOL> second_committee_meetings = cms [ - <NUM_LIT:1> ] <EOL> bill_inabox_dict [ '<STR_LIT>' ] = dict ( { '<STR_LIT>' : second_committee_meetings . date . day , <EOL> '<STR_LIT>' : second_committee_meetings . date . month , <EOL> '<STR_LIT>' : second_committee_meetings . date . year , <EOL> '<STR_LIT:url>' : second_committee_meetings . get_absolute_url ( ) } ) <EOL> av = bill . approval_vote <EOL> if av : <EOL> bill_inabox_dict [ '<STR_LIT>' ] = create_vote_dict ( av ) <EOL> return bill_inabox_dict </s>
