Commit 4918dc4a authored by stef's avatar stef
Browse files

[enh] better commenting function, admin and comment moderation

parent 54357924
from django.db import models from django.db import models
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.contrib.comments.moderation import CommentModerator, moderator
COUNTRIES = ( COUNTRIES = (
('BE', _('Belgium')), ('BE', _('Belgium')),
...@@ -71,3 +72,12 @@ class Comment(models.Model): ...@@ -71,3 +72,12 @@ class Comment(models.Model):
class Attachment(models.Model): class Attachment(models.Model):
storage = models.FileField(upload_to='static') storage = models.FileField(upload_to='static')
comment = models.ForeignKey(Comment) comment = models.ForeignKey(Comment)
class ViolationModerator(CommentModerator):
email_notification = True
moderate_after = 0
def moderate(self, comment, content_object, request):
return True
if Violation not in moderator._registry:
moderator.register(Violation, ViolationModerator)
...@@ -9,16 +9,17 @@ li { list-style: none; } ...@@ -9,16 +9,17 @@ li { list-style: none; }
.fieldWrapper label { width: 200px; display: inline-block; } .fieldWrapper label { width: 200px; display: inline-block; }
.help_text { font-size: 0.7em; left: 30px; width: 20%; position: absolute; } .help_text { font-size: 0.7em; left: 30px; width: 20%; position: absolute; }
.attachments { float: right; margin-top: 0.4em; display: block; clear: both; } .attachments { float: right; margin-top: 0.4em; display: block; clear: both; }
.comment-node { margin: 1em; padding-bottom: 0.4em; border-bottom: 1px solid black; width: 500px;} .report-node { margin: 1em; padding-bottom: 0.4em; border-bottom: 1px solid black; width: 500px;}
.comment { margin: 1em; } .report { margin: 1em; }
.atttachsg { margin: 1em; } .atttachsg { margin: 1em; }
#addForm { margin: auto; width: 50%; padding 4em; } #addForm { margin: auto; width: 50%; padding 4em; }
#add_attach { cursor: pointer; } #add_attach { cursor: pointer; }
#show_optionals { text-decoration: underline; color: blue; cursor: pointer; clear: both; } #show_optionals { text-decoration: underline; color: blue; cursor: pointer; clear: both; }
#optional { clear: both; } #optional { clear: both; }
#report dt { display: inline-block; width: 14em; }
#report dd { display: inline; }
#auth { float: right; clear: both; }
table.listing, .pagination { width: 90%; margin: auto; } table.listing, .pagination { width: 90%; margin: auto; }
table.listing thead td { font-weight: bold; border-bottom: 1px solid black; } table.listing thead td { font-weight: bold; border-bottom: 1px solid black; }
dt { display: inline-block; width: 14em; }
dd { display: inline; }
...@@ -11,7 +11,7 @@ MEDIA_PATH = BASE_PATH+'/media' ...@@ -11,7 +11,7 @@ MEDIA_PATH = BASE_PATH+'/media'
ROOT_URL = '' ROOT_URL = ''
ADMINS = ( ADMINS = (
# ('stef', 'stef@ctrlc.hu'), ('stef', 'stef@ctrlc.hu'),
) )
MANAGERS = ADMINS MANAGERS = ADMINS
...@@ -128,13 +128,14 @@ INSTALLED_APPS = ( ...@@ -128,13 +128,14 @@ INSTALLED_APPS = (
'django.contrib.sites', 'django.contrib.sites',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'django.contrib.comments',
'tinymce', 'tinymce',
'registration', 'registration',
'bt', 'bt',
'babeldjango', 'babeldjango',
'captcha', 'captcha',
# Uncomment the next line to enable the admin: # Uncomment the next line to enable the admin:
# 'django.contrib.admin', 'django.contrib.admin',
# Uncomment the next line to enable admin documentation: # Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs', # 'django.contrib.admindocs',
) )
......
{%load bt%}
A comment has been posted on {{ content_object }}.
The comment reads as follows:
{{ comment }}
Approve: {%root_url%}/comments/approve/{{ comment.id }}/
Delete: {%root_url%}/comments/delete/{{ comment.id }}/
...@@ -2,16 +2,46 @@ ...@@ -2,16 +2,46 @@
{% load bt %} {% load bt %}
{% load i18n %} {% load i18n %}
{% load babel %} {% load babel %}
{% load comments %}
{% block styles %} {% block styles %}
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
<script type="text/javascript" src="{%media_url%}/js/jquery.1.4.2.min.js"></script>
<script type="text/javascript" charset="utf-8">
function bindPostCommentHandler() {
$('#comment_form form input.submit-preview').remove();
$('#comment_form form').submit(function() {
var postdata=$('#comment_form form').serialize()+'&csrftoken={{csrf_token}}';
$.ajax({
type: "POST",
data: postdata,
url: "{% comment_form_target %}",
cache: false,
dataType: "html",
success: function(html, textStatus) {
$('#comment_form form').replaceWith(html);
bindPostCommentHandler();
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
$('#comment_form form').replaceWith('Your comment was unable to be posted at this time. We apologise for the inconvenience.');
}
});
return false;
});
}
$(document).ready(function() {
bindPostCommentHandler();
});
</script>
{% endblock %} {% endblock %}
{%block content%} {%block content%}
<ul> <ul id="report">
<li><dl><dt>Operator</dt><dd>{{v.operator}} ({{v.country}})</dd></dl></li> <li><dl><dt>Operator</dt><dd>{{v.operator}} ({{v.country}})</dd></dl></li>
<li><dl><dt>Contract</dt><dd>{{v.contract}}</dd></dl></li> <li><dl><dt>Contract</dt><dd>{{v.contract}}</dd></dl></li>
{%if v.resource%}<li><dl><dt>Resource</dt><dd>{{v.resource}}</dd></dl></li>{%endif%} {%if v.resource%}<li><dl><dt>Resource</dt><dd>{{v.resource}}</dd></dl></li>{%endif%}
{%if v.resource_name%}<li><dl><dt>Resource name</dt><dd>{{v.resource_name}}</dd></dl></li>{%endif%}
{%if v.type%}<li><dl><dt>Type</dt><dd>{{v.type}}</dd></dl></li>{%endif%} {%if v.type%}<li><dl><dt>Type</dt><dd>{{v.type}}</dd></dl></li>{%endif%}
{%if v.media%}<li><dl><dt>Media</dt><dd>{{v.media}}</dd></dl></li>{%endif%} {%if v.media%}<li><dl><dt>Media</dt><dd>{{v.media}}</dd></dl></li>{%endif%}
{%if v.temporary%}<li><dl><dt>Temporary restriction</dt><dd>{{v.temporary}}</dd></dl></li>{%endif%} {%if v.temporary%}<li><dl><dt>Temporary restriction</dt><dd>{{v.temporary}}</dd></dl></li>{%endif%}
...@@ -19,12 +49,12 @@ ...@@ -19,12 +49,12 @@
{%if v.contract_excerpt%}<li><dl><dt>Contract excerpt</dt><dd>{{v.contract_excerpt|safe}}</dd></dl></li>{%endif%} {%if v.contract_excerpt%}<li><dl><dt>Contract excerpt</dt><dd>{{v.contract_excerpt|safe}}</dd></dl></li>{%endif%}
{%if v.loophole%}<li><dl><dt>Loophole offering</dt><dd>{{v.loophole}}</dd></dl></li>{%endif%} {%if v.loophole%}<li><dl><dt>Loophole offering</dt><dd>{{v.loophole}}</dd></dl></li>{%endif%}
{%if v.comment_set.all%} {%if v.comment_set.all%}
<div id="comments"> <li id="description">
Comments <h3>{%trans "Description" %}</h3>
{%for c in v.comment_set.all%} {%for c in v.comment_set.all%}
<div class="comment-node"> <div class="description-node">
<span class="commenter">{%if c.submitter_nick%}{{c.submitter_nick}}{%else%}{{c.submitter_email}}{%endif%}</span> - <span class="comment_date">{{c.timestamp|datetimefmt:"short" }}</span> <span class="submitter">{%if c.submitter_name%}{{c.submitter_name}}{%else%}{{c.submitter_email}}{%endif%}</span> - <span class="comment_date">{{c.timestamp|datetimefmt:"short" }}</span>
<div class="comment">{{c.comment|safe}}</div> <div class="description">{{c.comment|safe}}</div>
{%if c.attachment_set.all%} {%if c.attachment_set.all%}
<div class="attachs"> <div class="attachs">
Attachments Attachments
...@@ -35,7 +65,16 @@ ...@@ -35,7 +65,16 @@
</ul> </ul>
</div> </div>
{%endif%} {%endif%}
{%endfor%}
</div> </div>
{%endfor%}
</li>
</ul>
{%endif%} {%endif%}
<h3>Comments</h3>
{% render_comment_list for v %}
<h3>Comment</h3>
{% get_comment_form for v as form %}
<div id="comment_form">
{% render_comment_form for v %}
</div>
{%endblock%} {%endblock%}
from django.conf.urls.defaults import patterns, include, url from django.conf.urls.defaults import patterns, include, url
from django.conf import settings from django.conf import settings
from django.contrib import admin
from bt import views as bt from bt import views as bt
# Uncomment the next two lines to enable the admin: admin.autodiscover()
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = patterns('', urlpatterns = patterns('',
(r'^$', bt.index), (r'^$', bt.index),
(r'^accounts/logout$', 'django.contrib.auth.views.logout', {'next_page' : '/'}),
(r'^accounts/', include('registration.urls')),
url(r'^captcha/', include('captcha.urls')),
(r'^ajax/(?P<country>[^/]*)(/(?P<operator>[^/]*))?$', bt.ajax), (r'^ajax/(?P<country>[^/]*)(/(?P<operator>[^/]*))?$', bt.ajax),
(r'^add/$', bt.add), (r'^add/$', bt.add),
(r'^view/(?P<id>[0-9]*)$', bt.view), (r'^view/(?P<id>[0-9]*)$', bt.view),
(r'^accounts/logout$', 'django.contrib.auth.views.logout', {'next_page' : '/'}),
(r'^accounts/', include('registration.urls')),
(r'^comments/', include('django.contrib.comments.urls')),
url(r'^captcha/', include('captcha.urls')),
url(r'^admin/', include(admin.site.urls)),
) )
if settings.DEV_SERVER: if settings.DEV_SERVER:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment