Exemple #1
0
def profile(request):
    #template = loader.get_template("welcome.html")
    template = loader.get_template("prods.html")

    # get all list
    bk_lst = Book.objects.filter(user_id=request.user).order_by('-date')
    pl_lst = Place.objects.filter(user_id=request.user).order_by('name')
    pr_lst = Product.objects.filter(user_id=request.user).order_by('name')
    br_lst = Branch.objects.filter(user_id=request.user).order_by('name')

    br_lst = calc_stat(request.user)
    #calc_stat(br_lst)


    context = RequestContext(request, {
            "rows": bk_lst,
            "branchs" : br_lst,
            "places" : pl_lst,
            "products" : pr_lst,

            })
    return HttpResponse(template.render(context))
Exemple #2
0
def index(request):
    if request.method == 'POST':
        form = RegForm(request.POST)

        try:
            user = User.objects.get(username=form.data.get('email', None))
        except User.DoesNotExist:
            if form.is_valid():
                template = loader.get_template("activate.html")
                try:
                    send_mail('Активация аккаунта', 'Перейдите по ссылке http://www.calbook.tk/ и введите логин и пароль.', '*****@*****.**',[form.data.get('email', None),])
                except:
                    template = loader.get_template("error.html")
                    context = RequestContext(request, {
                    "error" : "Неизвестная ошибка.\n Мы уже работаем над этим. \n Попробуйте чуть позже.",
                    })
                    return HttpResponse(template.render(context))

                try:
                    user = User.objects.create_user(form.data.get('email', None), form.data.get('email', None), form.data.get('password', None))
                    user.save()
                    template = loader.get_template("error.html")
                    context = RequestContext(request, {
                        "error" : "Вам отправлено письмо с инструкцией по активации",
                        })
                    return HttpResponse(template.render(context))
                except:
                    user.delete()
                    template = loader.get_template("error.html")
                    context = RequestContext(request, {
                    "error" : "Пользователь не создан.\n Попробуйте ввести снова.",
                    })
                    return HttpResponse(template.render(context))
            else:
                if not request.user.is_anonymous():
                    if not request.user.is_active():
                        form = RegForm()
                        return render_to_response('activate.html',
                                                  {'form': form},
                                                  context_instance=RequestContext(request))
        template = loader.get_template("error.html")
        context = RequestContext(request, {
            "error" : "Пользователь с таким именем уже существует.\n Попробуйте другой.",
            })
        return HttpResponse(template.render(context))

    if not request.user.is_anonymous():
        template = loader.get_template("prods.html")
        bk_lst = Book.objects.filter(user_id=request.user).order_by('-date')
        pl_lst = Place.objects.filter(user_id=request.user).order_by('name')
        pr_lst = Product.objects.filter(user_id=request.user).order_by('name')
        #br_lst = Branch.objects.all().order_by('name')

        br_lst = calc_stat(request.user)



        context = RequestContext(request, {
        "rows": bk_lst,
        "branchs" : br_lst,
        "places" : pl_lst,
        "products" : pr_lst,
        "user" : request.user.username,

        })
        return HttpResponse(template.render(context))
    else:
        form = RegForm()
        return render_to_response('activate.html', {'form': form}, context_instance=RequestContext(request))
Exemple #3
0
def index(request):
    if request.method == 'POST':
        form = RegForm(request.POST)

        try:
            user = User.objects.get(username=form.data.get('email', None))
        except User.DoesNotExist:
            if form.is_valid():
                template = loader.get_template("activate.html")
                try:
                    send_mail(
                        'Активация аккаунта',
                        'Перейдите по ссылке http://www.calbook.tk/ и введите логин и пароль.',
                        '*****@*****.**', [
                            form.data.get('email', None),
                        ])
                except:
                    template = loader.get_template("error.html")
                    context = RequestContext(
                        request, {
                            "error":
                            "Неизвестная ошибка.\n Мы уже работаем над этим. \n Попробуйте чуть позже.",
                        })
                    return HttpResponse(template.render(context))

                try:
                    user = User.objects.create_user(
                        form.data.get('email', None),
                        form.data.get('email', None),
                        form.data.get('password', None))
                    user.save()
                    template = loader.get_template("error.html")
                    context = RequestContext(
                        request, {
                            "error":
                            "Вам отправлено письмо с инструкцией по активации",
                        })
                    return HttpResponse(template.render(context))
                except:
                    user.delete()
                    template = loader.get_template("error.html")
                    context = RequestContext(
                        request, {
                            "error":
                            "Пользователь не создан.\n Попробуйте ввести снова.",
                        })
                    return HttpResponse(template.render(context))
            else:
                if not request.user.is_anonymous():
                    if not request.user.is_active():
                        form = RegForm()
                        return render_to_response(
                            'activate.html', {'form': form},
                            context_instance=RequestContext(request))
        template = loader.get_template("error.html")
        context = RequestContext(
            request, {
                "error":
                "Пользователь с таким именем уже существует.\n Попробуйте другой.",
            })
        return HttpResponse(template.render(context))

    if not request.user.is_anonymous():
        template = loader.get_template("prods.html")
        bk_lst = Book.objects.filter(user_id=request.user).order_by('-date')
        pl_lst = Place.objects.filter(user_id=request.user).order_by('name')
        pr_lst = Product.objects.filter(user_id=request.user).order_by('name')
        #br_lst = Branch.objects.all().order_by('name')

        br_lst = calc_stat(request.user)

        context = RequestContext(
            request, {
                "rows": bk_lst,
                "branchs": br_lst,
                "places": pl_lst,
                "products": pr_lst,
                "user": request.user.username,
            })
        return HttpResponse(template.render(context))
    else:
        form = RegForm()
        return render_to_response('activate.html', {'form': form},
                                  context_instance=RequestContext(request))