コード例 #1
0
def blog_detail(request, blog_pk):
    context = {}
    blog = get_object_or_404(Blog,pk=blog_pk)
    # 方法一
    # blog.readed_num += 1
    # blog.save()

    # 方法二

    if ReadNum.objects.filter(blog=blog).count():
        # 存在记录
        readnum = ReadNum.objects.get(blog=blog)
    else:
        readnum = ReadNum(blog=blog)

    readnum.read_num += 1
    readnum.save()

    # 获取评论
    # blog_content_type = ContentType.objects.get_for_model(blog)
    # comments = Comment.objects.filter(content_type=blog_content_type, object_id=blog.pk, parent=None)

    context["previous_blog"] = Blog.objects.filter(created_time__gt=blog.created_time).last()
    context["next_blog"] = Blog.objects.filter(created_time__lt=blog.created_time).first()
    context["blog"] = blog
    context["login_form"] = LoginForm()
    # 设置回复倒叙
    # context["comments"] = comments.order_by('-comment_time')

    # context["comments_count"] = Comment.objects.filter(content_type=blog_content_type, object_id=blog.pk).count()
    data = {}
    # 获取对象的model
    # data["content_type"] = blog_content_type.model
    # data["object_id"] = blog_pk
    # 在前端初始化值
    # context["comment_form"] = CommentForm(initial={"content_type": blog_content_type.model, "object_id": blog_pk, "reply_comment_id": 0})
    return render(request, 'blog/blog_detail.html', context)
コード例 #2
0
 def post(self, request):
     # having received the authorization request
     form = LoginForm(request.POST or None)
     # check the correct form, that there is a user and he entered the correct password
     if form.is_valid():
         username = form.cleaned_data.get("username")
         password = form.cleaned_data.get("password")
         user = auth.authenticate(request=request, username=username, password=password)
         if not user:
             return render(request, 'account/invalid_login.html')
         else:
             # if successful authorizing user
             auth.login(request, user)
             auth.get_user_model().last_login = datetime.now()
             #  and if the user of the number of staff and went through url /admin/login/
             # then redirect the user to the admin panel
             if request.user.is_staff or request.user.is_admin:
                 return redirect('/admin/')
             return redirect('shop:ProductList')
     # If not true(form is invalid), then the user will appear on the login page
     # and see an error message
     context = create_context_username_csrf(request)
     context['login_form'] = form
     return render(request=request, template_name='account/login.html', context=context)
コード例 #3
0
ファイル: views.py プロジェクト: fast-falcon/dong_yab
def sign(request):
    if request.method == "GET":
        return render(request, 'sign.html', {"error": ""})
    else:
        if "register" in request.POST:
            form = RegisterForm(request.POST)
            if form.is_valid():
                form.save()
        elif "login" in request.POST:
            form = LoginForm(request.POST)
            if form.is_valid():
                user = User.objects.filter(
                    email=form.cleaned_data["email"]).first()
                if user:
                    valid = user.check_password(form.cleaned_data["password"])
                else:
                    valid = False
                if valid:
                    login(request, user)
                    return HttpResponseRedirect(reverse("home"))
            return render(request, 'sign.html',
                          {"error": "ایمیل یا پسورد اشتباه می باشد."})

    return HTTPResponse()
コード例 #4
0
ファイル: views.py プロジェクト: Ferdellans/restless
class Login(AuthenticateEndpoint):
    user_fields = ('email', 'password')
    form = LoginForm()

    def get(self, request, *args, **kwargs):
        return render(request, 'account/login.html', {'form': self.form})

    def post(self, request, *args, **kwargs):
        self.form = LoginForm(request.POST)

        if self.form.is_valid():

            email = self.form.cleaned_data['email']
            password = self.form.cleaned_data['password']
            user = auth.authenticate(username=email, password=password)
            # user = auth.authenticate(email=email, password=password)
            if user is not None:
                auth.login(request, user)
                messages.success(request,
                                 'Добро пожаловать, %s!' % request.user)
                return redirect('/')

            messages.error(request, 'Неправильный пароль или почта')
            return redirect('/account/login/')
コード例 #5
0
def signin(request):

    template = 'account/login.html'
    login_form = LoginForm()
    message = ""

    # form 작성 후 post method 시
    if request.method == "POST":
        email = request.POST['email']
        password = request.POST['password']

        # 사용자 검증
        user = authenticate(username=email, password=password)
        if user is not None:
            if user.is_active:
                login(request, user)
                messages.success(request, '로그인 성공!')
                # 사용자가 admin인 경우
                if user.is_staff:
                    return HttpResponseRedirect('/admin/')
                # 사용자가 일반user인 경우
                else:
                    return HttpResponseRedirect('/home/')
            else:
                return HttpResponse("Your account is not active, please contact the site admin")
        else:
            return HttpResponse("로그인 실패! : Your username and/or password were incorrect")

    # get method 시
    else:
        if request.user.is_anonymous:
            context = {"loginForm": login_form, "message": message}
            return render(request, template, context)
        # 이미 로그인을 한 상태면 home으로 이동.
        else:
            return HttpResponseRedirect('/home/')
コード例 #6
0
def get_login():
    return LoginForm()
コード例 #7
0
def index(request):
    form = LoginForm()
    return render(request, 'index.html', {
        'html_title': 'Welcome to L-evaluation Portal',
        'login_form': form, })
コード例 #8
0
 def test_login_email_error(self):
     user_login_form = {'username': '******',
                        'password': '******'
                        }
     form = LoginForm(data=user_login_form)
     self.assertFalse(form.is_valid())
コード例 #9
0
ファイル: views.py プロジェクト: dfront/car_rental
def login(request):
    login_form = LoginForm()   
    c = {"login_form":login_form}
    return render_to_response("account/login.html",c)
コード例 #10
0
ファイル: views.py プロジェクト: cartermyers/bithumb
def index(request):
    total_in_game_currency = None
    if request.user.is_authenticated:
        total_in_game_currency = request.user.get_bank_account().get_in_game_currency()

    return render(request, 'bithumb/index.html', {'signup_form': SignupForm(), 'login_form': LoginForm(), 'total_score': total_in_game_currency})
コード例 #11
0
 def test_form_with_uncorect_data(self):
     form = LoginForm(data={})
     self.assertFalse(form.is_valid())
     self.assertEqual(len(form.errors), 2)
コード例 #12
0
ファイル: test_forms.py プロジェクト: AlexZie/ticketsystem
 def test_invalid_login_form(self):
     data = {'username': "******", 'password': "******"}
     form = LoginForm(data=data)
     self.assertFalse(form.is_valid())
コード例 #13
0
 def render(self, context):
     context[self.name] = LoginForm(request=context['request'])
     return ''
コード例 #14
0
    def test_form_with_valid_data(self):
        form = LoginForm(data={'username': '******', 'password': '******'})

        self.assertTrue(form.is_valid())
コード例 #15
0
def login_view(request):
    form = LoginForm()

    if request.user.is_authenticated:
        return redirect("home")
    return render(request, 'account/login.html', {'form':form})
コード例 #16
0
def checkout_login(request):
	ctx = {'form': LoginForm()}
	return TemplateResponse(request, 'orders/login.html', ctx)
コード例 #17
0
def checkout_home(request):
    cart_obj, new_obj = Cart.objects.new_or_get(
        request)  #we are getting the current session cart
    order_obj = None  #get_or_create is build in function
    if new_obj or cart_obj.products.count() == 0:
        return redirect(
            'carthome'
        )  #if the cart is just now created in the above line then go to carthome(Cart is empty)
    user = request.user
    login_form = LoginForm()
    guest_form = GuestForm()
    address_form = AddressForm()
    billing_address_id = request.session.get("billing_address_id", None)
    shipping_address_id = request.session.get("shipping_address_id", None)
    billing_profile = None
    guest_email_id = request.session.get('guest_email')
    if user.is_authenticated:
        billing_profile, billing_profile_created = Billingprofile.objects.get_or_create(
            user=user, email=user.email)
    elif guest_email_id is not None:
        guest_obj = GuestEmail.objects.get(id=guest_email_id)
        billing_profile, billing_guest_profile_created = Billingprofile.objects.get_or_create(
            email=guest_obj.email)
    else:
        pass
    address_qs = None
    #so basically the billingprofile is created for the user above but if he logs back again then we shouldnt keep on create an order we should retrieve it and produce it
    if billing_profile is not None:
        if request.user.is_authenticated:
            #order_qs=Order.objects.filter(billing_profile=billing_profile,cart=cart_obj,active=True)
            #if order_qs.count()==1:this entire thing moved to the oredermanager
            #     order_obj=order_qs.first()
            #else:
            address_qs = Address.objects.filter(
                billing_profile=billing_profile)
        order_obj, order_obj_created = Order.objects.new_or_get(
            billing_profile, cart_obj)
        if shipping_address_id:
            order_obj.shipping_address = Address.objects.get(
                id=shipping_address_id)
            order_obj.save()
            del request.session["shipping_address_id"]
        if billing_address_id:
            order_obj.billing_address = Address.objects.get(
                id=billing_address_id)
            order_obj.save()
            del request.session["billing_address_id"]

    #we are gonna update the oder as we are completed the checkout process
    #so we deletet the cart_id
    #and redirect it to the success
    #these 3 we are gonna perform
    if request.method == "POST":
        #checking for that order to be done
        #del request.session['cart_id']
        done = order_obj.check_done()
        if done:
            order_obj.mark_paid()
            del request.session['cart_id']
            request.session['cart_items'] = 0
            return redirect("success")

    context = {
        "object": order_obj,
        "billingprofile": billing_profile,
        "login": login_form,
        "guest_form": guest_form,
        "address_qs": address_qs,
        #"billing_address_form":billing_address_form,
        "address_form":
        address_form  #This is for the shipping above is for the billing address
    }
    return render(request, "carts/checkout.html", context)