Esempio n. 1
0
    def change_view(self, request, pk):
        """
        修改数据页面
        """
        if request.method == "GET":
            obj = self.model.objects.filter(pk=pk).first()
            if obj:
                AddModelForm = self.get_model_form_class()
                forms = AddModelForm(instance=obj)

                info = self.model._meta.app_label, self.model._meta.model_name
                change_url = reverse("%s_%s_change" % info, kwargs={"pk": pk})
                return render(request, "kingadmin/form.html", {"fields": forms, "add_change_url": change_url})

            else:
                return JsonResponse({"code": 401, "msg": "数据错误"})

        elif request.method == "POST":
            obj = self.model.objects.filter(pk=pk).first()
            if obj:
                AddModelForm = self.get_model_form_class()
                forms = AddModelForm(data=request.POST, instance=obj)
                if forms.is_valid():
                    forms.save()
                    return JsonResponse({"code": 200, "msg": "修改成功"})
                return JsonResponse({"code": 201, "msg": "修改失败", "errors": forms.errors})
            else:
                return JsonResponse({"code": 401, "msg": "数据错误"})
        else:
            return JsonResponse({"code": 403, "msg": "请求方法不被允许"})
Esempio n. 2
0
def uchp_add(request):
    request_url = request.GET.get("next")
    form = Uchp_adding_form()
    if request.POST:
        forms = Uchp_adding_form(request.POST)
        forms.save()
        return redirect(request_url)
    return render(request, "sport/uchp.html", {
        'form': form,
        'whatweadding': 'УЧП'
    })
Esempio n. 3
0
def place_adding(request):
    request_url = request.GET.get("next")
    form = Place_adding_form()
    if request.POST:
        forms = Place_adding_form(request.POST)
        forms.save()
        return redirect(request_url)
    return render(request, "sport/addform.html", {
        'form': form,
        'whatweadding': 'места проведения'
    })
Esempio n. 4
0
def sport_adding(request):
    request_url = request.GET.get("next")
    form = Sport_adding_form()
    if request.POST:
        forms = Sport_adding_form(request.POST)
        forms.save()
        return redirect(request_url)
    return render(request, "sport/addform.html", {
        'form': form,
        'whatweadding': 'вида спорта'
    })
Esempio n. 5
0
def create_customer(request):
    forms = CustomerForm()
    if request.method == 'POST':
        forms = CustomerForm(request.POST)
        if forms.is_valid():
            forms.save()
            return redirect('customer-list')
        else:
            print(forms.errors)
    context = {'cform': forms}
    return render(request, 'booking/create_customer.html', context)
def register(request):
    if request.method == "POST":
        forms = userregisterform(request.POST)
        if forms.is_valid():
            forms.save()
            username = forms.cleaned_data.get('username')
            messages.success(request, f'Account Created For {username}')
            return redirect('login')
    else:
        forms = userregisterform()

    return render(request, 'register.html', {'form': forms})
def profile_update_new(request):
    if request.method == "POST":
        forms = profileupdateform(request.POST,
                                  request.FILES,
                                  instance=request.user.profile)
        if forms.is_valid():
            forms.save()
            username = forms.cleaned_data.get('username')
            messages.success(request, f'Profile Updated For {request.user}')
            return redirect('profile_view')
    else:
        forms = profileupdateform(instance=request.user.profile)

    return render(request, 'profile-update-new.html', {'form': forms})
Esempio n. 8
0
def match_view(request):
    forms = MatchForm(request.POST or None)
    try:
        if forms.is_valid():
            forms.save()

            return HttpResponseRedirect(reverse('match:score'))

        context = {
            'forms': forms,
        }
        return render(request, 'match/match.html', context)
    except:
        messages.warning(request, "Kayıt Başarısız")
Esempio n. 9
0
def login_request(request):
    if request.method == "POST":
        print(request.POST.get('submit'))
        print(request.POST)
        if request.POST.get('submit') == 'Acceder':
            print(request.POST.get('submit'))
            form = AuthenticationForm(request, data=request.POST)
            if form.is_valid():
                username = form.cleaned_data.get('username')
                password = form.cleaned_data.get('password')
                user = authenticate(username=username, password=password)
                if user is not None:
                    login(request, user)
                    messages.info(request,
                                  f"You are now logged in as {username}.")
                    return redirect("perfil")
                else:
                    messages.error(request, "Invalid username or password.")
            else:
                messages.error(request, "Invalid username or password.")
        if request.POST.get('submit') == 'signup':
            forms = UserCreationFormWithEmail(request.POST)
            if forms.is_valid():
                forms.save()
                username = forms.cleaned_data.get('username')
                raw_password = forms.cleaned_data.get('password1')
                user = authenticate(username=username, password=raw_password)
                login(request,
                      user,
                      backend='django.contrib.auth.backends.ModelBackend')
                #us = {'example':'hola'}
                messages.success(request, 'Profile details updated.')
                return redirect('perfil')
            else:
                form = UserCreationFormWithEmail()

    form = UserCreationFormWithEmail()
    us = {'example': 'hola'}
    return render(request=request,
                  template_name="registration/login.html",
                  context={"us": us})  # context={"form": form}
Esempio n. 10
0
def edit_profile_info(request):
    '''Редактирование информации о блоггере'''
    if request.method == 'POST':
        forms = EditProfile(request.POST, instance=request.user)
        try:
            forms2 = EditBlogerProfile(request.POST,
                                       instance=request.user.bloger)
            forms_foto = ImageLoadForm(request.POST,
                                       request.FILES,
                                       instance=request.user.bloger)
        except:
            forms2 = EditBlogerProfile(request.POST)
            forms_foto = ImageLoadForm(request.POST, request.FILES)
        if forms.is_valid() and forms2.is_valid() and forms_foto.is_valid():
            forms2.instance.user = request.user
            forms.save()
            forms2.save()
            forms_foto.save()
            username = forms.cleaned_data.get('username')
            name = forms.cleaned_data.get('name')
            surname = forms.cleaned_data.get('surname')
            age = forms.cleaned_data.get('age')
            about = forms.cleaned_data.get('about')
            messages.success(request, f'Изменения внесены!')
            return redirect(reverse_lazy('profile'))
    else:
        forms = EditProfile(instance=request.user)
        try:
            forms2 = EditBlogerProfile(instance=request.user.bloger)
            forms_foto = ImageLoadForm(instance=request.user.bloger)
        except:
            forms2 = EditBlogerProfile()
            forms_foto = ImageLoadForm()
    context = {
        'title': f'Редактирование {request.user}',
        'form': forms,
        'form2': forms2,
        'forms_foto': forms_foto,
    }
    return render(request, 'blogdiy/create-blogger.html', context)
Esempio n. 11
0
    def add_view(self, request):
        """
        添加数据页面
        """
        if request.method == "GET":
            AddModelForm = self.get_model_form_class()
            forms = AddModelForm()

            info = self.model._meta.app_label, self.model._meta.model_name
            add_url = reverse("%s_%s_add" % info)
            return render(request, "kingadmin/form.html", {"fields": forms, "add_change_url": add_url})

        elif request.method == "POST":
            AddModelForm = self.get_model_form_class()
            forms = AddModelForm(request.POST)
            if forms.is_valid():
                forms.save()
                return JsonResponse({"code": 200, "msg": "添加成功"})

            return JsonResponse({"code": 201, "msg": "添加失败", "errors": forms.errors})
        else:
            return JsonResponse({"code": 403, "msg": "请求方法不被允许"})
Esempio n. 12
0
def RegisterView(request):
    print(request.user.is_authenticated())
    forms = UserRegistrationForm(request.POST or None)
    if forms.is_valid():
        user = forms.save(commit=False)
        password = forms.cleaned_data.get('password')
        user.set_password(password)
        user.save()

        new_user = authenticate(username=user.username, password=password)
        login(request, new_user)
        return redirect("/home/")

    return render(request, "prona/registration_form.html", {"forms": forms})