Skip to content
This repository has been archived by the owner on Jun 22, 2021. It is now read-only.

Commit

Permalink
Anonymous comment bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpethick committed Sep 4, 2011
1 parent adf4459 commit 8e324a7
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 4 deletions.
9 changes: 8 additions & 1 deletion book/models.py
Expand Up @@ -47,7 +47,14 @@ def get_score(self):
def get_votes_on_chapter(self):
chapter_type = ContentType.objects.get_for_model(self)
return Vote.objects.filter(object_id=self.pk, content_type=chapter_type)


def get_number(self):
chapters = Chapter.objects.filter(visible=True).extra(select={'r': '((100/%s*rating_score/(rating_votes+%s))+100)/2' % (Chapter.rating.range, Chapter.rating.weight)}).order_by('-r')
i=0
for chapter in chapters:
i+=1
if self==chapter:
return i
@models.permalink
def get_absolute_url(self):
return ('chapter', [str(self.id)])
Expand Down
1 change: 1 addition & 0 deletions settings.py
Expand Up @@ -14,6 +14,7 @@

if DEVELOPMENT_MODE:
DEBUG = True
TEMPLATE_DEBUG = True
MEDIA_URL = '/m/uploads/'
STATIC_URL = '/m/'
EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend'
Expand Down
2 changes: 1 addition & 1 deletion simplewiki/models.py
Expand Up @@ -34,6 +34,7 @@ def html2list(x, b=0):
else: cur += c
output.append(cur)
return filter(lambda x: x is not '', output)

class ShouldHaveExactlyOneRootSlug(Exception):
pass

Expand Down Expand Up @@ -311,7 +312,6 @@ def get_diff(self):
s = difflib.SequenceMatcher(None, a, b)
for e in s.get_opcodes():
if e[0] == "replace":

out.append('<del>'+''.join(a[e[1]:e[2]]) + '</del><ins>'+''.join(b[e[3]:e[4]])+"</ins>")
elif e[0] == "delete":
out.append('<del class="diff">'+ ''.join(a[e[1]:e[2]]) + "</del>")
Expand Down
1 change: 0 additions & 1 deletion templates/book/chapter.html
Expand Up @@ -14,7 +14,6 @@
<div class="chapter clearfix" id="chapter">
<div id="chapter_header">
<h1 id="chapter_title" class="float_left">{{ chapter.title }}</h1>

<div id="chapter_info">
<div id="rating_average"class="float_left">
{{ chapter.rating.votes }} {% ifequal chapter.rating.votes 1 %}vote{%else%}votes{%endifequal%}<br />
Expand Down
1 change: 1 addition & 0 deletions templates/comments/base.html
@@ -0,0 +1 @@
{% extends 'base.html' %}
8 changes: 7 additions & 1 deletion templates/comments/form.html
@@ -1,4 +1,9 @@
{% extends 'base.html' %}
{% load comments i18n %}

{% block title %}Post a comment{% endblock %}

{% block content %}
{% if user.is_authenticated %}
<form action="{% comment_form_target %}" method="post">
{% csrf_token %}
Expand All @@ -21,4 +26,5 @@
</form>
{% else %}
Log in or register to comment!
{% endif %}
{% endif %}
{% endblock %}
42 changes: 42 additions & 0 deletions templates/comments/preview.html
@@ -0,0 +1,42 @@
{% extends "comments/base.html" %}
{% load i18n %}

{% block title %}{% trans "Preview your comment" %}{% endblock %}

{% block content %}
{% load comments %}
{% if user.is_authenticated %}
<form action="{% comment_form_target %}" method="post">{% csrf_token %}
{% if next %}<div><input type="hidden" name="next" value="{{ next }}" /></div>{% endif %}
{% if form.errors %}
<h1>{% blocktrans count form.errors|length as counter %}Please correct the error below{% plural %}Please correct the errors below{% endblocktrans %}</h1>
{% else %}
<h1>{% trans "Preview your comment" %}</h1>
<blockquote>{{ comment|linebreaks }}</blockquote>
<p>
{% trans "and" %} <input type="submit" name="submit" class="submit-post" value="{% trans "Post your comment" %}" id="submit" /> {% trans "or make changes" %}:
</p>
{% endif %}
{% for field in form %}
{% if field.is_hidden %}
<div>{{ field }}</div>
{% else %}
{% if field.errors %}{{ field.errors }}{% endif %}
<p
{% if field.errors %} class="error"{% endif %}
{% ifequal field.name "honeypot" %} style="display:none;"{% endifequal %}>
{{ field.label_tag }} {{ field }}
</p>
{% endif %}
{% endfor %}
<p class="submit">
<input type="submit" name="submit" class="submit-post" value="{% trans "Post" %}" />
<input type="submit" name="preview" class="submit-preview" value="{% trans "Preview" %}" />
</p>
</form>
{% else %}
<a href="/accounts/login/">Log in</a> or <a href="/accounts/register/">register</a> to comment!<br /><br />
Your comment will not be posted so please copy it from below:<br />
{{ form.comment }}
{% endif %}
{% endblock %}
10 changes: 10 additions & 0 deletions templates/email/weekly_newsletter.html
@@ -0,0 +1,10 @@
{% include "email/email_top.html" %}
Hi <a href="http://winning-without-losing.com/account">{{ user }}</a>! Here is an update of what happened this week on WWL!<br />

<!-- <h3>Status</h3> -->

<h3>Feedback and ratings on your chapters:</h3>
<i>The feedback your chapters receive will determine if they’ll be selected in the final version of the book!</i><br />
<h4>{{ chapter.title }}</h4>
Your chapter has obtained an average rating of {{ chapter.rating.get_rating|floatformat }} out of 5 and is now number {{ chapter.get_number }} out of {{ chapters.count }} chapters!
{% include "email/email_bottom.html" %}

0 comments on commit 8e324a7

Please sign in to comment.