remove did of Did forms

This commit is contained in:
Cayo Puigdefabregas 2023-11-03 16:27:40 +01:00
parent 580204b5fd
commit f00285624f
5 changed files with 16 additions and 45 deletions

View File

@ -456,24 +456,13 @@ class AdminDidRegisterView(Credentials, CreateView):
icon = 'bi bi-patch-check-fill'
wallet = True
model = DID
fields = ('did', 'label')
fields = ('label',)
success_url = reverse_lazy('idhub:admin_dids')
object = None
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
kwargs['initial'] = {
'did': iota.issue_did()
}
return kwargs
def get_form(self):
form = super().get_form()
form.fields['did'].required = False
form.fields['did'].disabled = True
return form
def form_valid(self, form):
form.instance.user = self.request.user
form.instance.did = iota.issue_did()
form.save()
messages.success(self.request, _('DID created successfully'))
return super().form_valid(form)
@ -485,7 +474,7 @@ class AdminDidEditView(Credentials, UpdateView):
icon = 'bi bi-patch-check-fill'
wallet = True
model = DID
fields = ('did', 'label')
fields = ('label',)
success_url = reverse_lazy('idhub:admin_dids')
def get(self, request, *args, **kwargs):
@ -493,12 +482,6 @@ class AdminDidEditView(Credentials, UpdateView):
self.object = get_object_or_404(self.model, pk=self.pk)
return super().get(request, *args, **kwargs)
def get_form(self):
form = super().get_form()
form.fields['did'].required = False
form.fields['did'].disabled = True
return form
def form_valid(self, form):
user = form.save()
messages.success(self.request, _('DID updated successfully'))

View File

@ -43,7 +43,7 @@
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">{% trans 'Delete DID' %} {{ d.did }}</h5>
<h5 class="modal-title" id="exampleModalLabel">{% trans 'Delete DID' %} "{{ d.label }}"</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">

View File

@ -27,7 +27,7 @@
</div>
<div class="form-actions-no-box">
<a class="btn btn-grey" href="{% url 'idhub:user_dids' %}">{% trans "Cancel" %}</a>
<input class="btn btn-green-admin" type="submit" name="submit" value="{% trans 'Save' %}" />
<input class="btn btn-green-user" type="submit" name="submit" value="{% trans 'Save' %}" />
</div>
</form>

View File

@ -43,7 +43,7 @@
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">{% trans 'Delete DID' %} {{ d.did }}</h5>
<h5 class="modal-title" id="exampleModalLabel">{% trans 'Delete DID' %} "{{ d.label }}"</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">

View File

@ -170,26 +170,20 @@ class UserDidRegisterView(MyWallet, CreateView):
icon = 'bi bi-patch-check-fill'
wallet = True
model = DID
fields = ('did', 'label')
fields = ('label',)
success_url = reverse_lazy('idhub:user_dids')
object = None
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
kwargs['initial'] = {
'did': iota.issue_did(),
'user': self.request.user
}
return kwargs
def get_form(self):
form = super().get_form()
form.fields['did'].required = False
form.fields['did'].disabled = True
return form
# def get_form_kwargs(self):
# kwargs = super().get_form_kwargs()
# kwargs['initial'] = {
# 'user': self.request.user
# }
# return kwargs
def form_valid(self, form):
form.instance.user = self.request.user
form.instance.did = iota.issue_did()
form.save()
messages.success(self.request, _('DID created successfully'))
return super().form_valid(form)
@ -201,7 +195,7 @@ class UserDidEditView(MyWallet, UpdateView):
icon = 'bi bi-patch-check-fill'
wallet = True
model = DID
fields = ('did', 'label')
fields = ('label',)
success_url = reverse_lazy('idhub:user_dids')
def get(self, request, *args, **kwargs):
@ -209,12 +203,6 @@ class UserDidEditView(MyWallet, UpdateView):
self.object = get_object_or_404(self.model, pk=self.pk)
return super().get(request, *args, **kwargs)
def get_form(self):
form = super().get_form()
form.fields['did'].required = False
form.fields['did'].disabled = True
return form
def form_valid(self, form):
user = form.save()
messages.success(self.request, _('DID updated successfully'))