SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 2a282d41 authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Add AffiliationUpdateView

parent 7cfe9650
No related branches found
No related tags found
No related merge requests found
......@@ -77,4 +77,9 @@ urlpatterns = [
views.AffiliationCreateView.as_view(),
name='affiliation_create'
),
url(
r'^affiliation/(?P<pk>[0-9]+)/update/$',
views.AffiliationUpdateView.as_view(),
name='affiliation_update'
),
]
......@@ -412,3 +412,28 @@ class AffiliationCreateView(UserPassesTestMixin, CreateView):
return reverse_lazy('profiles:profile_detail',
kwargs={'pk': self.object.profile.id})
return reverse_lazy('scipost:personal_page')
class AffiliationUpdateView(UserPassesTestMixin, UpdateView):
model = Affiliation
form_class = AffiliationForm
template_name = 'profiles/affiliation_form.html'
def test_func(self):
"""
Allow creating an Affiliation if user is Admin, EdAdmin or is
the Contributor to which this Profile is related.
"""
if self.request.user.has_perm('scipost.can_create_profiles'):
return True
return self.request.user.contributor.profile is self.object.profile
def get_success_url(self):
"""
If request.user is Admin or EdAdmin, redirect to profile detail view.
Otherwise if request.user is Profile owner, return to personal page.
"""
if self.request.user.has_perm('scipost.can_create_profiles'):
return reverse_lazy('profiles:profile_detail',
kwargs={'pk': self.object.profile.id})
return reverse_lazy('scipost:personal_page')
......@@ -159,6 +159,7 @@
<th>Category</th>
<th>From</th>
<th>Until</th>
<td>Actions</td>
</tr>
</thead>
<tbody>
......@@ -168,6 +169,10 @@
<td>{{ aff.get_category_display }}</td>
<td>{{ aff.date_from|date:'Y-m-d' }}</td>
<td>{{ aff.date_until|date:'Y-m-d' }}</td>
<td>
<ul class="list-unstyled">
<li><a href="{% url 'profiles:affiliation_update' pk=aff.id %}" class="text-warning">Update</a></li>
</ul>
</tr>
{% empty %}
<tr><td colspan="4">No Affiliation has been defined</td></tr>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment