admin: set invitation’s created_by properly, remove edit of invite

This commit is contained in:
Jens Langhammer 2018-12-10 14:38:44 +01:00
parent 6bcb5ef8ef
commit 57f285ae54
4 changed files with 18 additions and 17 deletions

View file

@ -17,18 +17,17 @@
<table class="table table-striped table-bordered"> <table class="table table-striped table-bordered">
<thead> <thead>
<tr> <tr>
<th>{% trans 'Name' %}</th> <th>{% trans 'Expiry' %}</th>
<th>{% trans 'Provider' %}</th> <th>{% trans 'Link' %}</th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for invitation in object_list %} {% for invitation in object_list %}
<tr> <tr>
<td>{{ invitation.name }}</td> <td>{{ invitation.expires|default:"Never" }}</td>
<td>{{ invitation.provider }}</td> <td><pre>test</pre></td>
<td> <td>
<a class="btn btn-default btn-sm" href="{% url 'passbook_admin:invitation-update' pk=invitation.uuid %}?back={{ request.get_full_path }}">{% trans 'Edit' %}</a>
<a class="btn btn-default btn-sm" href="{% url 'passbook_admin:invitation-delete' pk=invitation.uuid %}?back={{ request.get_full_path }}">{% trans 'Delete' %}</a> <a class="btn btn-default btn-sm" href="{% url 'passbook_admin:invitation-delete' pk=invitation.uuid %}?back={{ request.get_full_path }}">{% trans 'Delete' %}</a>
</td> </td>
</tr> </tr>

View file

@ -37,8 +37,6 @@ urlpatterns = [
# Invitations # Invitations
path('invitations/', invitations.InviteListView.as_view(), name='invitations'), path('invitations/', invitations.InviteListView.as_view(), name='invitations'),
path('invitations/create/', invitations.InviteCreateView.as_view(), name='invitation-create'), path('invitations/create/', invitations.InviteCreateView.as_view(), name='invitation-create'),
path('invitations/<uuid:pk>/update/',
invitations.InviteUpdateView.as_view(), name='invitation-update'),
path('invitations/<uuid:pk>/delete/', path('invitations/<uuid:pk>/delete/',
invitations.InviteDeleteView.as_view(), name='invitation-delete'), invitations.InviteDeleteView.as_view(), name='invitation-delete'),
# path('api/v1/', include('passbook.admin.api.v1.urls')) # path('api/v1/', include('passbook.admin.api.v1.urls'))

View file

@ -24,15 +24,10 @@ class InviteCreateView(SuccessMessageMixin, AdminRequiredMixin, CreateView):
success_message = _('Successfully created Invite') success_message = _('Successfully created Invite')
form_class = InviteForm form_class = InviteForm
def get_initial(self):
class InviteUpdateView(SuccessMessageMixin, AdminRequiredMixin, UpdateView): return {
"""Update invitation""" 'created_by': self.request.user
}
model = Invite
template_name = 'generic/update.html'
success_url = reverse_lazy('passbook_admin:invitations')
success_message = _('Successfully updated Invite')
form_class = InviteForm
class InviteDeleteView(SuccessMessageMixin, AdminRequiredMixin, DeleteView): class InviteDeleteView(SuccessMessageMixin, AdminRequiredMixin, DeleteView):
"""Delete invitation""" """Delete invitation"""

View file

@ -11,4 +11,13 @@ class InviteForm(forms.ModelForm):
class Meta: class Meta:
model = Invite model = Invite
fields = '__all__' fields = ['created_by', 'expires', 'fixed_username', 'fixed_email']
labels = {
'fixed_username': "Force user's username (optional)",
'fixed_email': "Force user's email (optional)",
}
widgets = {
'created_by': forms.Select(attrs={'disabled': 'disabled'}),
'fixed_username': forms.TextInput(),
'fixed_email': forms.TextInput(),
}