add conversations about talk in talk descriptions
This commit is contained in:
parent
6e0d87ddee
commit
58256e0d3b
|
@ -0,0 +1,8 @@
|
|||
<div class="panel panel-{% block panelstyleblock %}default{% endblock %}">
|
||||
<div class="panel-heading">
|
||||
{{ message.created }} | {{ message.author.profile }}
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
{{ message.content }}
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,14 @@
|
|||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
Send a message
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<form action="{{ form_url }}" method="post" role="form">
|
||||
{% csrf_token %}
|
||||
<div class="form-group">
|
||||
<textarea class="form-control" name="content" required></textarea>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-success"><span class="glyphicon glyphicon-envelope"></span> Send</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
|
@ -5,36 +5,16 @@
|
|||
{% block content %}
|
||||
|
||||
<div class="page-header">
|
||||
<h1>Messaging</h1>
|
||||
{% block heading %}
|
||||
<a href="{% url 'correspondents' %}" class="btn btn-primary"><span class="glyphicon glyphicon-arrow-left"></span> Go back to correspondents list</a>
|
||||
{% endblock %}
|
||||
<h1>Messaging</h1>
|
||||
{% block heading %}
|
||||
<a href="{% url 'correspondents' %}" class="btn btn-primary"><span class="glyphicon glyphicon-arrow-left"></span> Go back to correspondents list</a>
|
||||
{% endblock %}
|
||||
</div>
|
||||
|
||||
{% for message in message_list %}
|
||||
<div class="panel panel-{% block panelstyleblock %}default{% endblock %}">
|
||||
<div class="panel-heading">
|
||||
{{ message.date }} | {{ message.author.profile }}
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
{{ message.content }}
|
||||
</div>
|
||||
</div>
|
||||
{% include 'conversations/_message_detail.html' %}
|
||||
{% endfor %}
|
||||
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
Send a message
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<form action="" method="post" role="form">
|
||||
{% csrf_token %}
|
||||
<div class="form-group">
|
||||
<textarea class="form-control" name="content" required></textarea>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-success"><span class="glyphicon glyphicon-envelope"></span> Send</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% include 'conversations/_message_form.html' %}
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -7,6 +7,7 @@ urlpatterns = [
|
|||
url(r'^inbox/$', views.conversation, name='inbox'),
|
||||
url(r'^$', views.correspondents, name='correspondents'),
|
||||
url(r'^with/(?P<username>[\w.@+-]+)/$', views.conversation, name='conversation'),
|
||||
url(r'^about/(?P<talk>[\w.@+-]+)/$', views.talk_conversation, name='talk-conversation'),
|
||||
url(r'^subscribe/(?P<username>[\w.@+-]+)/$', views.subscribe, name='subscribe-conversation'),
|
||||
url(r'^unsubscribe/(?P<username>[\w.@+-]+)/$', views.unsubscribe, name='unsubscribe-conversation'),
|
||||
]
|
||||
|
|
|
@ -7,6 +7,7 @@ from django.core.urlresolvers import reverse
|
|||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
|
||||
from accounts.models import Participation
|
||||
from proposals.models import Talk
|
||||
|
||||
from .forms import MessageForm
|
||||
|
||||
|
@ -30,11 +31,9 @@ def conversation(request, username=None):
|
|||
form = MessageForm(request.POST or None)
|
||||
|
||||
if request.method == 'POST' and form.is_valid():
|
||||
message = form.save(commit=False)
|
||||
message.conversation = conversation
|
||||
message.author = request.user
|
||||
message.subject = "Assistance request from %s" % message.author.profile
|
||||
message.save()
|
||||
form.instance.conversation = conversation
|
||||
form.instance.author = request.user
|
||||
form.save()
|
||||
messages.success(request, 'Message sent!')
|
||||
if username:
|
||||
return redirect(reverse('conversation', args=[username]))
|
||||
|
@ -47,6 +46,21 @@ def conversation(request, username=None):
|
|||
})
|
||||
|
||||
|
||||
@login_required
|
||||
def talk_conversation(request, talk):
|
||||
|
||||
talk = get_object_or_404(Talk, slug=talk)
|
||||
form = MessageForm(request.POST or None)
|
||||
|
||||
if request.method == 'POST' and form.is_valid():
|
||||
form.instance.conversation = talk.conversation
|
||||
form.instance.author = request.user
|
||||
form.save()
|
||||
messages.success(request, 'Message sent!')
|
||||
|
||||
return redirect(talk.get_absolute_url())
|
||||
|
||||
|
||||
@login_required
|
||||
def correspondents(request):
|
||||
|
||||
|
|
|
@ -53,19 +53,18 @@ class Talk(PonyConfModel):
|
|||
def get_absolute_url(self):
|
||||
return reverse('show-talk', kwargs={'slug': self.slug})
|
||||
|
||||
def is_editable_by(self, user):
|
||||
def is_moderable_by(self, user):
|
||||
if user.is_superuser:
|
||||
return True
|
||||
if user == self.proposer:
|
||||
return True
|
||||
if user in self.speakers.all():
|
||||
return True
|
||||
try:
|
||||
participation = Participation.on_site.get(user=user)
|
||||
except Participation.DoesNotExists:
|
||||
return False
|
||||
return participation.orga or self.topics.filter(reviewers=participation).exists()
|
||||
|
||||
def is_editable_by(self, user):
|
||||
return user == self.proposer or user in self.speakers.all() or self.is_moderable_by(user)
|
||||
|
||||
|
||||
class Vote(PonyConfModel):
|
||||
|
||||
|
|
|
@ -34,4 +34,16 @@
|
|||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
{% if moderate_perm %}
|
||||
<h2>Moderation</h2>
|
||||
|
||||
<b>Messages:</b>
|
||||
{% for message in talk.conversation.messages.all %}
|
||||
{% include 'conversations/_message_detail.html' %}
|
||||
{% endfor %}
|
||||
|
||||
{% include 'conversations/_message_form.html' %}
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -4,6 +4,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin
|
|||
from django.contrib.auth.models import User
|
||||
from django.contrib.sites.shortcuts import get_current_site
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.views.generic import CreateView, DetailView, ListView
|
||||
|
||||
|
@ -81,7 +82,10 @@ class TalkDetail(LoginRequiredMixin, DetailView):
|
|||
queryset = Talk.on_site.all()
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
return super().get_context_data(edit_perm=self.object.is_editable_by(self.request.user), **kwargs)
|
||||
kwargs['edit_perm'] = self.object.is_editable_by(self.request.user)
|
||||
kwargs['moderate_perm'] = self.object.is_moderable_by(self.request.user)
|
||||
kwargs['form_url'] = reverse('talk-conversation', kwargs={'talk': self.object.slug})
|
||||
return super().get_context_data(**kwargs)
|
||||
|
||||
|
||||
class TopicList(LoginRequiredMixin, ListView):
|
||||
|
|
Loading…
Reference in New Issue