form of contract

This commit is contained in:
Cayo Puigdefabregas 2023-12-11 12:11:18 +01:00
parent 914d408ded
commit 93557fe277
10 changed files with 2492 additions and 41 deletions

View File

@ -1,4 +1,4 @@
# Generated by Django 4.2.5 on 2023-12-04 08:44
# Generated by Django 4.2.5 on 2023-12-11 08:35
from django.conf import settings
from django.db import migrations, models

View File

@ -1,4 +1,4 @@
# Generated by Django 4.2.5 on 2023-12-04 08:44
# Generated by Django 4.2.5 on 2023-12-11 08:35
from django.db import migrations, models

View File

@ -1,4 +1,4 @@
# Generated by Django 4.2.5 on 2023-11-29 10:18
# Generated by Django 4.2.5 on 2023-12-11 08:35
from django.conf import settings
from django.db import migrations, models
@ -30,6 +30,7 @@ class Migration(migrations.Migration):
'code',
models.CharField(default=oidc4vp.models.set_code, max_length=24),
),
('code_used', models.BooleanField()),
('created', models.DateTimeField(auto_now=True)),
('presentation_definition', models.CharField(max_length=250)),
],
@ -70,26 +71,6 @@ class Migration(migrations.Migration):
),
],
),
migrations.CreateModel(
name='VPVerifyRequest',
fields=[
(
'id',
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name='ID',
),
),
('nonce', models.CharField(max_length=50)),
('expected_credentials', models.CharField(max_length=255)),
('expected_contents', models.TextField()),
('action', models.TextField()),
('response_or_redirect', models.CharField(max_length=255)),
('submitted_on', models.DateTimeField(auto_now=True)),
],
),
migrations.CreateModel(
name='OAuth2VPToken',
fields=[
@ -103,14 +84,14 @@ class Migration(migrations.Migration):
),
),
('created', models.DateTimeField(auto_now=True)),
('code', models.CharField(max_length=250)),
('result_verify', models.BooleanField(max_length=250)),
('presentation_definition', models.CharField(max_length=250)),
('result_verify', models.CharField(max_length=255)),
('vp_token', models.TextField()),
(
'authorization',
models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name='oauth2vptoken',
to='oidc4vp.authorization',
),
),

View File

@ -0,0 +1,45 @@
# Generated by Django 4.2.5 on 2023-12-11 08:35
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('oidc4vp', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Promotion',
fields=[
(
'id',
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name='ID',
),
),
('name', models.CharField(max_length=250)),
(
'discount',
models.PositiveSmallIntegerField(
choices=[(1, 'Financial vulnerability')]
),
),
(
'authorize',
models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name='promotions',
to='oidc4vp.authorization',
),
),
],
),
]

View File

@ -21,6 +21,9 @@ class Promotion(models.Model):
def get_url(self, code):
url = "{}?code={}".format(
reverse_lazy("promotion:show_promotion"),
reverse_lazy("promotion:contract"),
code
)
def get_discount(self, price):
return price - price*0.25

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -11,4 +11,8 @@ urlpatterns = [
name="show_promotion"),
path('select_wallet', views.SelectWalletView.as_view(),
name="select_wallet"),
path('contract', views.ContractView.as_view(),
name="contract"),
path('contract/1', views.ThanksView.as_view(),
name="thanks"),
]

View File

@ -6,11 +6,21 @@ from django.template.loader import get_template
from django.urls import reverse_lazy
from django.http import HttpResponse
from oidc4vp.models import Authorization
from promotion.forms import WalletForm, ContractForm
class PromotionView(View):
template_name = "somconnexio.tarifes-mobil.html"
template_name = "somconnexio_tarifes-mobil.html"
def get(self, request, *args, **kwargs):
self.context = {}
template = get_template(
self.template_name,
).render()
return HttpResponse(template)
class ThanksView(View):
template_name = "somconnexio_thanks.html"
def get(self, request, *args, **kwargs):
self.context = {}
template = get_template(
@ -19,26 +29,38 @@ class PromotionView(View):
return HttpResponse(template)
class PromotionMobile1View(FormView):
class ContractView(FormView):
template_name = "somconnexio_contract.html"
promotion = None
vp_tokens = None
vp_token = None
authorization = None
form_class = ContractForm
def get(self, request, *args, **kwargs):
success_url = reverse_lazy('promotion:thanks')
def get_context_data(self, **kwargs):
# import pdb; pdb.set_trace()
self.context = super().get_context_data(**kwargs)
code = self.request.GET.get("code")
self.get_discount(code)
self.context = {
self.context.update({
"promotion": self.promotion,
"verificable_presentation": self.vp_token
}
template = get_template(
self.template_name,
).render()
return HttpResponse(template)
"verificable_presentation": self.vp_token,
"sim": 10.0,
"mensual": 15.0,
"total": 25.0
})
if self.promotion:
self.context['sim'] = self.context.get_discount(self.context["sim"])
self.context['mensual'] = self.context.get_discount(self.context["mensual"])
self.context['total'] = self.context.get_discount(self.context["total"])
return self.context
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
if not self.vp_token:
return kwargs
self.vp_token.get_user_info()
kwargs['verificable_presentation'] = self.vp_token
kwargs["nif"] = self.vp_token.user_info.get("nif", '')
@ -58,6 +80,9 @@ class PromotionMobile1View(FormView):
return redirect(url)
def get_discount(self, code):
if not code:
return
self.authorization = Authorization.objects.filter(
code=code,
code_unused=False