diff options
author | luxagraf <sng@luxagraf.net> | 2015-09-07 17:22:24 +0000 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2015-09-07 17:22:24 +0000 |
commit | 6cf2f5b09f3753351abc291cc70c6ae7e1126078 (patch) | |
tree | ebd14d3fd9b425eb8d8a88a0cae4034dddf28061 /app/lib/django_comments/__init__.py | |
parent | 6ff5d738b9442c92fa6cc36477a3e099eb516f7d (diff) |
added comments to my apps, fixed uwsgi config, fixed bug in photo template jquery url, added piwik stats code
Diffstat (limited to 'app/lib/django_comments/__init__.py')
-rw-r--r-- | app/lib/django_comments/__init__.py | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/app/lib/django_comments/__init__.py b/app/lib/django_comments/__init__.py new file mode 100644 index 0000000..a78b21a --- /dev/null +++ b/app/lib/django_comments/__init__.py @@ -0,0 +1,92 @@ +from django.conf import settings +from django.core import urlresolvers +from django.core.exceptions import ImproperlyConfigured +from django.utils.importlib import import_module + +from django_comments.models import Comment +from django_comments.forms import CommentForm + +DEFAULT_COMMENTS_APP = 'django_comments' + +def get_comment_app(): + """ + Get the comment app (i.e. "django_comments") as defined in the settings + """ + # Make sure the app's in INSTALLED_APPS + comments_app = get_comment_app_name() + if comments_app not in settings.INSTALLED_APPS: + raise ImproperlyConfigured("The COMMENTS_APP (%r) "\ + "must be in INSTALLED_APPS" % settings.COMMENTS_APP) + + # Try to import the package + try: + package = import_module(comments_app) + except ImportError as e: + raise ImproperlyConfigured("The COMMENTS_APP setting refers to "\ + "a non-existing package. (%s)" % e) + + return package + +def get_comment_app_name(): + """ + Returns the name of the comment app (either the setting value, if it + exists, or the default). + """ + return getattr(settings, 'COMMENTS_APP', DEFAULT_COMMENTS_APP) + +def get_model(): + """ + Returns the comment model class. + """ + if get_comment_app_name() != DEFAULT_COMMENTS_APP and hasattr(get_comment_app(), "get_model"): + return get_comment_app().get_model() + else: + return Comment + +def get_form(): + """ + Returns the comment ModelForm class. + """ + if get_comment_app_name() != DEFAULT_COMMENTS_APP and hasattr(get_comment_app(), "get_form"): + return get_comment_app().get_form() + else: + return CommentForm + +def get_form_target(): + """ + Returns the target URL for the comment form submission view. + """ + if get_comment_app_name() != DEFAULT_COMMENTS_APP and hasattr(get_comment_app(), "get_form_target"): + return get_comment_app().get_form_target() + else: + return urlresolvers.reverse("django_comments.views.comments.post_comment") + +def get_flag_url(comment): + """ + Get the URL for the "flag this comment" view. + """ + if get_comment_app_name() != DEFAULT_COMMENTS_APP and hasattr(get_comment_app(), "get_flag_url"): + return get_comment_app().get_flag_url(comment) + else: + return urlresolvers.reverse("django_comments.views.moderation.flag", + args=(comment.id,)) + +def get_delete_url(comment): + """ + Get the URL for the "delete this comment" view. + """ + if get_comment_app_name() != DEFAULT_COMMENTS_APP and hasattr(get_comment_app(), "get_delete_url"): + return get_comment_app().get_delete_url(comment) + else: + return urlresolvers.reverse("django_comments.views.moderation.delete", + args=(comment.id,)) + +def get_approve_url(comment): + """ + Get the URL for the "approve this comment from moderation" view. + """ + if get_comment_app_name() != DEFAULT_COMMENTS_APP and hasattr(get_comment_app(), "get_approve_url"): + return get_comment_app().get_approve_url(comment) + else: + return urlresolvers.reverse("django_comments.views.moderation.approve", + args=(comment.id,)) |