Add user-based case study listing
This commit is contained in:
parent
57ac8eab86
commit
eb7eabb7c7
@ -9,6 +9,8 @@ from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
from apps.map.models import CaseStudy
|
||||
|
||||
|
||||
class UserDetailView(LoginRequiredMixin, DetailView):
|
||||
model = get_user_model()
|
||||
@ -19,6 +21,15 @@ class UserDetailView(LoginRequiredMixin, DetailView):
|
||||
def get_object(self):
|
||||
return get_user_model().objects.get(username=self.request.user.username)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
# Get case studies for this user
|
||||
case_studies = CaseStudy.objects.filter(author=self.request.user.id)
|
||||
context['case_studies'] = case_studies
|
||||
|
||||
return context
|
||||
|
||||
|
||||
class UserRedirectView(LoginRequiredMixin, RedirectView):
|
||||
permanent = False
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
|
||||
@ -15,23 +14,40 @@
|
||||
|
||||
{% if object.first_name and object.last_name %}
|
||||
<h2>{{ object.first_name }} {{ object.last_name }} <i>({{ object.username }})</i></h2>
|
||||
{% else %}
|
||||
<h2>{{ object.username }}</h2>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if object == request.user %}
|
||||
<!-- Action buttons -->
|
||||
<div class="row">
|
||||
|
||||
<div class="col-sm-12">
|
||||
<a class="btn btn-primary" href="{% url 'profile:update' %}">{% trans 'Change Name' %}</a>
|
||||
<a class="btn btn-primary mx-1" href="{% url 'avatar_change' %}">Change Avatar</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<h3>Your case studies</h3>
|
||||
|
||||
{% if case_studies %}
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name
|
||||
<th>Approved
|
||||
<th>Actions
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for case in case_studies %}
|
||||
<tr>
|
||||
<td>{{ case.entry_name }}
|
||||
<td>{% if case.approved %}Yes{% else %}No{% endif %}
|
||||
<td><a href="{% url 'detail' case.slug %}">View</a> | Edit
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<p>You have no case studies.</p>
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
Loading…
Reference in New Issue
Block a user