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


Python Order.school方法代码示例

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


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

示例1: view_order

# 需要导入模块: from models import Order [as 别名]
# 或者: from models.Order import school [as 别名]
def view_order(request, compete_id=1):
    if compete_id is None:
        compete_id = 1
    school = get_object_or_404(School, user=request.user)
    competition = get_object_or_404(Competition, pk=compete_id)
    groups = set(request.user.groups.all())
    available_competitions = [c for c in Competition.objects.all()
                              if any(g in groups for g in c.available_for.all())]

    parallels_for_competition = CompetitionForParallel.objects.filter(competition=competition)
    parallels_for_competition_dict = dict((pc.parallel, pc) for pc in parallels_for_competition)
    if competition not in available_competitions:
        raise Http404('this competition is unavalilable for you')
    if competition.state == 4:
        return render_to_response('cabinet_order.html', {
            'school': school,
            'competitions':  available_competitions,
            'selected_competition': competition,
            'form': None,
            'message': '',
            'parallels': parallels_for_competition,
        }, context_instance=RequestContext(request))
    else:
        message = ''
        messagestatus = 1
        is_new = True
        order_status = 'не подана'
        blank_status = ''
        try:
            current_order = Order.objects.get(school=school, competition=competition)
            order_status = current_order.get_status_display()
            if competition.state == 3:
                blank_status = current_order.get_blank_status_display()
            is_new = False
        except Order.DoesNotExist:
            current_order = Order()
            current_order.create_time = datetime.now()
            current_order.competition = competition
            current_order.school = school

        if request.method == 'POST':
            form = OrderForm(dict(request.POST.items()), instance=current_order)
            if form.is_valid():
                message = ('Заявка поступила на рассмотрение'
                           if is_new else
                           'Заявка изменена')
                form.save()
            else:
                message='Неправильно указаны поля'
                messagestatus = 0
                if is_new:
                    current_order = None
            #form = OrderForm(instance=current_order)
            #form.errors = src_form.errors
        else:
            form = OrderForm(instance=current_order)
            if is_new:
               current_order = None
        total = 0
        total_cost = 0
        if current_order:
            order_parallels = OrderParallel.objects.filter(order=current_order)
            total = sum(op.count for op in order_parallels)
            total_cost = sum(op.count * parallels_for_competition_dict[op.parallel].cost for op in order_parallels if op.parallel in parallels_for_competition_dict)

        return render_to_response('cabinet_order.html', {
            'total': total,
            'parallels': parallels_for_competition,
            'total_cost': total_cost,
            'competitions':  available_competitions,
            'selected_competition': competition,
            'form': form,
            'message': message,
            'messagestatus': messagestatus,
            'order': current_order,
            'school': school,
        }, context_instance=RequestContext(request))
开发者ID:mstebelev,项目名称:rm22,代码行数:79,代码来源:views.py


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