Legislative or executive office?
557973
def route_election(self, election):
        
        if (
            election.election_type.slug == ElectionType.GENERAL
            or ElectionType.GENERAL_RUNOFF
        ):
            self.bootstrap_general_election(election)
        elif election.race.special:
            self.bootstrap_special_election(election)

        if election.race.office.is_executive:
            self.bootstrap_executive_office(election)
        else:
            self.bootstrap_legislative_office(election)
675141
def page_location(self):
        
        cycle = self.election_day.cycle.name
        if self.content_type.model_class() == PageType:
            print(self.content_object)
            return self.content_object.page_location_template()
        elif self.content_type.model_class() == Division:
            if self.content_object.level.name == DivisionLevel.STATE:
                if self.special_election:
                    # /{state}/special-election/{month-day}/
                    path = os.path.join(
                        self.content_object.slug,
                        "special-election",
                        self.election_day.special_election_datestring(),
                    )
                else:
                    # /{state}/
                    path = self.content_object.slug
            else:
                # /  National
                path = ""
        # Offices and Bodies
        else:
            if self.division.level.name == DivisionLevel.STATE:
                if not self.content_object.body:
                    path = os.path.join(self.division.slug, "governor")
                else:
                    path = os.path.join(
                        self.division.slug, self.content_object.slug
                    )
            else:
                path = self.content_object.slug
        return (
            os.sep + os.path.normpath(os.path.join(cycle, path)) + os.sep
        )
327544
function isSameNotification(a, b) {
        return a.type === b.settings.type && a.text === b.settings.text;
      }
875237
def by_type(self, chamber, type, congress=CURRENT_CONGRESS):
        ""
        check_chamber(chamber)

        path = "{congress}/{chamber}/votes/{type}.json".format(
            congress=congress, chamber=chamber, type=type)
        return self.fetch(path)
356093
def _gt_from_le(self, other):
    """"""
    op_result = self.__le__(other)
    if op_result is NotImplemented:
        return NotImplemented
    return not op_result
402377
def activate_legislators(current_term, abbr):
    
    for legislator in db.legislators.find(
        {'roles': {'$elemMatch':
                   {settings.LEVEL_FIELD: abbr, 'term': current_term}}}):
        active_role = legislator['roles'][0]

        if not active_role.get('end_date') and active_role['type'] == 'member':
            legislator['active'] = True
            legislator['party'] = active_role.get('party', None)
            legislator['district'] = active_role.get('district', None)
            legislator['chamber'] = active_role.get('chamber', None)

        legislator['updated_at'] = datetime.datetime.utcnow()
        db.legislators.save(legislator, safe=True)
977527
def logical_or(self, other):
        """"""
        return self.operation(other, lambda x, y: int(x or y))
1334844
def get_elections(self, obj):
        """"""
        election_day = ElectionDay.objects.get(
            date=self.context["election_date"]
        )

        kwargs = {"race__office__body": obj, "election_day": election_day}
        if self.context.get("division") and obj.slug == "senate":
            kwargs["division"] = self.context["division"]
        elif self.context.get("division") and obj.slug == "house":
            kwargs["division__parent"] = self.context["division"]

        if obj.slug == "house" and not self.context.get("division"):
            kwargs["race__special"] = False

        elections = Election.objects.filter(**kwargs)
        return ElectionSerializer(elections, many=True).data
954146
def office_content(self, election_day, office):
        
        from electionnight.models import PageType

        office_type = ContentType.objects.get_for_model(office)
        page_type = PageType.objects.get(
            model_type=office_type,
            election_day=election_day,
            division_level=office.division.level,
        )

        page_content = self.get(
            content_type__pk=office_type.pk,
            object_id=office.pk,
            election_day=election_day,
        )
        page_type_content = self.get(
            content_type=ContentType.objects.get_for_model(page_type),
            object_id=page_type.pk,
            election_day=election_day,
        )
        return {
            "site": self.site_content(election_day)["site"],
            "page_type": self.serialize_content_blocks(page_type_content),
            "page": self.serialize_content_blocks(page_content),
        }
1049413
public void voteFor(WeightedItem<T> weightedItem) {
        reorganizationCounter++;
        weightedItem.vote();
        if (reorganizationCounter == maxVotesBeforeReorganization) {
            reorganizationCounter = 0;
            organizeAndAdd(null);
        }
    }
1046247
def OR(self):
        
        clone = copy.deepcopy(self)
        clone.adapter._QUERY_GLUE = ' OR '
        return clone
362506
def get_precinctsreporting(self, obj):
        """"""
        if obj.division.level == \
                obj.candidate_election.election.division.level:
            return obj.candidate_election.election.meta.precincts_reporting
        return None
8411
def is_enactable(self, as_of):
        """"""
        return \
            not self.disabled and \
            not self.archived and \
            not self._is_finished(as_of) and \
            self._is_ready(as_of) and \
            not self._is_billing_complete()
780800
function electMaster (advertiseId) {
    _advertiseId = advertiseId || null
    if (_electingMaster) return _electingMaster
    _electingMaster = _requestVotes()
                      .then(nodes => {
                        _electingMaster = false
                        _advertiseId = null
                        const masterNodes = nodes.filter(
                          ({isMaster}) => isMaster)
                        nodes = masterNodes.length ? masterNodes : nodes
                        const electedMaster = sortBy(nodes, ({id}) => id)[0]
                        if (!electedMaster) throw new Error('could not elect a master')

                        debug(`elected master: ${electedMaster.name} ${JSON.stringify(electedMaster.endpoints)}`)
                        _broadcastMessage('masterElected', electedMaster)
                        return electedMaster
                      })

    _electingMaster.catch(() => {
      _electingMaster = false
      _advertiseId = null
    })
    return _electingMaster
  }
1099136
def inc(self):
        """"""
        inc1 = self.get('INC', None)
        inc2 = self.get('INC2', None)
        if inc1 is None and inc2 is None:
            return None
        if inc2 is None:
            return inc1
        if inc1 is None:
            return -1 * inc2
        return (inc1 - inc2) / 2.0
467836
def context_role(self, bill=None, vote=None, session=None, term=None):
        '''
        '''
        # If no hints were given about the context, look for a related bill,
        # then for a related vote.
        if not any([bill, vote, session, term]):
            try:
                bill = self.bill
            except AttributeError:
                # A vote?
                try:
                    vote = self.vote
                except AttributeError:
                    # If we're here, this method was called on a
                    # Legislator was that doesn't have a related bill or vote.
                    return ''

        # If we still have to historical point of reference, figuring
        # out the context role is impossible. Return emtpy string.
        if not any([bill, vote, session, term]):
            return ''

        # First figure out the term.
        if bill is not None:
            term = bill['_term']

        elif vote is not None:
            try:
                _bill = vote.bill
            except AttributeError:
                _bill = BillVote(vote).bill
            if callable(_bill):
                _bill = _bill()
            term = _bill['_term']

        if term is None and session is not None:
            term = term_for_session(self[settings.LEVEL_FIELD], session)

        # Use the term to get the related roles. First look in the current
        # roles list, then fail over to the old_roles list.
        roles = [r for r in self['roles']
                 if r.get('type') == 'member' and r.get('term') == term]
        roles = list(filter(None, roles))

        if not roles:
            roles = [r for r in self.get('old_roles', {}).get(term, [])
                     if r.get('type') == 'member']
        roles = list(filter(None, roles))

        if not roles:
            # Legislator had no roles for this term. If there is a related
            # bill ro vote, this shouldn't happen, but could if the
            # legislator's roles got deleted.
            return ''

        # If there's only one applicable role, we're done.
        if len(roles) == 1:
            role = roles.pop()
            self['context_role'] = role
            return role

        # If only one of term or session is given and there are multiple roles:
        if not list(filter(None, [bill, vote])):
            if term is not None:
                role = roles[0]
                self['context_role'] = role
                return role

            # Below, use the date of the related bill or vote to determine
            # which (of multiple) roles applies.
            # Get the context date.
            if session is not None:
                # If we're here, we have multiple roles for a single session.
                # Try to find the correct one in self.metadata,
                # else give up.
                session_data = self.metadata['session_details'][session]
                for role in roles:
                    role_start = role.get('start_date')
                    role_end = role.get('end_date')

                    # Return the first role that overlaps at all with the
                    # session.
                    session_start = session_data.get('start_date')
                    session_end = session_data.get('end_date')
                    if session_start and session_end:
                        started_during = (role_start < session_start <
                                          role_end)
                        ended_during = (role_start < session_end < role_end)
                        if started_during or ended_during:
                            self['context_role'] = role
                            return role
                    else:
                        continue

                # Return first role from the session?
                role = roles[0]
                self['context_role'] = role
                return role

        if vote is not None:
            date = vote['date']
        if bill is not None:
            date = bill['action_dates']['first']

        dates_exist = False
        for role in roles:
            start_date = role.get('start_date')
            end_date = role.get('end_date')
            if start_date and end_date:
                dates_exist = True
                if start_date < date < end_date:
                    self['context_role'] = role
                    return role

        if dates_exist:
            # If we're here, the context date didn't fall into any of the
            # legislator's role date ranges.
            return ''

        else:
            # Here the roles didn't have date ranges. Return the last one?
            role = roles.pop()
            self['context_role'] = role
            return role

        return ''
861740
function() {
        var e, spo;

        if(this.falseFact) {
            spo = 'FALSE';
        } else {
            spo = '(' + Utils.removeBeforeSharp(this.subject) + ', ' + Utils.removeBeforeSharp(this.predicate) + ', ' + Utils.removeBeforeSharp(this.object) + ')'
        }

        this.explicit ? e = 'E' : e = 'I';
        return e + spo;
    }