From b4b55a811d55ffeb810385fa048539df13157729 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 14 Dec 2023 17:59:40 +0100 Subject: [PATCH] add more translate sentens --- idhub/admin/forms.py | 2 +- idhub/models.py | 1 + idhub/templates/idhub/base.html | 2 +- idhub/templates/idhub/base_admin.html | 2 +- idhub/urls.py | 3 -- idhub/user/forms.py | 47 +++------------------------ idhub/user/views.py | 25 -------------- idhub_auth/forms.py | 7 ++-- idhub_auth/models.py | 7 ++-- 9 files changed, 15 insertions(+), 81 deletions(-) diff --git a/idhub/admin/forms.py b/idhub/admin/forms.py index 1919a62..2649f4b 100644 --- a/idhub/admin/forms.py +++ b/idhub/admin/forms.py @@ -139,7 +139,7 @@ class ImportForm(forms.Form): class SchemaForm(forms.Form): - file_template = forms.FileField() + file_template = forms.FileField(label=_("File template")) class MembershipForm(forms.ModelForm): diff --git a/idhub/models.py b/idhub/models.py index 3aa6ec8..7d1ef6c 100644 --- a/idhub/models.py +++ b/idhub/models.py @@ -629,6 +629,7 @@ class UserRol(models.Model): ) service = models.ForeignKey( Service, + verbose_name=_("Service"), on_delete=models.CASCADE, related_name='users', ) diff --git a/idhub/templates/idhub/base.html b/idhub/templates/idhub/base.html index 834b7ef..390cb33 100644 --- a/idhub/templates/idhub/base.html +++ b/idhub/templates/idhub/base.html @@ -139,7 +139,7 @@

{{ title }}

- +
diff --git a/idhub/templates/idhub/base_admin.html b/idhub/templates/idhub/base_admin.html index 1253806..c97f165 100644 --- a/idhub/templates/idhub/base_admin.html +++ b/idhub/templates/idhub/base_admin.html @@ -171,7 +171,7 @@

{{ title }}

- +
diff --git a/idhub/urls.py b/idhub/urls.py index 48b9214..d139c32 100644 --- a/idhub/urls.py +++ b/idhub/urls.py @@ -88,9 +88,6 @@ urlpatterns = [ path('user/credentials_presentation/demand', views_user.DemandAuthorizationView.as_view(), name='user_demand_authorization'), - path('user/credentials_presentation/', - views_user.CredentialsPresentationView.as_view(), - name='user_credentials_presentation'), # Admin path('admin/dashboard/', views_admin.DashboardView.as_view(), diff --git a/idhub/user/forms.py b/idhub/user/forms.py index 5b6f9ab..5ac04ad 100644 --- a/idhub/user/forms.py +++ b/idhub/user/forms.py @@ -1,6 +1,8 @@ import requests from django import forms from django.conf import settings +from django.utils.translation import gettext_lazy as _ + from idhub_auth.models import User from idhub.models import DID, VerificableCredential from oidc4vp.models import Organization @@ -15,8 +17,8 @@ class ProfileForm(forms.ModelForm): class RequestCredentialForm(forms.Form): - did = forms.ChoiceField(choices=[]) - credential = forms.ChoiceField(choices=[]) + did = forms.ChoiceField(label=_("Did"), choices=[]) + credential = forms.ChoiceField(label=_("Credential"), choices=[]) def __init__(self, *args, **kwargs): self.user = kwargs.pop('user', None) @@ -59,7 +61,7 @@ class RequestCredentialForm(forms.Form): class DemandAuthorizationForm(forms.Form): - organization = forms.ChoiceField(choices=[]) + organization = forms.ChoiceField(label=_("Organization"), choices=[]) def __init__(self, *args, **kwargs): self.user = kwargs.pop('user', None) @@ -85,42 +87,3 @@ class DemandAuthorizationForm(forms.Form): return - -class CredentialPresentationForm(forms.Form): - organization = forms.ChoiceField(choices=[]) - # credential = forms.ChoiceField(choices=[]) - - def __init__(self, *args, **kwargs): - self.user = kwargs.pop('user', None) - super().__init__(*args, **kwargs) - self.fields['organization'].choices = [ - (x.id, x.name) for x in Organization.objects.filter() - ] - # self.fields['credential'].choices = [ - # (x.id, x.type()) for x in VerificableCredential.objects.filter( - # user=self.user, - # status=VerificableCredential.Status.ISSUED - # ) - # ] - - def save(self, commit=True): - self.org = Organization.objects.filter( - id=self.data['organization'] - ) - self.cred = VerificableCredential.objects.filter( - user=self.user, - id=self.data['credential'], - status=VerificableCredential.Status.ISSUED - ) - if not all([self.org.exists(), self.cred.exists()]): - return - - self.org = self.org[0] - self.cred = self.cred[0] - - if commit: - self.org.send(self.cred) - return self.cred - - return - diff --git a/idhub/user/views.py b/idhub/user/views.py index d7b1cb3..e6e28dc 100644 --- a/idhub/user/views.py +++ b/idhub/user/views.py @@ -15,7 +15,6 @@ from django.contrib import messages from idhub.user.forms import ( ProfileForm, RequestCredentialForm, - CredentialPresentationForm, DemandAuthorizationForm ) from idhub.mixins import UserView @@ -181,30 +180,6 @@ class DemandAuthorizationView(MyWallet, FormView): return super().form_valid(form) -class CredentialsPresentationView(MyWallet, FormView): - template_name = "idhub/user/credentials_presentation.html" - subtitle = _('Credential presentation') - icon = 'bi bi-patch-check-fill' - form_class = CredentialPresentationForm - success_url = reverse_lazy('idhub:user_credentials') - - def get_form_kwargs(self): - kwargs = super().get_form_kwargs() - kwargs['user'] = self.request.user - kwargs['authorize'] = self.request.GET.params.get("uri") - return kwargs - - def form_valid(self, form): - cred = form.save() - if cred: - Event.set_EV_CREDENTIAL_PRESENTED_BY_USER(cred, form.org) - Event.set_EV_CREDENTIAL_PRESENTED(cred, form.org) - messages.success(self.request, _("The credential was presented successfully!")) - else: - messages.error(self.request, _("Error sending credential!")) - return super().form_valid(form) - - class DidsView(MyWallet, TemplateView): template_name = "idhub/user/dids.html" subtitle = _('Identities (DIDs)') diff --git a/idhub_auth/forms.py b/idhub_auth/forms.py index f4297b7..f4279b7 100644 --- a/idhub_auth/forms.py +++ b/idhub_auth/forms.py @@ -6,15 +6,12 @@ from idhub_auth.models import User class ProfileForm(forms.ModelForm): - first_name = forms.CharField(label=_("First name"), required=True) - last_name = forms.CharField(label=_("Last name"), required=True) + first_name = forms.CharField(required=True) + last_name = forms.CharField(required=True) class Meta: model = User fields = ['first_name', 'last_name', 'email'] - labels = { - 'email': _('Email address'), - } def clean_first_name(self): first_name = super().clean()['first_name'] diff --git a/idhub_auth/models.py b/idhub_auth/models.py index ccda94c..07a7896 100644 --- a/idhub_auth/models.py +++ b/idhub_auth/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.utils.translation import gettext_lazy as _ from django.contrib.auth.models import BaseUserManager, AbstractBaseUser @@ -35,14 +36,14 @@ class UserManager(BaseUserManager): class User(AbstractBaseUser): email = models.EmailField( - verbose_name="email address", + _('Email address'), max_length=255, unique=True, ) is_active = models.BooleanField(default=True) is_admin = models.BooleanField(default=False) - first_name = models.CharField(max_length=255, blank=True, null=True) - last_name = models.CharField(max_length=255, blank=True, null=True) + first_name = models.CharField(_("First name"), max_length=255, blank=True, null=True) + last_name = models.CharField(_("Last name"), max_length=255, blank=True, null=True) objects = UserManager()