• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python result_form.ResultForm类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: __init__

    def __init__(self, tally_id):
        super(IntakenProgressReport, self).__init__(tally_id)

        pks = ResultForm.distinct_form_pks(self.tally_id)

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


示例2: get

    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,代码行数:32,代码来源:form_list_view.py


示例3: get

    def get(self, *args, **kwargs):
        tally_id = kwargs.get('tally_id')
        self.initial = {
            'tally_id': tally_id,
        }
        del self.request.session['result_form']
        pk = self.request.session.get('result_form')

        if pk:
            result_form = ResultForm.objects.get(pk=pk, tally__id=tally_id)
        else:
            tally = Tally.objects.get(id=tally_id)
            barcode = ResultForm.generate_barcode(tally_id)
            result_form = ResultForm.objects.create(
                barcode=barcode,
                form_state=FormState.CLEARANCE,
                tally=tally)
            self.request.session['result_form'] = result_form.pk

        form = NewResultForm(instance=result_form)
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        return self.render_to_response(self.get_context_data(
            form=form, result_form=result_form, tally_id=tally_id))
开发者ID:crononauta,项目名称:tally-ho,代码行数:25,代码来源:clearance.py


示例4: get

    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,代码行数:27,代码来源:form_list_view.py


示例5: distinct_forms

def distinct_forms(ballot):
    """Return the distinct forms for a ballot based on its type.

    If there are no forms for a ballot assume that it is a component ballot and
    return forms for the associated general ballots.

    :param ballot: The ballot to return distinct forms for.

    :returns: The list of result forms.
    """
    forms = ResultForm.distinct_filter(ballot.resultform_set)

    if not forms:
        forms = ResultForm.distinct_for_component(ballot)

    return forms
开发者ID:comocho00,项目名称:tally-ho,代码行数:16,代码来源:exports.py


示例6: get

    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,代码行数:10,代码来源:form_list_view.py


示例7: get_queryset

    def get_queryset(self):
        qs = super(FormListDataView, self).get_queryset()
        ballot_number = self.kwargs.get('ballot')

        if ballot_number:
            ballot = Ballot.objects.get(number=ballot_number)
            qs = ResultForm.distinct_forms().filter(
                ballot__number__in=ballot.form_ballot_numbers)

        return qs
开发者ID:ben12345,项目名称:tally-ho,代码行数:10,代码来源:form_list_view.py


示例8: get_results_duplicates

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,代码行数:50,代码来源:super_admin.py


示例9: get

    def get(self, *args, **kwargs):
        pk = self.request.session.get('result_form')

        if pk:
            result_form = ResultForm.objects.get(pk=pk)
        else:
            barcode = ResultForm.generate_barcode()
            result_form = ResultForm.objects.create(
                barcode=barcode,
                form_state=FormState.CLEARANCE)
            self.request.session['result_form'] = result_form.pk

        form = NewResultForm(instance=result_form)
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        return self.render_to_response(self.get_context_data(
            form=form, result_form=result_form))
开发者ID:lnabergoi,项目名称:tally-ho,代码行数:18,代码来源:clearance.py


示例10: export_candidate_votes

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,代码行数:101,代码来源:exports.py


示例11: filter_queryset

 def filter_queryset(self, qs):
     return ResultForm.forms_in_state(FormState.UNSUBMITTED)
开发者ID:onaio,项目名称:tally-ho,代码行数:2,代码来源:form_list_view.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python test_base.create_center函数代码示例发布时间:2022-05-27
下一篇:
Python player.Player类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap