Finished renaming comments app to document_comments

This commit is contained in:
Roberto Rosario
2011-05-01 16:13:34 -04:00
parent e69a85efad
commit 5349b29965
11 changed files with 2 additions and 2 deletions

View File

@@ -0,0 +1,40 @@
from django.utils.translation import ugettext_lazy as _
from navigation.api import register_links, \
register_model_list_columns
from permissions.api import register_permissions
from django.contrib.comments.models import Comment
from documents.models import Document
PERMISSION_COMMENT_CREATE = 'comment_create'
PERMISSION_COMMENT_DELETE = 'comment_delete'
PERMISSION_COMMENT_EDIT = 'comment_edit'
register_permissions('comments', [
{'name': PERMISSION_COMMENT_CREATE, 'label': _(u'Create new comments')},
{'name': PERMISSION_COMMENT_DELETE, 'label': _(u'Delete comments')},
{'name': PERMISSION_COMMENT_EDIT, 'label': _(u'Edit comments')},
])
comment_delete = {'text': _('delete'), 'view': 'comment_delete', 'args': 'object.id', 'famfam': 'comment_delete', 'permissions': {'namespace': 'comments', 'permissions': [PERMISSION_COMMENT_DELETE]}}
comment_multiple_delete = {'text': _('delete'), 'view': 'comment_multiple_delete', 'args': 'object.id', 'famfam': 'comments_delete', 'permissions': {'namespace': 'comments', 'permissions': [PERMISSION_COMMENT_DELETE]}}
comment_add = {'text': _('add comment'), 'view': 'comment_add', 'args': 'document.id', 'famfam': 'comment_add', 'permissions': {'namespace': 'comments', 'permissions': [PERMISSION_COMMENT_CREATE]}}
register_model_list_columns(Comment, [
{
'name': _(u'date'),
'attribute': 'submit_date'
},
{
'name': _(u'user'),
'attribute': lambda x: x.user.get_full_name() if x.user.get_full_name() else x.user
},
{
'name': _(u'comment'),
'attribute': 'comment'
}
])
register_links(Document, [comment_add])

View File

@@ -0,0 +1,11 @@
from django import forms
from django.contrib.comments.models import Comment
class CommentForm(forms.ModelForm):
"""
A standard model form to allow users to post a comment
"""
class Meta:
model = Comment
fields = ('comment',)

Binary file not shown.

View File

@@ -0,0 +1,89 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2011-05-01 04:21-0400\n"
"PO-Revision-Date: 2011-05-01 04:25\n"
"Last-Translator: Roberto Rosario <rosario_r@jp.pr.gov>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: \n"
"X-Translated-Using: django-rosetta 0.5.6\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: __init__.py:16
msgid "Create new comments"
msgstr "Crear nuevos comentarios"
#: __init__.py:17
msgid "Delete comments"
msgstr "Eliminar comentarios"
#: __init__.py:18
msgid "Edit comments"
msgstr "Editar los comentarios"
#: __init__.py:21 __init__.py:22
msgid "delete"
msgstr "eliminar"
#: __init__.py:23
msgid "add comment"
msgstr "añadir comentario"
#: __init__.py:27
msgid "date"
msgstr "fecha"
#: __init__.py:31
msgid "user"
msgstr "usuario"
#: __init__.py:35 views.py:45
msgid "comment"
msgstr "comentario"
#: utils.py:17
msgid "comments"
msgstr "comentarios"
#: views.py:26
msgid "Must provide at least one comment."
msgstr "Debe proveer al menos un comentario."
#: views.py:36
#, python-format
msgid "Comment \"%s\" deleted successfully."
msgstr "Comentario \"%s\" eliminado exitosamente."
#: views.py:38
#, python-format
msgid "Error deleting comment \"%(comment)s\": %(error)s"
msgstr "Error al eliminar el comentario \" %(comment)s\": %(error)s "
#: views.py:52
#, python-format
msgid "Are you sure you wish to delete the comment: %s?"
msgstr "¿Está seguro que desea eliminar el comentario:% s?"
#: views.py:54
#, python-format
msgid "Are you sure you wish to delete the comments: %s?"
msgstr "¿Está seguro que desea eliminar los comentarios:% s?"
#: views.py:84
msgid "Comment added successfully."
msgstr "Comentario añadido exitosamente."
#: views.py:91
#, python-format
msgid "Add comment to document: %s"
msgstr "Añadir comentario al documento: %s"

View File

@@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

View File

@@ -0,0 +1,23 @@
"""
This file demonstrates two different styles of tests (one doctest and one
unittest). These will both pass when you run "manage.py test".
Replace these with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.failUnlessEqual(1 + 1, 2)
__test__ = {"doctest": """
Another way to test that 1 + 1 is equal to 2.
>>> 1 + 1 == 2
True
"""}

View File

@@ -0,0 +1,7 @@
from django.conf.urls.defaults import patterns, url
urlpatterns = patterns('document_comments.views',
url(r'^(?P<comment_id>\d+)/delete/$', 'comment_delete', (), 'comment_delete'),
url(r'^multiple/delete/$', 'comment_multiple_delete', (), 'comment_multiple_delete'),
url(r'^add_to_document(?P<document_id>\d+)/$', 'comment_add', (), 'comment_add'),
)

View File

@@ -0,0 +1,22 @@
from django.utils.translation import ugettext_lazy as _
from django.contrib.comments.models import Comment
from document_comments import comment_delete
def get_comments_subtemplate(obj):
"""
Return all the settings to render a subtemplate containing an
object's comments
"""
return {
'name': 'generic_list_subtemplate.html',
'context': {
'title': _(u'comments'),
'object_list': Comment.objects.for_model(obj).order_by('-submit_date'),
'hide_link': True,
'hide_object': True,
'navigation_object_links': [comment_delete],
'scrollable_content': True,
'scrollable_content_height': '200px',
}
}

View File

@@ -0,0 +1,93 @@
from django.shortcuts import render_to_response, get_object_or_404
from django.utils.translation import ugettext_lazy as _
from django.contrib.comments.models import Comment
from django.http import HttpResponseRedirect
from django.template import RequestContext
from django.contrib import messages
from django.contrib.contenttypes.models import ContentType
from django.contrib.sites.models import Site
from permissions.api import check_permissions
from documents.models import Document
from document_comments import PERMISSION_COMMENT_DELETE, PERMISSION_COMMENT_CREATE
from document_comments.forms import CommentForm
def comment_delete(request, comment_id=None, comment_id_list=None):
check_permissions(request.user, 'comments', [PERMISSION_COMMENT_DELETE])
post_action_redirect = None
if comment_id:
comments = [get_object_or_404(Comment, pk=comment_id)]
elif comment_id_list:
comments = [get_object_or_404(Comment, pk=comment_id) for comment_id in comment_id_list.split(',')]
else:
messages.error(request, _(u'Must provide at least one comment.'))
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', '/')))
next = request.POST.get('next', request.GET.get('next', post_action_redirect if post_action_redirect else request.META.get('HTTP_REFERER', '/')))
if request.method == 'POST':
for comment in comments:
try:
comment.delete()
messages.success(request, _(u'Comment "%s" deleted successfully.') % comment)
except Exception, e:
messages.error(request, _(u'Error deleting comment "%(comment)s": %(error)s') % {
'comment': comment, 'error': e
})
return HttpResponseRedirect(next)
context = {
'object_name': _(u'comment'),
'delete_view': True,
'previous': previous,
'next': next,
}
if len(comments) == 1:
context['object'] = comments[0]
context['title'] = _(u'Are you sure you wish to delete the comment: %s?') % ', '.join([unicode(d) for d in comments])
elif len(comments) > 1:
context['title'] = _(u'Are you sure you wish to delete the comments: %s?') % ', '.join([unicode(d) for d in comments])
return render_to_response('generic_confirm.html', context,
context_instance=RequestContext(request))
def comment_multiple_delete(request):
return comment_delete(
request, comment_id_list=request.GET.get('id_list', [])
)
def comment_add(request, document_id):
check_permissions(request.user, 'comments', [PERMISSION_COMMENT_CREATE])
document = get_object_or_404(Document, pk=document_id)
post_action_redirect = None
next = request.POST.get('next', request.GET.get('next', post_action_redirect if post_action_redirect else request.META.get('HTTP_REFERER', '/')))
if request.method == 'POST':
form = CommentForm(request.POST)
if form.is_valid():
comment = form.save(commit=False)
comment.user = request.user
comment.content_type = ContentType.objects.get_for_model(document)
comment.object_pk = document.pk
comment.site = Site.objects.get_current()
comment.save()
messages.success(request, _(u'Comment added successfully.'))
return HttpResponseRedirect(next)
else:
form = CommentForm()
return render_to_response('generic_form.html', {
'form': form,
'title': _(u'Add comment to document: %s') % document,
'next': next,
}, context_instance=RequestContext(request))