form of contract
This commit is contained in:
parent
914d408ded
commit
93557fe277
|
@ -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.conf import settings
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
|
@ -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
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
|
@ -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.conf import settings
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
@ -30,6 +30,7 @@ class Migration(migrations.Migration):
|
||||||
'code',
|
'code',
|
||||||
models.CharField(default=oidc4vp.models.set_code, max_length=24),
|
models.CharField(default=oidc4vp.models.set_code, max_length=24),
|
||||||
),
|
),
|
||||||
|
('code_used', models.BooleanField()),
|
||||||
('created', models.DateTimeField(auto_now=True)),
|
('created', models.DateTimeField(auto_now=True)),
|
||||||
('presentation_definition', models.CharField(max_length=250)),
|
('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(
|
migrations.CreateModel(
|
||||||
name='OAuth2VPToken',
|
name='OAuth2VPToken',
|
||||||
fields=[
|
fields=[
|
||||||
|
@ -103,14 +84,14 @@ class Migration(migrations.Migration):
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
('created', models.DateTimeField(auto_now=True)),
|
('created', models.DateTimeField(auto_now=True)),
|
||||||
('code', models.CharField(max_length=250)),
|
('result_verify', models.CharField(max_length=255)),
|
||||||
('result_verify', models.BooleanField(max_length=250)),
|
('vp_token', models.TextField()),
|
||||||
('presentation_definition', models.CharField(max_length=250)),
|
|
||||||
(
|
(
|
||||||
'authorization',
|
'authorization',
|
||||||
models.ForeignKey(
|
models.ForeignKey(
|
||||||
null=True,
|
null=True,
|
||||||
on_delete=django.db.models.deletion.SET_NULL,
|
on_delete=django.db.models.deletion.SET_NULL,
|
||||||
|
related_name='oauth2vptoken',
|
||||||
to='oidc4vp.authorization',
|
to='oidc4vp.authorization',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -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',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
|
@ -21,6 +21,9 @@ class Promotion(models.Model):
|
||||||
|
|
||||||
def get_url(self, code):
|
def get_url(self, code):
|
||||||
url = "{}?code={}".format(
|
url = "{}?code={}".format(
|
||||||
reverse_lazy("promotion:show_promotion"),
|
reverse_lazy("promotion:contract"),
|
||||||
code
|
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
|
@ -11,4 +11,8 @@ urlpatterns = [
|
||||||
name="show_promotion"),
|
name="show_promotion"),
|
||||||
path('select_wallet', views.SelectWalletView.as_view(),
|
path('select_wallet', views.SelectWalletView.as_view(),
|
||||||
name="select_wallet"),
|
name="select_wallet"),
|
||||||
|
path('contract', views.ContractView.as_view(),
|
||||||
|
name="contract"),
|
||||||
|
path('contract/1', views.ThanksView.as_view(),
|
||||||
|
name="thanks"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -6,11 +6,21 @@ from django.template.loader import get_template
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
|
||||||
|
from oidc4vp.models import Authorization
|
||||||
from promotion.forms import WalletForm, ContractForm
|
from promotion.forms import WalletForm, ContractForm
|
||||||
|
|
||||||
|
|
||||||
class PromotionView(View):
|
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):
|
def get(self, request, *args, **kwargs):
|
||||||
self.context = {}
|
self.context = {}
|
||||||
template = get_template(
|
template = get_template(
|
||||||
|
@ -19,26 +29,38 @@ class PromotionView(View):
|
||||||
return HttpResponse(template)
|
return HttpResponse(template)
|
||||||
|
|
||||||
|
|
||||||
class PromotionMobile1View(FormView):
|
class ContractView(FormView):
|
||||||
template_name = "somconnexio_contract.html"
|
template_name = "somconnexio_contract.html"
|
||||||
promotion = None
|
promotion = None
|
||||||
vp_tokens = None
|
vp_token = None
|
||||||
authorization = None
|
authorization = None
|
||||||
form_class = ContractForm
|
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")
|
code = self.request.GET.get("code")
|
||||||
self.get_discount(code)
|
self.get_discount(code)
|
||||||
self.context = {
|
self.context.update({
|
||||||
"promotion": self.promotion,
|
"promotion": self.promotion,
|
||||||
"verificable_presentation": self.vp_token
|
"verificable_presentation": self.vp_token,
|
||||||
}
|
"sim": 10.0,
|
||||||
template = get_template(
|
"mensual": 15.0,
|
||||||
self.template_name,
|
"total": 25.0
|
||||||
).render()
|
})
|
||||||
return HttpResponse(template)
|
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):
|
def get_form_kwargs(self):
|
||||||
kwargs = super().get_form_kwargs()
|
kwargs = super().get_form_kwargs()
|
||||||
|
if not self.vp_token:
|
||||||
|
return kwargs
|
||||||
|
|
||||||
self.vp_token.get_user_info()
|
self.vp_token.get_user_info()
|
||||||
kwargs['verificable_presentation'] = self.vp_token
|
kwargs['verificable_presentation'] = self.vp_token
|
||||||
kwargs["nif"] = self.vp_token.user_info.get("nif", '')
|
kwargs["nif"] = self.vp_token.user_info.get("nif", '')
|
||||||
|
@ -58,6 +80,9 @@ class PromotionMobile1View(FormView):
|
||||||
return redirect(url)
|
return redirect(url)
|
||||||
|
|
||||||
def get_discount(self, code):
|
def get_discount(self, code):
|
||||||
|
if not code:
|
||||||
|
return
|
||||||
|
|
||||||
self.authorization = Authorization.objects.filter(
|
self.authorization = Authorization.objects.filter(
|
||||||
code=code,
|
code=code,
|
||||||
code_unused=False
|
code_unused=False
|
||||||
|
|
Loading…
Reference in New Issue