Permalink
Browse files

style clean-ups

  • Loading branch information...
1 parent b9099b7 commit 83647d25adf2c2a6d580e2be5327eb2cb85d9a55 @brosner brosner committed Oct 8, 2010
Showing with 20 additions and 7 deletions.
  1. +3 −1 dialogos/forms.py
  2. +1 −0 dialogos/models.py
  3. +10 −1 dialogos/templatetags/dialogos_tags.py
  4. +2 −3 dialogos/tests.py
  5. +1 −0 dialogos/views.py
  6. +3 −2 runtests.py
View
@@ -6,6 +6,7 @@
class BaseCommentForm(forms.ModelForm):
+
def __init__(self, *args, **kwargs):
self.request = kwargs.pop("request", None)
self.obj = kwargs.pop("obj")
@@ -21,8 +22,8 @@ def save(self, commit=True):
return comment
-
class UnauthenticatedCommentForm(BaseCommentForm):
+
class Meta:
model = Comment
fields = [
@@ -31,6 +32,7 @@ class Meta:
class AuthenticatedCommentForm(BaseCommentForm):
+
class Meta:
model = Comment
fields = [
View
@@ -8,6 +8,7 @@
class Comment(models.Model):
+
author = models.ForeignKey(User, null=True, related_name="comments")
name = models.CharField(max_length=100)
@@ -11,6 +11,7 @@
class BaseCommentNode(template.Node):
+
@classmethod
def handle_token(cls, parser, token):
bits = token.split_contents()
@@ -25,7 +26,7 @@ def handle_token(cls, parser, token):
else:
args = "either 1 or 3 arguments"
raise template.TemplateSyntaxError("%r takes %s" % (bits[0], args))
-
+
def __init__(self, obj, varname=None):
self.obj = obj
self.varname = varname
@@ -37,7 +38,9 @@ def get_comments(self, context):
content_type=ContentType.objects.get_for_model(obj)
)
+
class CommentCountNode(BaseCommentNode):
+
requires_as_var = False
def render(self, context):
@@ -49,6 +52,7 @@ def render(self, context):
class CommentsNode(BaseCommentNode):
+
requires_as_var = True
def render(self, context):
@@ -57,6 +61,7 @@ def render(self, context):
class CommentFormNode(BaseCommentNode):
+
requires_as_var = False
def render(self, context):
@@ -71,6 +76,7 @@ def render(self, context):
class CommentTargetNode(BaseCommentNode):
+
requires_as_var = False
def render(self, context):
@@ -92,6 +98,7 @@ def comment_count(parser, token):
"""
return CommentCountNode.handle_token(parser, token)
+
@register.tag
def comments(parser, token):
"""
@@ -101,6 +108,7 @@ def comments(parser, token):
"""
return CommentsNode.handle_token(parser, token)
+
@register.tag
def comment_form(parser, token):
"""
@@ -113,6 +121,7 @@ def comment_form(parser, token):
"""
return CommentFormNode.handle_token(parser, token)
+
@register.tag
def comment_target(parser, token):
"""
View
@@ -11,15 +11,15 @@
class CommentTests(TestCase):
+
def setUp(self):
self.user = User.objects.create_user("gimli", "myaxe@dwarf.org", "gloin")
self.user2 = User.objects.create_user("aragorn", "theking@gondor.gov", "strider")
-
+
def assert_renders(self, tmpl, context, value):
tmpl = Template(tmpl)
self.assertEqual(tmpl.render(context), value)
-
def post_comment(self, obj, data):
return self.post("post_comment",
content_type_id=ContentType.objects.get_for_model(obj).pk,
@@ -46,7 +46,6 @@ def test_post_comment(self):
})
self.assertEqual(Comment.objects.count(), 1)
-
with self.login("gimli", "gloin"):
response = self.post_comment(g, data={
"comment": "I thought you were watching the hobbits?"
View
@@ -21,6 +21,7 @@ def post_comment(request, content_type_id, object_id):
form.save()
return redirect(obj)
+
@login_required
@require_POST
def delete_comment(request, comment_id):
View
@@ -17,17 +17,18 @@
]
)
+
from django.test.simple import run_tests
def runtests(*test_args):
if not test_args:
- test_args = ['dialogos']
+ test_args = ["dialogos"]
parent = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, parent)
failures = run_tests(test_args, verbosity=1, interactive=True)
sys.exit(failures)
-if __name__ == '__main__':
+if __name__ == "__main__":
runtests(*sys.argv[1:])

0 comments on commit 83647d2

Please sign in to comment.