示例#1
0
文件: views.py 项目: od-5/crm
def adjustertask_area(request):
    """
    функция добавления задачи по районам
    версия 2
    """
    context = {}
    user = request.user
    if request.method == 'POST':
        form = AdjusterTaskAreaAddForm(request.POST)
        if form.is_valid():
            if request.POST.getlist('chk_group[]'):
                # сохраняем задачу
                task = form.save()
                surfaces = request.POST.getlist('chk_group[]')
                for item in surfaces:
                    try:
                        surface = Surface.objects.get(pk=int(item))
                        # Если полностью сломана - не создавать поверхность задачи
                        # сохраняем поверхности для задачи
                        if not surface.full_broken:
                            adjustertasksurface = AdjusterTaskSurface(
                                adjustertask=task,
                                surface=surface
                            )
                            adjustertasksurface.save()
                            for porch in surface.porch_set.all():
                                if not porch.is_broken:
                                    atsporch = AdjusterTaskSurfacePorch(
                                        adjustertasksurface=adjustertasksurface,
                                        porch=porch
                                    )
                                    atsporch.save()
                    except:
                        pass
                return HttpResponseRedirect(task.get_absolute_url())
    else:
        form = AdjusterTaskAreaAddForm()
        if user.type == 1:
            city_qs = City.objects.all()
        elif user.type == 6:
            city_qs = user.superviser.city.all()
        elif user.type == 2:
            city_qs = City.objects.filter(moderator=user)
        elif user.type == 5:
            manager = Manager.objects.get(user=user)
            city_qs = City.objects.filter(moderator=manager.moderator)
        else:
            city_qs = None
        form.fields['city'].queryset = city_qs
    try:
        request.session['adjustertask_filtered_list']
    except:
        request.session['adjustertask_filtered_list'] = reverse('adjustertask:list')
    context.update({
        'form': form,
        'back_to_list': request.session['adjustertask_filtered_list']
    })
    return render(request, 'adjustertask/adjustertask_area_add.html', context)
示例#2
0
文件: views.py 项目: od-5/crm
def adjustertask_repair(request):
    """
    функция добавления задачи на ремонт
    версия 2
    """
    context = {}
    error = None
    user = request.user
    if request.method == 'POST':
        form = AdjusterTaskRepairAddForm(request.POST)
        if form.is_valid():
            if request.POST.getlist('chk_group[]'):
                task = form.save()
                porch_list = request.POST.getlist('chk_group[]')
                for item in porch_list:
                    porch = Porch.objects.get(pk=int(item))
                    try:
                        adjustertasksurface = AdjusterTaskSurface.objects.get(adjustertask=task, surface=porch.surface)
                    except:
                        adjustertasksurface = AdjusterTaskSurface(
                            adjustertask=task,
                            surface=porch.surface
                        )
                        adjustertasksurface.save()
                    atsporch = AdjusterTaskSurfacePorch(
                        adjustertasksurface=adjustertasksurface,
                        porch=porch
                    )
                    atsporch.save()
                return HttpResponseRedirect(task.get_absolute_url())
            else:
                error = u'Не выбрано ни одно подъезда для ремонта'
        else:
            error = u'Проверьте правильность ввода полей. Все поля, кроме комментария, обязательны к заполнению'
    else:
        form = AdjusterTaskRepairAddForm()
    if user.type == 1:
        city_qs = City.objects.all()
    elif user.type == 6:
        city_qs = user.superviser.city.all()
    elif user.type == 2:
        city_qs = City.objects.filter(moderator=user)
    elif user.type == 5:
        city_qs = City.objects.filter(moderator=user.manager.moderator)
    else:
        city_qs = None
    form.fields['city'].queryset = city_qs
    try:
        request.session['adjustertask_filtered_list']
    except:
        request.session['adjustertask_filtered_list'] = reverse('adjustertask:list')
    context.update({
        'form': form,
        'error': error,
        'back_to_list': request.session['adjustertask_filtered_list']
    })
    return render(request, 'adjustertask/adjustertask_repair_add.html', context)
示例#3
0
def adjustertask_repair(request):
    """
    функция добавления задачи на ремонт
    версия 2
    """
    context = {}
    error = None
    user = request.user
    if request.method == 'POST':
        form = AdjusterTaskRepairAddForm(request.POST)
        if form.is_valid():
            if request.POST.getlist('chk_group[]'):
                task = form.save()
                porch_list = request.POST.getlist('chk_group[]')
                for item in porch_list:
                    porch = Porch.objects.get(pk=int(item))
                    try:
                        adjustertasksurface = AdjusterTaskSurface.objects.get(
                            adjustertask=task, surface=porch.surface)
                    except:
                        adjustertasksurface = AdjusterTaskSurface(
                            adjustertask=task, surface=porch.surface)
                        adjustertasksurface.save()
                    atsporch = AdjusterTaskSurfacePorch(
                        adjustertasksurface=adjustertasksurface, porch=porch)
                    atsporch.save()
                    surface = porch.surface
                    if not surface.coord_x or not surface.coord_y:
                        surface.save()
                return HttpResponseRedirect(task.get_absolute_url())
            else:
                error = u'Не выбрано ни одно подъезда для ремонта'
        else:
            error = u'Проверьте правильность ввода полей. Все поля, кроме комментария, обязательны к заполнению'
    else:
        form = AdjusterTaskRepairAddForm()
    if user.type == 1:
        city_qs = City.objects.all()
    elif user.type == 6:
        city_qs = user.superviser.city.all()
    elif user.type == 2:
        city_qs = City.objects.filter(moderator=user)
    elif user.type == 5:
        city_qs = City.objects.filter(moderator=user.manager.moderator)
    else:
        city_qs = None
    form.fields['city'].queryset = city_qs
    try:
        request.session['adjustertask_filtered_list']
    except:
        request.session['adjustertask_filtered_list'] = reverse(
            'adjustertask:list')
    context.update({
        'form':
        form,
        'error':
        error,
        'back_to_list':
        request.session['adjustertask_filtered_list']
    })
    return render(request, 'adjustertask/adjustertask_repair_add.html',
                  context)
示例#4
0
def adjustertask_area(request):
    """
    функция добавления задачи по районам
    версия 2
    """
    context = {}
    user = request.user
    if request.method == 'POST':
        form = AdjusterTaskAreaAddForm(request.POST)
        if form.is_valid():
            if request.POST.getlist('chk_group[]'):
                # сохраняем задачу
                task = form.save()
                surfaces = request.POST.getlist('chk_group[]')
                for item in surfaces:
                    try:
                        surface = Surface.objects.get(pk=int(item))
                        # Если полностью сломана - не создавать поверхность задачи
                        # сохраняем поверхности для задачи
                        if not surface.full_broken:
                            adjustertasksurface = AdjusterTaskSurface(
                                adjustertask=task, surface=surface)
                            adjustertasksurface.save()
                            for porch in surface.porch_set.all():
                                if not porch.is_broken:
                                    atsporch = AdjusterTaskSurfacePorch(
                                        adjustertasksurface=adjustertasksurface,
                                        porch=porch)
                                    atsporch.save()
                            if not surface.coord_x or not surface.coord_y:
                                surface.save()
                    except:
                        pass
                return HttpResponseRedirect(task.get_absolute_url())
            elif request.POST.getlist('chk_group2[]'):
                # сохраняем задачу
                task = form.save()
                porches = request.POST.getlist('chk_group2[]')
                for item in porches:
                    try:
                        porch = Porch.objects.get(pk=int(item))
                        try:
                            adjustertasksurface = AdjusterTaskSurface.objects.get(
                                adjustertask=task, surface=porch.surface)
                        except:
                            adjustertasksurface = AdjusterTaskSurface(
                                adjustertask=task, surface=porch.surface)
                            adjustertasksurface.save()
                        atsporch = AdjusterTaskSurfacePorch(
                            adjustertasksurface=adjustertasksurface,
                            porch=porch)
                        atsporch.save()
                    except:
                        pass
                return HttpResponseRedirect(task.get_absolute_url())
    else:
        form = AdjusterTaskAreaAddForm()
        if user.type == 1:
            city_qs = City.objects.all()
        elif user.type == 6:
            city_qs = user.superviser.city.all()
        elif user.type == 2:
            city_qs = City.objects.filter(moderator=user)
        elif user.type == 5:
            manager = Manager.objects.get(user=user)
            city_qs = City.objects.filter(moderator=manager.moderator)
        else:
            city_qs = None
        form.fields['city'].queryset = city_qs
    try:
        request.session['adjustertask_filtered_list']
    except:
        request.session['adjustertask_filtered_list'] = reverse(
            'adjustertask:list')
    context.update({
        'form':
        form,
        'back_to_list':
        request.session['adjustertask_filtered_list']
    })
    return render(request, 'adjustertask/adjustertask_area_add.html', context)