edit and delete memberships
This commit is contained in:
parent
a43b522faf
commit
021410e316
|
@ -125,7 +125,6 @@ class AdminPeopleRegisterView(People, CreateView):
|
|||
success_url = reverse_lazy('idhub:admin_people_list')
|
||||
|
||||
def get_success_url(self):
|
||||
# import pdb; pdb.set_trace()
|
||||
self.success_url = reverse_lazy(
|
||||
'idhub:admin_people_membership_new',
|
||||
kwargs={"pk": self.object.id}
|
||||
|
@ -163,6 +162,52 @@ class AdminPeopleMembershipRegisterView(People, CreateView):
|
|||
kwargs = super().get_form_kwargs()
|
||||
return kwargs
|
||||
|
||||
def get_success_url(self):
|
||||
self.success_url = reverse_lazy(
|
||||
'idhub:admin_people_edit',
|
||||
kwargs={"pk": self.user.id}
|
||||
)
|
||||
return self.success_url
|
||||
|
||||
|
||||
class AdminPeopleMembershipEditView(People, CreateView):
|
||||
template_name = "idhub/admin_people_membership_register.html"
|
||||
subtitle = _('People add membership')
|
||||
icon = 'bi bi-person'
|
||||
model = Membership
|
||||
from_class = MembershipForm
|
||||
fields = ('type', 'start_date', 'end_date')
|
||||
success_url = reverse_lazy('idhub:admin_people_list')
|
||||
|
||||
def get_form(self):
|
||||
form = super().get_form()
|
||||
form.fields['start_date'].widget.input_type = 'date'
|
||||
form.fields['end_date'].widget.input_type = 'date'
|
||||
return form
|
||||
|
||||
def get_form_kwargs(self):
|
||||
pk = self.kwargs.get('pk')
|
||||
if pk:
|
||||
self.object = get_object_or_404(self.model, pk=pk)
|
||||
kwargs = super().get_form_kwargs()
|
||||
return kwargs
|
||||
|
||||
|
||||
class AdminPeopleMembershipDeleteView(AdminPeopleView):
|
||||
model = Membership
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.pk = kwargs['pk']
|
||||
self.object = get_object_or_404(self.model, pk=self.pk)
|
||||
|
||||
if self.object != self.request.user:
|
||||
user = self.object.user
|
||||
self.object.delete()
|
||||
else:
|
||||
messages.error(self.request, _('Is not possible delete your account!'))
|
||||
|
||||
return redirect('idhub:admin_people_edit', user.id)
|
||||
|
||||
|
||||
class AdminRolesView(AccessControl):
|
||||
template_name = "idhub/admin_roles.html"
|
||||
|
|
|
@ -77,3 +77,6 @@ class Membership(models.Model):
|
|||
on_delete=models.CASCADE,
|
||||
related_name='memberships',
|
||||
)
|
||||
|
||||
def get_type(self):
|
||||
return dict(self.Types.choices).get(self.type)
|
||||
|
|
|
@ -47,6 +47,31 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Membership' %}</button></th>
|
||||
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'From' %}</button></th>
|
||||
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'To' %}</button></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for membership in object.memberships.all %}
|
||||
<tr>
|
||||
<td>{{ membership.get_type }}</td>
|
||||
<td>{{ membership.start_date|default:'' }}</td>
|
||||
<td>{{ membership.end_date|default:'' }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal -->
|
||||
<div class="modal" id="confirm-delete" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
|
|
|
@ -29,4 +29,36 @@
|
|||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
<div class="row mt-5">
|
||||
<div class="col">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'Membership' %}</button></th>
|
||||
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'From' %}</button></th>
|
||||
<th scope="col"><button type="button" class="btn btn-grey border border-dark">{% trans 'To' %}</button></th>
|
||||
<th scope="col"></th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for membership in object.memberships.all %}
|
||||
<tr>
|
||||
<td>{{ membership.get_type }}</td>
|
||||
<td>{{ membership.start_date|default:'' }}</td>
|
||||
<td>{{ membership.end_date|default:'' }}</td>
|
||||
<td><a href="{% url 'idhub:admin_people_membership_edit' membership.id %}" title="{% trans 'Edit' %}"><i class="bi bi-pencil-square"></i></a></td>
|
||||
<td><a href="{% url 'idhub:admin_people_membership_del' membership.id %}" title="{% trans 'Delete' %}"><i class="bi bi-trash"></i></a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="form-actions-no-box">
|
||||
<a class="btn btn-green-admin" href="{% url 'idhub:admin_people_membership_new' object.id %}">{% translate "Add membership" %} <i class="bi bi-plus"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -66,6 +66,10 @@ urlpatterns = [
|
|||
name='admin_people_new'),
|
||||
path('admin/people/<int:pk>/membership/new/', views_admin.AdminPeopleMembershipRegisterView.as_view(),
|
||||
name='admin_people_membership_new'),
|
||||
path('admin/membership/<int:pk>/edit/', views_admin.AdminPeopleMembershipEditView.as_view(),
|
||||
name='admin_people_membership_edit'),
|
||||
path('admin/membership/<int:pk>/del/', views_admin.AdminPeopleMembershipDeleteView.as_view(),
|
||||
name='admin_people_membership_del'),
|
||||
path('admin/roles/', views_admin.AdminRolesView.as_view(),
|
||||
name='admin_roles'),
|
||||
path('admin/services/', views_admin.AdminServicesView.as_view(),
|
||||
|
|
Loading…
Reference in New Issue