-
-
Notifications
You must be signed in to change notification settings - Fork 12
Comments #131
Comments #131
Changes from all commits
0da2393
1bb4516
6cc3946
228f63d
78b8f54
9660685
f3e0dde
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,7 @@ | |
.no-lead { | ||
padding-top: 10px; | ||
} | ||
|
||
.pointer { | ||
cursor: pointer; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,57 @@ | |
.accordion-inner { overflow: auto; } | ||
</style> | ||
{% endif %} | ||
|
||
{# csrf token #} | ||
<script type="text/javascript"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are these function separated from comments cookies and why don't they have a closure or $(document).ready around them? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually, I added this script in base class because we might add few more POST requests in future which need this script There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense. If you think we are going to use it, keep it here. Either way, all of this should go in a closure (I think there's no need to use $(document).ready). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done! changes are made in the next rebase |
||
// https://docs.djangoproject.com/en/1.5/ref/contrib/csrf/ | ||
(function($) { | ||
function getCookie(name) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where did you get this function from? If you can use it (license, etc.) then it would be good to link in a commenter where did you get it from. Also, maybe something like this is easier: http://www.quirksmode.org/js/cookies.html#script There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This script is mentioned in django documentation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, if you want to keep this code, add a link to that or mention it in a comment. And remove the // using jQuery comments because it's not using jQuery at all. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually I didn't even write the comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know, I saw it. It's still wrong, though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :) okay I just wasn't bother about it.. will remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added the source url |
||
var cookieValue = null; | ||
if (document.cookie && document.cookie != '') { | ||
var cookies = document.cookie.split(';'); | ||
for (var i = 0; i < cookies.length; i++) { | ||
var cookie = jQuery.trim(cookies[i]); | ||
// Does this cookie string begin with the name we want? | ||
if (cookie.substring(0, name.length + 1) == (name + '=')) { | ||
cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); | ||
break; | ||
} | ||
} | ||
} | ||
return cookieValue; | ||
} | ||
var csrftoken = getCookie('csrftoken'); | ||
|
||
function csrfSafeMethod(method) { | ||
// these HTTP methods do not require CSRF protection | ||
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method)); | ||
} | ||
function sameOrigin(url) { | ||
// test that a given url is a same-origin URL | ||
// url could be relative or scheme relative or absolute | ||
var host = document.location.host; // host + port | ||
var protocol = document.location.protocol; | ||
var sr_origin = '//' + host; | ||
var origin = protocol + sr_origin; | ||
// Allow absolute or scheme relative URLs to same origin | ||
return (url == origin || url.slice(0, origin.length + 1) == origin + '/') || | ||
(url == sr_origin || url.slice(0, sr_origin.length + 1) == sr_origin + '/') || | ||
// or any other URL that isn't scheme relative or absolute i.e relative. | ||
!(/^(\/\/|http:|https:).*/.test(url)); | ||
} | ||
$.ajaxSetup({ | ||
beforeSend: function(xhr, settings) { | ||
if (!csrfSafeMethod(settings.type) && sameOrigin(settings.url)) { | ||
// Send the token to same-origin, relative URLs only. | ||
// Send the token only if the method warrants CSRF protection | ||
// Using the CSRFToken value acquired earlier | ||
xhr.setRequestHeader("X-CSRFToken", csrftoken); | ||
} | ||
} | ||
}); | ||
})(window.jQuery); | ||
</script> | ||
|
||
{{ANALYTICS_SNIPPET|safe}} | ||
</head> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<p><small>We support reStructured Text. Please refer to <a href="{% url spc-markup-help %}">markup</a> for complete details</small></p> | ||
|
||
<ul class="unstyled"> | ||
<li>*Text in italics*</li> | ||
<li>**Bold text**</li> | ||
<li>Math expression \(z = x^2 + y^2\) as <td><tt>\( </tt><tt>z = x^2 + y^2</tt><tt> \)</tt></td></li> | ||
</ul> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ Sphinx | |
Pygments | ||
Pillow | ||
Mercurial | ||
simplejson |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from scipy_central.comments import forms, models | ||
|
||
def get_form(): | ||
""" | ||
Custom comments forms | ||
""" | ||
return forms.SpcCommentForm | ||
|
||
def get_model(): | ||
""" | ||
Custom comments model | ||
""" | ||
return models.SpcComment |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from django.utils.translation import ugettext_lazy as _ | ||
from django.contrib.comments.models import CommentFlag | ||
from django.contrib.comments.admin import CommentsAdmin | ||
from django.contrib import admin | ||
|
||
from scipy_central.comments.models import SpcComment | ||
|
||
class SpcCommentAdmin(CommentsAdmin): | ||
""" | ||
Custom admin interface for comments | ||
defined on the top of built-in admin interface | ||
""" | ||
list_display = CommentsAdmin.list_display | ||
fieldsets = ( | ||
(None, | ||
{'fields': ('content_type', 'object_pk', 'site')} | ||
), | ||
(_('Content'), | ||
{'fields': ('user', 'user_name', 'user_email', 'user_url', 'comment', 'rest_comment')} | ||
), | ||
(_('Metadata'), | ||
{'fields': ('submit_date', 'ip_address', 'is_public', 'is_removed')} | ||
), | ||
) | ||
|
||
class SpcCommentFlagAdmin(admin.ModelAdmin): | ||
""" | ||
Admin interface for comment flags | ||
""" | ||
list_display = ('flag', 'user', 'comment', 'flag_date') | ||
search_fields = ['user__username', 'comment__user__username', 'flag_date'] | ||
list_filter = ['flag_date'] | ||
ordering = ['-flag_date'] | ||
|
||
admin.site.register(SpcComment, SpcCommentAdmin) | ||
admin.site.register(CommentFlag, SpcCommentFlagAdmin) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from django import forms | ||
from django.contrib.comments.forms import CommentSecurityForm, CommentForm, COMMENT_MAX_LENGTH | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
from scipy_central.rest_comments.views import compile_rest_to_html | ||
from scipy_central.comments.models import SpcComment | ||
|
||
class SpcCommentForm(CommentForm): | ||
# we want only comment field to be shown on the page | ||
name = forms.CharField(label=_("Name"), max_length=50, widget=forms.HiddenInput()) | ||
email = forms.EmailField(label=_("Email address"), widget=forms.HiddenInput()) | ||
url = forms.URLField(label=("URL"), required=False, widget=forms.HiddenInput()) | ||
|
||
def get_comment_model(self): | ||
return SpcComment | ||
|
||
def get_comment_create_data(self): | ||
data = super(SpcCommentForm, self).get_comment_create_data() | ||
rest_comment = compile_rest_to_html(data['comment']) | ||
data['rest_comment'] = rest_comment | ||
return data | ||
|
||
class SpcCommentEditForm(CommentSecurityForm): | ||
honeypot = forms.CharField(required=False, | ||
label=_('If you enter anything in this field'\ | ||
'your comment will be treated as spam'), | ||
widget=forms.HiddenInput()) | ||
edit_comment = forms.CharField(label=_('Comment'), widget=forms.Textarea, | ||
max_length=COMMENT_MAX_LENGTH) | ||
|
||
def clean_honeypot(self): | ||
value = self.cleaned_data['honeypot'] | ||
if value: | ||
raise forms.ValidationError(self.fields['honeypot'].label) | ||
return value |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from django.db import models | ||
from django.contrib.comments.models import Comment | ||
|
||
from django.utils.translation import ugettext_lazy as _ | ||
from django.conf import settings | ||
|
||
COMMENT_MAX_LENGTH = getattr(settings, 'COMMENT_MAX_LENGTH', 3000) | ||
|
||
class SpcComment(Comment): | ||
""" | ||
Custom model for comments | ||
`rest_comment` stores compiled ReST comments | ||
""" | ||
rest_comment = models.TextField(_('rest_comment'), | ||
max_length=COMMENT_MAX_LENGTH, | ||
null = True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears twice on this file... It' also on https://github.com/scipy/SciPyCentral/pull/131/files#L0R17
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops! I think there is a problem with
import
statements in less. I should then be usingimport-once
instead.. Since anyway, I am changing it, should I delete css files from repo, and ignore it from repo further? (I mean in comments branch)