notes on a speaker
This commit is contained in:
parent
8d44ec7f40
commit
b8cfaea5e1
|
@ -3,7 +3,7 @@ from django.forms.models import modelform_factory
|
|||
|
||||
from .models import Participation, Profile
|
||||
|
||||
__all__ = ['UserForm', 'ProfileForm']
|
||||
__all__ = ['UserForm', 'ProfileForm', 'ProfileOrgaForm']
|
||||
|
||||
|
||||
UserForm = modelform_factory(User, fields=['first_name', 'last_name', 'email', 'username'])
|
||||
|
@ -11,3 +11,5 @@ UserForm = modelform_factory(User, fields=['first_name', 'last_name', 'email', '
|
|||
ParticipationForm = modelform_factory(Participation, fields=['transport', 'connector', 'sound', 'constraints'])
|
||||
|
||||
ProfileForm = modelform_factory(Profile, fields=['biography'])
|
||||
|
||||
ProfileOrgaForm = modelform_factory(Profile, fields=['biography', 'notes'])
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.7 on 2016-06-25 15:03
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('accounts', '0007_participation_orga'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='profile',
|
||||
name='notes',
|
||||
field=models.TextField(default=''),
|
||||
),
|
||||
]
|
|
@ -18,6 +18,7 @@ class Profile(PonyConfModel):
|
|||
user = models.OneToOneField(User)
|
||||
biography = models.TextField(blank=True, verbose_name='Biography')
|
||||
email_token = models.CharField(max_length=12, default=generate_user_uid, unique=True)
|
||||
notes = models.TextField(default='')
|
||||
|
||||
def __str__(self):
|
||||
return self.user.get_full_name() or self.user.username
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
{% block speakertab %} class="active"{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h1>{{ profile }}</h1>
|
||||
|
||||
{% include "_form.html" %}
|
||||
|
||||
{% endblock %}
|
|
@ -1,6 +1,6 @@
|
|||
from django import template
|
||||
|
||||
from accounts.utils import is_staff
|
||||
from accounts.utils import can_edit_profile, is_staff
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
@ -8,3 +8,8 @@ register = template.Library()
|
|||
@register.filter
|
||||
def staff(request):
|
||||
return is_staff(request, request.user)
|
||||
|
||||
|
||||
@register.filter
|
||||
def edit_profile(request, profile):
|
||||
return can_edit_profile(request, profile)
|
||||
|
|
|
@ -5,7 +5,8 @@ from django.contrib.auth import views as auth_views
|
|||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^profile$', views.profile, name='profile'),
|
||||
url(r'^profile/$', views.profile, name='profile'),
|
||||
url(r'^profile/(?P<username>[\w.@+-]+)$', views.edit, name='edit-profile'),
|
||||
url(r'^logout/$', auth_views.logout, {'next_page': settings.LOGOUT_REDIRECT_URL}, name='logout'),
|
||||
url(r'^admin/participants/$', views.participants, name='participants'),
|
||||
url(r'^admin/participant/(?P<username>[\w.@+-]+)$', views.participant, name='show-participation'),
|
||||
|
|
|
@ -8,3 +8,8 @@ def generate_user_uid():
|
|||
|
||||
def is_staff(request, user):
|
||||
return user.is_authenticated() and user.participation_set.get(site=get_current_site(request)).is_staff()
|
||||
|
||||
|
||||
def can_edit_profile(request, profile):
|
||||
editor = request.user.participation_set.get(site=get_current_site(request))
|
||||
return editor.orga or editor.topic_set.filter(talk__speakers=profile.user).exists()
|
||||
|
|
|
@ -3,8 +3,9 @@ from django.contrib.auth.decorators import login_required
|
|||
from django.core.exceptions import PermissionDenied
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
|
||||
from .forms import ParticipationForm, ProfileForm, UserForm
|
||||
from .models import Participation
|
||||
from .forms import ParticipationForm, ProfileForm, ProfileOrgaForm, UserForm
|
||||
from .models import Participation, Profile
|
||||
from .utils import can_edit_profile
|
||||
|
||||
|
||||
@login_required
|
||||
|
@ -40,3 +41,22 @@ def participants(request):
|
|||
def participant(request, username):
|
||||
return render(request, 'admin/participant.html',
|
||||
{'participant': get_object_or_404(Participation, user__username=username)})
|
||||
|
||||
|
||||
@login_required
|
||||
def edit(request, username):
|
||||
|
||||
profile = get_object_or_404(Profile, user__username=username)
|
||||
if not can_edit_profile(request, profile):
|
||||
raise PermissionDenied()
|
||||
|
||||
form = ProfileOrgaForm(request.POST or None, instance=profile)
|
||||
|
||||
if request.method == 'POST':
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
messages.success(request, 'Profile updated successfully.')
|
||||
else:
|
||||
messages.error(request, 'Please correct those errors.')
|
||||
|
||||
return render(request, 'accounts/edit_profile.html', {'form': form, 'profile': profile})
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
{% load bootstrap3 %}
|
||||
<form action="" method="post" class="form-horizontal">
|
||||
{% csrf_token %}
|
||||
{% bootstrap_form form layout="horizontal" %}
|
||||
{% buttons layout="horizontal" %}
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
{% endbuttons %}
|
||||
</form>
|
||||
|
|
@ -1,12 +1,23 @@
|
|||
{% extends 'base.html' %}
|
||||
{% load accounts_tags %}
|
||||
|
||||
{% block speakertab %} class="active"{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h1>{{ user }}</h1>
|
||||
<h1>{{ profile }}</h1>
|
||||
|
||||
<b>Biography:</b>
|
||||
<p>{{ user.biography }}</p>
|
||||
<h2>Biography</h2>
|
||||
<p>{{ profile.biography }}</p>
|
||||
|
||||
<h2>Talks</h2>
|
||||
<a href="{% url 'list-talks-by-speaker' profile.user.username %}">See the list of talks with this speaker</a>
|
||||
|
||||
{% 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>
|
||||
{% endif %}
|
||||
|
||||
<a href="{% url 'list-talks-by-speaker' user.user.username %}">See the list of talks with this speaker</a>
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -95,12 +95,12 @@ class TopicCreate(StaffRequiredMixin, CreateView):
|
|||
|
||||
|
||||
class SpeakerList(StaffRequiredMixin, ListView):
|
||||
queryset = User.objects.filter(speech__talk=Talk.on_site.all())
|
||||
queryset = User.objects.filter(speech__talk__in=Talk.on_site.all())
|
||||
template_name = 'proposals/speaker_list.html'
|
||||
|
||||
|
||||
@login_required
|
||||
def user_details(request, username):
|
||||
return render(request, 'proposals/user_details.html', {
|
||||
'user': get_object_or_404(User, username=username).profile,
|
||||
'profile': get_object_or_404(User, username=username).profile,
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue