get_link & clean views

This commit is contained in:
Guilhem Saurel 2016-06-28 01:04:45 +02:00
parent 9426c28f0f
commit fa7c943b3f
11 changed files with 40 additions and 29 deletions

View File

@ -55,7 +55,7 @@ class Participation(PonyConfModel):
return "%s participation to %s" % (str(self.user.profile), self.site.name)
def get_absolute_url(self):
return reverse('show-participation', kwargs={'username': self.user.username})
return reverse('edit-participant', kwargs={'username': self.user.username})
def is_staff(self):
return self.user.is_superuser or self.orga or self.topic_set.exists()

View File

@ -15,19 +15,29 @@
<th>#</th>
<th>Username</th>
<th>Fullname</th>
<th>Administration</th>
<th>Orga</th>
<th>Reviews</th>
<th>Conversations</th>
</tr>
{% for participation in participation_list %}
<tr>
<th>{{ forloop.counter }}</th>
<td>{{ participation.user.username }}</td>
<td><a href="{{ participation.get_absolute_url }}">{{ participation.user.username }}</a></td>
<td>{{ participation.user.get_full_name }}</td>
<td>{{ participation.orga|yesno:"✔,✘" }}</td>
<td>{% for topic in participation.topic_set.all %}{{ topic.get_link }}{% if not forloop.last %},
{% endif %}{% endfor %}</td>
<td>
<a href="{% url 'conversation' participation.user.username %}" data-toggle="tooltip" data-placement="bottom" title="View conversation"><span class="glyphicon glyphicon-envelope"></span></a>
<a href="{% url 'conversation' participation.user.username %}" data-toggle="tooltip" data-placement="bottom"
title="View conversation"><span class="glyphicon glyphicon-envelope"></span></a>
{% if request.user in participation.conversation.subscribers.all %}
<a href="{% url 'unsubscribe-conversation' participation.user.username %}?next={% url 'participants' %}" data-toggle="tooltip" data-placement="bottom" title="Unsubscribe to conversation"><span class="glyphicon glyphicon-star"></span></a>
<a href="{% url 'unsubscribe-conversation' participation.user.username %}?next={% url 'list-participant' %}"
data-toggle="tooltip" data-placement="bottom" title="Unsubscribe to conversation">
<span class="glyphicon glyphicon-star"></span></a>
{% else %}
<a href="{% url 'subscribe-conversation' participation.user.username %}?next={% url 'participants' %}" data-toggle="tooltip" data-placement="bottom" title="Subscribe to conversation"><span class="glyphicon glyphicon-star-empty"></span></a>
<a href="{% url 'subscribe-conversation' participation.user.username %}?next={% url 'list-participant' %}"
data-toggle="tooltip" data-placement="bottom" title="Subscribe to conversation">
<span class="glyphicon glyphicon-star-empty"></span></a>
{% endif %}
</td>
</tr>

View File

@ -10,13 +10,13 @@ ROOT_URL = 'accounts'
class AccountTests(TestCase):
def setUp(self):
for guy in 'ab':
User.objects.create_user(guy, email='%s@example.org' % guy, password=guy)
Participation.objects.create(user=User.objects.first(), site=Site.objects.first())
a, b, c = (User.objects.create_user(guy, email='%s@example.org' % guy, password=guy) for guy in 'abc')
Participation.objects.create(user=a, site=Site.objects.first())
Participation.objects.create(user=c, site=Site.objects.first(), orga=True)
def test_models(self):
self.assertEqual(Profile.objects.count(), 2)
self.client.login(username='b', password='b')
self.assertEqual(Profile.objects.count(), 3)
self.client.login(username='c', password='c')
for model in [Profile, Participation]:
item = model.objects.first()
self.assertEqual(self.client.get(item.full_link()).status_code, 200)
@ -42,10 +42,9 @@ class AccountTests(TestCase):
self.client.logout()
def test_participant_views(self):
self.assertEqual(self.client.get(reverse('participants')).status_code, 302)
self.client.login(username='b', password='b')
self.assertEqual(self.client.get(reverse('participants')).status_code, 403)
self.assertEqual(self.client.get(reverse('list-participant')).status_code, 302)
b = User.objects.get(username='b')
b.is_superuser = True
b.save()
self.assertEqual(self.client.get(reverse('participants')).status_code, 200)
self.assertEqual(self.client.get(reverse('list-participant')).status_code, 200)

View File

@ -7,9 +7,9 @@ from . import views
urlpatterns = [
url(r'^register/$', views.Registration.as_view(), name='register'),
url(r'^profile/$', views.profile, name='profile'),
url(r'^profile/(?P<username>[\w.@+-]+)$', views.edit, name='edit-profile'),
url(r'^login/$', auth_views.login, {'extra_context': {'buttons': [views.RESET_PASSWORD_BUTTON]}}, name='login'),
url(r'^logout/$', auth_views.logout, {'next_page': settings.LOGOUT_REDIRECT_URL}, name='logout'),
url(r'^admin/participants/$', views.ParticipantList.as_view(), name='participants'),
url(r'^admin/participants/$', views.ParticipantList.as_view(), name='list-participant'),
url(r'^admin/participant/(?P<username>[\w.@+-]+)$', views.edit, name='edit-participant'),
url(r'', include('django.contrib.auth.urls')),
]

View File

@ -63,7 +63,7 @@
{% if request.user.is_staff %}
<a role="menuitem" tabindex="-1" href="{% url 'admin:index' %}"><span class="glyphicon glyphicon-dashboard"></span>&nbsp;Django Admin</a>
{% endif %}
<a role="menuitem" tabindex="-1" href="{% url 'participants' %}"><span class="glyphicon glyphicon-user"></span>&nbsp;Participants</a>
<a role="menuitem" tabindex="-1" href="{% url 'list-participant' %}"><span class="glyphicon glyphicon-user"></span>&nbsp;Participants</a>
<a role="menuitem" tabindex="-1" href="{% url 'correspondents' %}"><span class="glyphicon glyphicon-envelope"></span>&nbsp;Correspondence</a>
</li>
</ul>

View File

@ -1,5 +1,6 @@
from django.contrib.sites.shortcuts import get_current_site
from django.db import models
from django.utils.html import mark_safe
def enum_to_choices(enum):
@ -16,3 +17,6 @@ class PonyConfModel(models.Model):
def full_link(self, request=None):
protocol = 'https' if request is None or request.is_secure() else 'http'
return '%s://%s%s' % (protocol, get_current_site(request), self.get_absolute_url())
def get_link(self):
return mark_safe('<a href="%s">%s</a>' % (self.get_absolute_url(), self))

View File

@ -4,7 +4,7 @@
<li>{{ event.list.0.get_event_display }}
<ul>{% for talk in event.list %}
<li>
<a href="{% url 'show-talk' talk.slug %}">{{ talk }}</a>
{{ talk.get_link }}
<i>by</i>
{% for speaker in talk.speakers.all %}
<a href="{% url 'show-speaker' speaker.username %}">{{ speaker }}</a>
@ -12,7 +12,7 @@
{% endfor %}
<i>in</i>
{% for topic in talk.topics.all %}
<a href="{{ topic.get_absolute_url }}">{{ topic }}</a>
{{ topic.get_link }}
{% if forloop.revcounter == 2 %} and {% elif not forloop.last %}, {% endif %}
{% endfor %}
</li>

View File

@ -30,7 +30,7 @@
<ul>
{% for topic in talk.topics.all %}
<li><a href="{% url 'list-talks-by-topic' topic.slug %}">{{ topic }}</a></li>
<li>{{ topic.get_link }}</li>
{% endfor %}
</ul>

View File

@ -9,13 +9,11 @@
<h1>Topics:</h1>
<ul>
{% for topic in topic_list %}
<li>
<a href="{% url 'list-talks-by-topic' topic.slug %}">{{ topic.name }}</a>
</li>
{% empty %}
<li><i>No topic.</i></li>
{% endfor %}
{% for topic in topic_list %}
<li>{{ topic.get_link }} </li>
{% empty %}
<li><i>No topic.</i></li>
{% endfor %}
</ul>
{% if request|staff %}

View File

@ -16,7 +16,7 @@
{% if request|edit_profile:profile %}
<h2>Notes</h2>
<p>{{ profile.notes }}</p>
<a href="{% url 'edit-profile' profile.user.username %}" class="btn btn-success">Edit</a>
<a href="{% url 'edit-participant' profile.user.username %}" class="btn btn-success">Edit</a>
{% endif %}

View File

@ -95,7 +95,7 @@ class TopicCreate(StaffRequiredMixin, CreateView):
class SpeakerList(StaffRequiredMixin, ListView):
queryset = User.objects.filter(speech__talk__in=Talk.on_site.all())
queryset = User.objects.filter(speech__talk__in=Talk.on_site.all()).distinct()
template_name = 'proposals/speaker_list.html'