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' icon = 'bi bi-patch-check-fill'
wallet = True wallet = True
model = DID model = DID
fields = ('did', 'label') fields = ('label',)
success_url = reverse_lazy('idhub:admin_dids') success_url = reverse_lazy('idhub:admin_dids')
object = None 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): def form_valid(self, form):
form.instance.user = self.request.user
form.instance.did = iota.issue_did()
form.save() form.save()
messages.success(self.request, _('DID created successfully')) messages.success(self.request, _('DID created successfully'))
return super().form_valid(form) return super().form_valid(form)
@ -485,7 +474,7 @@ class AdminDidEditView(Credentials, UpdateView):
icon = 'bi bi-patch-check-fill' icon = 'bi bi-patch-check-fill'
wallet = True wallet = True
model = DID model = DID
fields = ('did', 'label') fields = ('label',)
success_url = reverse_lazy('idhub:admin_dids') success_url = reverse_lazy('idhub:admin_dids')
def get(self, request, *args, **kwargs): 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) self.object = get_object_or_404(self.model, pk=self.pk)
return super().get(request, *args, **kwargs) 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): def form_valid(self, form):
user = form.save() user = form.save()
messages.success(self.request, _('DID updated successfully')) messages.success(self.request, _('DID updated successfully'))

View file

@ -43,7 +43,7 @@
<div class="modal-dialog"> <div class="modal-dialog">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <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> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div> </div>
<div class="modal-body"> <div class="modal-body">

View file

@ -27,7 +27,7 @@
</div> </div>
<div class="form-actions-no-box"> <div class="form-actions-no-box">
<a class="btn btn-grey" href="{% url 'idhub:user_dids' %}">{% trans "Cancel" %}</a> <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> </div>
</form> </form>

View file

@ -43,7 +43,7 @@
<div class="modal-dialog"> <div class="modal-dialog">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <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> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div> </div>
<div class="modal-body"> <div class="modal-body">

View file

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