Commits

Julian Moritz  committed 61c18a6

initial version commit

  • Participants

Comments (0)

Files changed (12)

+Development setup
+=================
+
+To create a buildout,
+
+  $ python bootstrap.py
+  $ bin/buildout
+
+Release HOWTO
+=============
+
+To make a release, 
+
+  1) Update release date/version in NEWS.txt and setup.py
+  2) Run 'python setup.py sdist'
+  3) Test the generated source distribution in dist/
+  4) Upload to PyPI: 'python setup.py sdist register upload'
+  5) Increase version in setup.py (for next release)
+
+include README.rst
+include NEWS.txt
+News
+====
+
+0.1.1
+
+*Release date: 12-Aug-2010*
+
+* Added news to the NEWS.txt.
+
+0.1
+---
+
+*Release date: 12-Aug-2010*
+
+* First untested version published.
+
+README
+======
+
+To make sure no bad hacker adds a comment with no authentication, you have to install a small app called django-contrib-comments-auth::
+
+	pip install django-contrib-comments-auth
+	
+Add it to the INSTALLED_APPS::
+
+ 	INSTALLED_APPS = (
+    # ...
+    'django.contrib.comments',
+    'commentsauth',
+	)
+	
+Add these lines to your root urls.py::
+
+	urlpatterns = patterns('',
+    # ...
+    (r'^comments/', include('commentsauth.urls'),
+    (r'^comments/', include('django.contrib.comments.urls'))
+	)
+	
+It must be *before* the django.contrib.comments.urls-directive and have the same prefix. 
+
+The template for the comment-form could look like::
+
+	{% load comments %}
+	{% if request.user.is_authenticated %}
+	<h2>Leave a comment</h2>
+	{% get_comment_form for object as form %}
+    <form action="{% comment_form_target %}" method="POST"> 
+	{{ form.comment }} 
+	{{ form.honeypot }} 
+	{{ form.content_type }} 
+	{{ form.object_pk }} 
+	{{ form.timestamp }} 
+	{{ form.security_hash }} 
+	<input type="submit" value="Add comment" id="id_submit" />
+	</form> 
+	{% else %}
+	<h1>Display login form or link to login page!</h1>
+	{% endif %}
+	
+Please make sure to have these two lines in your MIDDLEWARE_CLASSES::
+
+	MIDDLEWARE_CLASSES = (
+	# ...
+    'django.middleware.csrf.CsrfViewMiddleware',
+    'django.middleware.csrf.CsrfResponseMiddleware',
+	)
+
+	
+

File bootstrap.py

+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id: bootstrap.py 102545 2009-08-06 14:49:47Z chrisw $
+"""
+
+import os, shutil, sys, tempfile, urllib2
+from optparse import OptionParser
+
+tmpeggs = tempfile.mkdtemp()
+
+is_jython = sys.platform.startswith('java')
+
+# parsing arguments
+parser = OptionParser()
+parser.add_option("-v", "--version", dest="version",
+                          help="use a specific zc.buildout version")
+parser.add_option("-d", "--distribute",
+                   action="store_true", dest="distribute", default=True,
+                   help="Use Disribute rather than Setuptools.")
+
+options, args = parser.parse_args()
+
+if options.version is not None:
+    VERSION = '==%s' % options.version
+else:
+    VERSION = ''
+
+USE_DISTRIBUTE = options.distribute
+args = args + ['bootstrap']
+
+to_reload = False
+try:
+    import pkg_resources
+    if not hasattr(pkg_resources, '_distribute'):
+        to_reload = True
+        raise ImportError
+except ImportError:
+    ez = {}
+    if USE_DISTRIBUTE:
+        exec urllib2.urlopen('http://python-distribute.org/distribute_setup.py'
+                         ).read() in ez
+        ez['use_setuptools'](to_dir=tmpeggs, download_delay=0, no_fake=True)
+    else:
+        exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+                             ).read() in ez
+        ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+    if to_reload:
+        reload(pkg_resources)
+    else:
+        import pkg_resources
+
+if sys.platform == 'win32':
+    def quote(c):
+        if ' ' in c:
+            return '"%s"' % c # work around spawn lamosity on windows
+        else:
+            return c
+else:
+    def quote (c):
+        return c
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+ws  = pkg_resources.working_set
+
+if USE_DISTRIBUTE:
+    requirement = 'distribute'
+else:
+    requirement = 'setuptools'
+
+if is_jython:
+    import subprocess
+
+    assert subprocess.Popen([sys.executable] + ['-c', quote(cmd), '-mqNxd',
+           quote(tmpeggs), 'zc.buildout' + VERSION],
+           env=dict(os.environ,
+               PYTHONPATH=
+               ws.find(pkg_resources.Requirement.parse(requirement)).location
+               ),
+           ).wait() == 0
+
+else:
+    assert os.spawnle(
+        os.P_WAIT, sys.executable, quote (sys.executable),
+        '-c', quote (cmd), '-mqNxd', quote (tmpeggs), 'zc.buildout' + VERSION,
+        dict(os.environ,
+            PYTHONPATH=
+            ws.find(pkg_resources.Requirement.parse(requirement)).location
+            ),
+        ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout' + VERSION)
+import zc.buildout.buildout
+zc.buildout.buildout.main(args)
+shutil.rmtree(tmpeggs)

File buildout.cfg

+[buildout]
+parts = python scripts
+develop = .
+eggs = django-contrib-comments-auth
+
+[python]
+recipe = zc.recipe.egg
+interpreter = python
+eggs = ${buildout:eggs}
+
+[scripts]
+recipe = zc.recipe.egg:scripts
+eggs = ${buildout:eggs}
+from setuptools import setup, find_packages
+import sys, os
+
+here = os.path.abspath(os.path.dirname(__file__))
+README = open(os.path.join(here, 'README.rst')).read()
+NEWS = open(os.path.join(here, 'NEWS.txt')).read()
+
+
+version = '0.1.1'
+
+install_requires = [
+    # List your project dependencies here.
+    # For more details, see:
+    # http://packages.python.org/distribute/setuptools.html#declaring-dependencies
+]
+
+
+setup(name='django-contrib-comments-auth',
+    version=version,
+    description="This adds authentication to django.contrib.comments.",
+    long_description=README + '\n\n' + NEWS,
+    classifiers=[
+      # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
+    ],
+    keywords='comments django web',
+    author='Julian Moritz',
+    author_email='jumo@gmx.de',
+    url='http://www.julianmoritz.de',
+    license='BSD',
+    packages=find_packages('src'),
+    package_dir = {'': 'src'},include_package_data=True,
+    zip_safe=False,
+    install_requires=install_requires,
+    entry_points={
+        'console_scripts':
+            ['django-contrib-comments-auth=djangocontribcommentsauth:main']
+    }
+)

File src/commentsauth/__init__.py

Empty file added.

File src/commentsauth/models.py

+from django.db import models
+
+# Create your models here.

File src/commentsauth/tests.py

+"""
+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
+"""}
+

File src/commentsauth/urls.py

+from django.conf.urls.defaults import *
+from commentsauth.views import post_comment_auth
+
+urlpatterns = patterns('',
+    url(r'^post/$', post_comment_auth, name='comments-post-comment-auth') 
+)

File src/commentsauth/views.py

+# Create your views here.
+from django.contrib.auth.decorators import login_required
+from django.contrib.comments.views import post_comment
+
+@login_required
+def post_comment_auth(request):
+    return post_comment(request)