当前位置: 首页>>代码示例>>Python>>正文


Python ResultForm.forms_in_state方法代码示例

本文整理汇总了Python中tally_ho.apps.tally.models.result_form.ResultForm.forms_in_state方法的典型用法代码示例。如果您正苦于以下问题:Python ResultForm.forms_in_state方法的具体用法?Python ResultForm.forms_in_state怎么用?Python ResultForm.forms_in_state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tally_ho.apps.tally.models.result_form.ResultForm的用法示例。


在下文中一共展示了ResultForm.forms_in_state方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get

# 需要导入模块: from tally_ho.apps.tally.models.result_form import ResultForm [as 别名]
# 或者: from tally_ho.apps.tally.models.result_form.ResultForm import forms_in_state [as 别名]
    def get(self, *args, **kwargs):
        form_state = kwargs.get('state')
        tally_id = kwargs.get('tally_id')

        if form_state:
            if form_state == ALL:
                form_list = ResultForm.objects.filter(tally__id=tally_id)
            else:
                form_state = FormState[form_state.upper()]
                form_list = ResultForm.forms_in_state(form_state.value,
                                                      tally_id=tally_id)

            form_list = form_list.values(
                'barcode', 'form_state', 'gender', 'station_number',
                'center__sub_constituency__code',
                'center__code',
                'ballot__race_type').order_by('barcode')

            return render_to_csv_response(form_list)

        return self.render_to_response(
            self.get_context_data(header_text=_('Form List'),
                                  remote_url=reverse(
                                      'form-list-data',
                                      kwargs={'tally_id': tally_id}),
                                  tally_id=tally_id,
                                  show_create_form_button=True))
开发者ID:onaio,项目名称:tally-ho,代码行数:29,代码来源:form_list_view.py

示例2: get

# 需要导入模块: from tally_ho.apps.tally.models.result_form import ResultForm [as 别名]
# 或者: from tally_ho.apps.tally.models.result_form.ResultForm import forms_in_state [as 别名]
    def get(self, *args, **kwargs):
        format_ = kwargs.get('format')
        if format_ == 'csv':
            form_list = ResultForm.forms_in_state(FormState.UNSUBMITTED).\
                values('id',
                       'created_date',
                       'modified_date',
                       'ballot_id__number',
                       'center_id__code',
                       'user_id__username',
                       'created_user_id__username',
                       'audited_count',
                       'barcode',
                       'date_seen',
                       'form_stamped',
                       'form_state',
                       'gender',
                       'name',
                       'office_id__number',
                       'rejected_count',
                       'serial_number',
                       'skip_quarantine_checks',
                       'station_number',
                       'is_replacement',
                       'intake_printed',
                       'clearance_printed')
            return render_to_csv_response(form_list)

        return self.render_to_response(
            self.get_context_data(header_text=_('Forms Not Received'),
                                  custom=True,
                                  remote_url='form-not-received-data'))
开发者ID:ewokcillo,项目名称:tally-ho,代码行数:34,代码来源:form_list_view.py

示例3: get

# 需要导入模块: from tally_ho.apps.tally.models.result_form import ResultForm [as 别名]
# 或者: from tally_ho.apps.tally.models.result_form.ResultForm import forms_in_state [as 别名]
    def get(self, *args, **kwargs):
        format_ = kwargs.get('format')
        if format_ == 'csv':
            form_list = ResultForm.forms_in_state(FormState.UNSUBMITTED)
            return render_to_csv_response(form_list)

        return self.render_to_response(
            self.get_context_data(header_text=_('Forms Not Received'),
                                  custom=True,
                                  remote_url='form-not-received-data'))
开发者ID:ben12345,项目名称:tally-ho,代码行数:12,代码来源:form_list_view.py

示例4: get_results_duplicates

# 需要导入模块: from tally_ho.apps.tally.models.result_form import ResultForm [as 别名]
# 或者: from tally_ho.apps.tally.models.result_form.ResultForm import forms_in_state [as 别名]
def get_results_duplicates(tally_id):
    complete_barcodes = []

    for ballot in valid_ballots(tally_id):
        forms = distinct_forms(ballot, tally_id)
        final_forms = ResultForm.forms_in_state(
            FormState.ARCHIVED, pks=[r.pk for r in forms], tally_id=tally_id)

        if not SPECIAL_BALLOTS or ballot.number in SPECIAL_BALLOTS:
            complete_barcodes.extend([r.barcode for r in final_forms])

    result_forms = ResultForm.objects\
        .select_related().filter(barcode__in=complete_barcodes,
                                 tally__id=tally_id)

    center_to_votes = defaultdict(list)
    center_to_forms = defaultdict(list)

    result_forms_founds = []

    for result_form in result_forms:
        # build list of votes for this barcode
        vote_list = ()

        for candidate in result_form.candidates:
            votes = candidate.num_votes(result_form)
            vote_list += (votes,)

        # store votes for this forms center
        center = result_form.center
        center_to_votes[center.code].append(vote_list)
        center_to_forms[center.code].append(result_form)

    for code, vote_lists in center_to_votes.items():
        votes_cast = sum([sum(l) for l in vote_lists]) > 0
        num_vote_lists = len(vote_lists)
        num_distinct_vote_lists = len(set(vote_lists))

        if votes_cast and num_distinct_vote_lists < num_vote_lists:

            for i, form in enumerate(center_to_forms[code]):
                vote_list = vote_lists[i]
                votes_cast = sum(vote_list) > 0
                other_vote_lists = vote_lists[:i] + vote_lists[i + 1:]

                if votes_cast and vote_list in other_vote_lists:
                    form.results_duplicated = vote_list
                    result_forms_founds.append(form)

    return result_forms_founds
开发者ID:onaio,项目名称:tally-ho,代码行数:52,代码来源:super_admin.py

示例5: __init__

# 需要导入模块: from tally_ho.apps.tally.models.result_form import ResultForm [as 别名]
# 或者: from tally_ho.apps.tally.models.result_form.ResultForm import forms_in_state [as 别名]
    def __init__(self, tally_id):
        super(NotRecievedProgressReport, self).__init__(tally_id)

        self.filtered_queryset = ResultForm.forms_in_state(
            FormState.UNSUBMITTED, tally_id=self.tally_id)
开发者ID:onaio,项目名称:tally-ho,代码行数:7,代码来源:progress.py

示例6: export_candidate_votes

# 需要导入模块: from tally_ho.apps.tally.models.result_form import ResultForm [as 别名]
# 或者: from tally_ho.apps.tally.models.result_form.ResultForm import forms_in_state [as 别名]
def export_candidate_votes(save_barcodes=False, output_duplicates=True,
                           output_to_file=True, show_disabled_candidates=True):
    """Export a spreadsheet of the candidates their votes for each race.

    :param save_barcodes: Generate barcode result file, default False.
    :param output_duplicates: Generate duplicates file, default True.
    :param output_to_file: Output to file, default True.

    :returns: The name of the temporary file that results have been output to.
    """
    header = ['ballot number',
              'stations',
              'stations completed',
              'stations percent completed']

    max_candidates = 0

    for ballot in Ballot.objects.all():
        if not show_disabled_candidates:
            ballot_number = ballot.candidates.filter(active=True).count()
        else:
            ballot_number = ballot.candidates.count()

        if ballot_number > max_candidates:
            max_candidates = ballot_number

    for i in xrange(1, max_candidates + 1):
        header.append('candidate %s name' % i)
        header.append('candidate %s votes' % i)
        header.append('candidate %s votes included quarantine' % i)

    complete_barcodes = []

    csv_file = NamedTemporaryFile(delete=False, suffix='.csv')

    with csv_file as f:
        w = csv.DictWriter(f, header)
        w.writeheader()

        for ballot in valid_ballots():
            general_ballot = ballot
            forms = distinct_forms(ballot)
            final_forms = ResultForm.forms_in_state(
                FormState.ARCHIVED, pks=[r.pk for r in forms])

            if not SPECIAL_BALLOTS or ballot.number in SPECIAL_BALLOTS:
                complete_barcodes.extend([r.barcode for r in final_forms])

            num_stations = forms.count()
            num_stations_completed = final_forms.count()

            percent_complete = round(
                100 * num_stations_completed / num_stations, 3) if num_stations\
                else 0

            output = OrderedDict({
                'ballot number': ballot.number,
                'stations': num_stations,
                'stations completed': num_stations_completed,
                'stations percent completed': percent_complete})

            candidates_to_votes = {}
            num_results_ary = []

            candidates = ballot.candidates.all()
            if not show_disabled_candidates:
                candidates = candidates.filter(active=True)

            for candidate in candidates:
                num_results, votes = candidate.num_votes()
                all_votes = candidate.num_all_votes
                candidates_to_votes[candidate.full_name] = [votes, all_votes]
                num_results_ary.append(num_results)

            assert len(set(num_results_ary)) <= 1

            for num_results in num_results_ary:
                if num_stations_completed != num_results:
                    print ('[WARNING] Number stations complete (%s) not '
                           'equal to num_results (%s) for ballot %s (general'
                           ' ballot %s)' % (
                               num_stations_completed, num_results,
                               ballot.number, general_ballot.number))
                    output['stations completed'] = num_results

            candidates_to_votes = OrderedDict((sorted(
                candidates_to_votes.items(), key=lambda t: t[1][0],
                reverse=True)))

            #Checks changes in candidates positions
            check_position_changes(candidates_to_votes)

            for i, item in enumerate(candidates_to_votes.items()):
                candidate, votes = item

                output['candidate %s name' % (i + 1)] = candidate
                output['candidate %s votes' % (i + 1)] = votes[0]
                output['candidate %s votes included quarantine' % (i + 1)] = votes[1]

            write_utf8(w, output)
#.........这里部分代码省略.........
开发者ID:comocho00,项目名称:tally-ho,代码行数:103,代码来源:exports.py

示例7: filter_queryset

# 需要导入模块: from tally_ho.apps.tally.models.result_form import ResultForm [as 别名]
# 或者: from tally_ho.apps.tally.models.result_form.ResultForm import forms_in_state [as 别名]
 def filter_queryset(self, qs):
     return ResultForm.forms_in_state(FormState.UNSUBMITTED)
开发者ID:onaio,项目名称:tally-ho,代码行数:4,代码来源:form_list_view.py


注:本文中的tally_ho.apps.tally.models.result_form.ResultForm.forms_in_state方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。