Add profiles to Trombi

This commit is contained in:
Skia 2017-05-12 10:25:26 +02:00
parent d88ffae51b
commit adeda41b52
6 changed files with 85 additions and 8 deletions

View File

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('trombi', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='trombi',
name='show_profiles',
field=models.BooleanField(default=True, verbose_name='show users profiles to each other'),
),
]

View File

@ -57,6 +57,7 @@ class Trombi(models.Model):
"able to make comments anymore.")) "able to make comments anymore."))
max_chars = models.IntegerField(_('maximum characters'), default=400, max_chars = models.IntegerField(_('maximum characters'), default=400,
help_text=_('Maximum number of characters allowed in a comment.')) help_text=_('Maximum number of characters allowed in a comment.'))
show_profiles = models.BooleanField(_("show users profiles to each other"), default=True)
club = models.OneToOneField(Club, related_name='trombi') club = models.OneToOneField(Club, related_name='trombi')
objects = TrombiManager() objects = TrombiManager()

View File

@ -0,0 +1,35 @@
{% extends "core/base.jinja" %}
{% block title %}
{% trans user_name=trombi_user.user.get_display_name() %}{{ user_name }}'s Trombi profile{% endtrans %}
{% endblock %}
{% block content %}
<h3>{% trans user_name=trombi_user.user.get_display_name() %}{{ user_name }}'s Trombi profile{% endtrans %}</h3>
<p> <a href="{{ url('trombi:user_tools') }}">{% trans %}Back to tools{% endtrans %}</a></p>
<div>
{% set profile_file = None %}
{% set scrub_file = None %}
{% if trombi_user.profile_pict %}
{% set profile_file = trombi_user.profile_pict.url %}
{% else %}
{% set profile_file = static('core/img/na.gif') %}
{% endif %}
{% if trombi_user.scrub_pict %}
{% set scrub_file = trombi_user.scrub_pict.url %}
{% else %}
{% set scrub_file = static('core/img/na.gif') %}
{% endif %}
<div style="max-width: 410px; margin: auto;">
<img src="{{ profile_file }}" alt="" style="max-width: 200px">
<img src="{{ scrub_file }}" alt="" style="max-width: 200px">
</div>
<dl>
{% for c in trombi_user.received_comments.all() %}
<dt style="font-weight: bold; font-size: 110%">{{ c.author.user.get_display_name() }}</dt>
<dd>{{ c.content}}</dd>
{% endfor %}
</dl>
</div>
{% endblock %}

View File

@ -38,14 +38,21 @@
<img src="{{ file }}" alt="" style="max-width: 100px"> <img src="{{ file }}" alt="" style="max-width: 100px">
</div> </div>
<div>{{ u.user.get_display_name() }}</div> <div>{{ u.user.get_display_name() }}</div>
{% if can_comment %} {% if trombi.show_profiles %}
{% set comment = u.received_comments.filter(author__id=user.trombi_user.id).first() %} <div>
{% if comment %} <a href="{{ url("trombi:user_profile", user_id=u.id) }}">{% trans %}Profile{% endtrans %}</a>
<a href="{{ url("trombi:edit_comment", comment_id=comment.id) }}">{% trans %}Edit comment{% endtrans %}</a> </div>
{% else %}
<a href="{{ url("trombi:new_comment", user_id=u.id) }}">{% trans %}Comment{% endtrans %}</a>
{% endif %}
{% endif %} {% endif %}
<div>
{% if can_comment %}
{% set comment = u.received_comments.filter(author__id=user.trombi_user.id).first() %}
{% if comment %}
<a href="{{ url("trombi:edit_comment", comment_id=comment.id) }}">{% trans %}Edit comment{% endtrans %}</a>
{% else %}
<a href="{{ url("trombi:new_comment", user_id=u.id) }}">{% trans %}Comment{% endtrans %}</a>
{% endif %}
{% endif %}
</div>
</div> </div>
{% endfor %} {% endfor %}
</div> </div>

View File

@ -32,6 +32,7 @@ urlpatterns = [
url(r'^(?P<trombi_id>[0-9]+)/delete/(?P<user_id>[0-9]+)$', TrombiDeleteUserView.as_view(), name='delete_user'), url(r'^(?P<trombi_id>[0-9]+)/delete/(?P<user_id>[0-9]+)$', TrombiDeleteUserView.as_view(), name='delete_user'),
url(r'^(?P<trombi_id>[0-9]+)$', TrombiDetailView.as_view(), name='detail'), url(r'^(?P<trombi_id>[0-9]+)$', TrombiDetailView.as_view(), name='detail'),
url(r'^(?P<user_id>[0-9]+)/new_comment$', TrombiCommentCreateView.as_view(), name='new_comment'), url(r'^(?P<user_id>[0-9]+)/new_comment$', TrombiCommentCreateView.as_view(), name='new_comment'),
url(r'^(?P<user_id>[0-9]+)/profile$', UserTrombiProfileView.as_view(), name='user_profile'),
url(r'^comment/(?P<comment_id>[0-9]+)/edit$', TrombiCommentEditView.as_view(), name='edit_comment'), url(r'^comment/(?P<comment_id>[0-9]+)/edit$', TrombiCommentEditView.as_view(), name='edit_comment'),
url(r'^tools$', UserTrombiToolsView.as_view(), name='user_tools'), url(r'^tools$', UserTrombiToolsView.as_view(), name='user_tools'),
url(r'^profile$', UserTrombiEditProfileView.as_view(), name='profile'), url(r'^profile$', UserTrombiEditProfileView.as_view(), name='profile'),

View File

@ -42,7 +42,7 @@ from club.models import Club
class TrombiForm(forms.ModelForm): class TrombiForm(forms.ModelForm):
class Meta: class Meta:
model = Trombi model = Trombi
fields = ['subscription_deadline', 'comments_deadline', 'max_chars'] fields = ['subscription_deadline', 'comments_deadline', 'max_chars', 'show_profiles']
widgets = { widgets = {
'subscription_deadline': SelectDate, 'subscription_deadline': SelectDate,
'comments_deadline': SelectDate, 'comments_deadline': SelectDate,
@ -160,6 +160,20 @@ class UserTrombiEditProfileView(UpdateView):
def get_success_url(self): def get_success_url(self):
return reverse('trombi:user_tools')+"?qn_success" return reverse('trombi:user_tools')+"?qn_success"
class UserTrombiProfileView(DetailView):
model = TrombiUser
pk_url_kwarg = "user_id"
template_name = "trombi/user_profile.jinja"
context_object_name = "trombi_user"
def get(self, request, *args, **kwargs):
self.object = self.get_object()
if (self.object.trombi.id != request.user.trombi_user.trombi.id or
self.object.user.id == request.user.id or
not self.object.trombi.show_profiles):
raise Http404()
return super(UserTrombiProfileView, self).get(request, *args, **kwargs)
class TrombiCommentFormView(): class TrombiCommentFormView():
""" """
Create/edit a trombi comment Create/edit a trombi comment