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
|
from .models import Participation, Profile
|
||||||
|
|
||||||
__all__ = ['UserForm', 'ProfileForm']
|
__all__ = ['UserForm', 'ProfileForm', 'ProfileOrgaForm']
|
||||||
|
|
||||||
|
|
||||||
UserForm = modelform_factory(User, fields=['first_name', 'last_name', 'email', 'username'])
|
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'])
|
ParticipationForm = modelform_factory(Participation, fields=['transport', 'connector', 'sound', 'constraints'])
|
||||||
|
|
||||||
ProfileForm = modelform_factory(Profile, fields=['biography'])
|
ProfileForm = modelform_factory(Profile, fields=['biography'])
|
||||||
|
|
||||||
|
ProfileOrgaForm = modelform_factory(Profile, fields=['biography', 'notes'])
|
||||||
|
|
20
accounts/migrations/0008_profile_notes.py
Normal file
20
accounts/migrations/0008_profile_notes.py
Normal file
|
@ -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)
|
user = models.OneToOneField(User)
|
||||||
biography = models.TextField(blank=True, verbose_name='Biography')
|
biography = models.TextField(blank=True, verbose_name='Biography')
|
||||||
email_token = models.CharField(max_length=12, default=generate_user_uid, unique=True)
|
email_token = models.CharField(max_length=12, default=generate_user_uid, unique=True)
|
||||||
|
notes = models.TextField(default='')
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.user.get_full_name() or self.user.username
|
return self.user.get_full_name() or self.user.username
|
||||||
|
|
11
accounts/templates/accounts/edit_profile.html
Normal file
11
accounts/templates/accounts/edit_profile.html
Normal file
|
@ -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 django import template
|
||||||
|
|
||||||
from accounts.utils import is_staff
|
from accounts.utils import can_edit_profile, is_staff
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
@ -8,3 +8,8 @@ register = template.Library()
|
||||||
@register.filter
|
@register.filter
|
||||||
def staff(request):
|
def staff(request):
|
||||||
return is_staff(request, request.user)
|
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
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
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'^logout/$', auth_views.logout, {'next_page': settings.LOGOUT_REDIRECT_URL}, name='logout'),
|
||||||
url(r'^admin/participants/$', views.participants, name='participants'),
|
url(r'^admin/participants/$', views.participants, name='participants'),
|
||||||
url(r'^admin/participant/(?P<username>[\w.@+-]+)$', views.participant, name='show-participation'),
|
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):
|
def is_staff(request, user):
|
||||||
return user.is_authenticated() and user.participation_set.get(site=get_current_site(request)).is_staff()
|
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.core.exceptions import PermissionDenied
|
||||||
from django.shortcuts import get_object_or_404, render
|
from django.shortcuts import get_object_or_404, render
|
||||||
|
|
||||||
from .forms import ParticipationForm, ProfileForm, UserForm
|
from .forms import ParticipationForm, ProfileForm, ProfileOrgaForm, UserForm
|
||||||
from .models import Participation
|
from .models import Participation, Profile
|
||||||
|
from .utils import can_edit_profile
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -40,3 +41,22 @@ def participants(request):
|
||||||
def participant(request, username):
|
def participant(request, username):
|
||||||
return render(request, 'admin/participant.html',
|
return render(request, 'admin/participant.html',
|
||||||
{'participant': get_object_or_404(Participation, user__username=username)})
|
{'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})
|
||||||
|
|
9
ponyconf/templates/_form.html
Normal file
9
ponyconf/templates/_form.html
Normal file
|
@ -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' %}
|
{% extends 'base.html' %}
|
||||||
|
{% load accounts_tags %}
|
||||||
|
|
||||||
|
{% block speakertab %} class="active"{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<h1>{{ user }}</h1>
|
<h1>{{ profile }}</h1>
|
||||||
|
|
||||||
<b>Biography:</b>
|
<h2>Biography</h2>
|
||||||
<p>{{ user.biography }}</p>
|
<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 %}
|
{% endblock %}
|
||||||
|
|
|
@ -95,12 +95,12 @@ class TopicCreate(StaffRequiredMixin, CreateView):
|
||||||
|
|
||||||
|
|
||||||
class SpeakerList(StaffRequiredMixin, ListView):
|
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'
|
template_name = 'proposals/speaker_list.html'
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def user_details(request, username):
|
def user_details(request, username):
|
||||||
return render(request, 'proposals/user_details.html', {
|
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
Block a user