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

Comments #131

Merged
merged 7 commits into from
Aug 24, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions deploy/media/css/spc-extend.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ body {
.no-lead {
padding-top: 10px;
}
.pointer {
cursor: pointer;
}
.header {
padding-top: 15px;
padding-bottom: 15px;
Expand All @@ -26,6 +29,9 @@ body {
.no-lead {
padding-top: 10px;
}
.pointer {
cursor: pointer;
}
Copy link

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

Copy link
Member Author

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 using import-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)

.tags .btn {
border: none;
font-size: 9.5px;
Expand All @@ -51,6 +57,34 @@ body {
.spc-searchbar button {
height: 40px;
}
#spc-post-comment.tab-content {
min-height: 305px;
}
#preview {
height: 209px;
margin-bottom: 19px;
}
.show-preview {
border-radius: 4px;
border-style: dashed;
border-width: 1px;
border-color: #999999;
height: 198px;
}
.preview-image img {
display: block;
margin-left: auto;
margin-right: auto;
padding-top: 50px;
}
#spc-comment-edit-modal .show-preview {
padding: 5px;
padding-bottom: 0px;
height: 193px;
}
#spc-comment-edit-modal .tab-content {
min-height: 228px;
}
.spc-rightsidebar {
color: #555555;
padding: 2px 10px;
Expand Down
70 changes: 55 additions & 15 deletions deploy/media/less/spc-content.less
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,78 @@

//tags -- need to design
.tags .btn {
border: none;
font-size: 9.5px;
font-weight: bold;
border: none;
font-size: 9.5px;
font-weight: bold;
}

// used in item.html
.accordion-group {
border: none;
border: none;
}
.accordion-heading {
border-bottom: 1px solid #e5e5e5;
border-bottom: 1px solid #e5e5e5;
}

// used in submission page
// used along with .alert to override its default features
.help-text {
background-color: @white;
border-color: @white;
color: rgb(51,51,51);
font-family: @monoFontFamily;
background-color: @white;
border-color: @white;
color: rgb(51,51,51);
font-family: @monoFontFamily;
}

// remove margins in bootstrap tables
.no-margin-table {
td, th {
border-top: none;
}
td, th {
border-top: none;
}
}

// increase searchbar width
.spc-searchbar {
input, button {
height: 40px;
}
input, button {
height: 40px;
}
}

// comments

#spc-post-comment {
&.tab-content {
min-height: 305px;
}
}

#preview {
height: 209px;
margin-bottom: 19px;
}

.show-preview {
border-radius: 4px;
border-style: dashed;
border-width: 1px;
border-color: #999999;
height: 198px;
}

.preview-image img {
display: block;
margin-left: auto;
margin-right: auto;
padding-top: 50px;
}

#spc-comment-edit-modal {
.show-preview {
padding: 5px;
padding-bottom: 0px;
height: 193px;
}

.tab-content {
min-height: 228px;
}
}
4 changes: 4 additions & 0 deletions deploy/media/less/spc-utils.less
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@
.no-lead {
padding-top: 10px;
}

.pointer {
cursor: pointer;
}
Binary file added deploy/media/send-email-icon-tiny.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions deploy/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# ('Your Name', 'your_email@example.com'),
)

SCIPY_CENTRAL_TEAM = 'scipy-dev@scipy.org'

MANAGERS = ADMINS
DATABASES = {
'default': {
Expand Down Expand Up @@ -137,6 +139,10 @@
# Humanize some data entries
'django.contrib.humanize',

# place above built-in to override templates
'scipy_central.comments',
'django.contrib.comments',

# 3rd party apps:
'haystack',
'registration',
Expand All @@ -154,6 +160,9 @@
'scipy_central.feeds',
)

# Custom comments App
COMMENTS_APP = 'scipy_central.comments'

# Authentication related:
AUTH_PROFILE_MODULE = 'person.UserProfile'
# Link the user is redirected to if not logged in and they try to perform
Expand Down
4 changes: 3 additions & 1 deletion deploy/templates/base-includes/rightsidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@
</ul>

<ul class="unstyled no-lead">
<li><a href="{% url spc-rss-recent-submissions %}"><img src="{{STATIC_URL}}img/feed-icon-14x14.png"> most recent submissions feed</a></li>
<li><a href="{% url spc-rss-recent-submissions %}"><img src="{{STATIC_URL}}img/feed-icon-14x14.png"> Most Recent Submissions Feed</a></li>
<li><a href="{% url spc-rss-latest-comments %}"><img src="{{STATIC_URL}}img/feed-icon-14x14.png"> Most Recent Comments Feed</a></li>
{% if not preview and item.entry %}
<li><a href="{% url spc-rss-submission-feed item_id=item.entry.pk %}"><img src="{{STATIC_URL}}img/feed-icon-14x14.png"> This Submission Feed</a></li>
<li><a href="{% url spc-rss-comment-feed item_id=item.entry.pk rev_id=item.rev_id|add:1 %}"><img src="{{STATIC_URL}}img/feed-icon-14x14.png"> This Submission Comment Feed</a></li>
{% endif %}
{% if what_view == "tag" %}
<li><a href="{% url spc-rss-tag-feed extra_info %}"><img src="{{STATIC_URL}}img/feed-icon-14x14.png"> Recent <b>{{extra_info}}</b> submissions feed</a></li>
Expand Down
51 changes: 51 additions & 0 deletions deploy/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,57 @@
.accordion-inner { overflow: auto; }
</style>
{% endif %}

{# csrf token #}
<script type="text/javascript">
Copy link

Choose a reason for hiding this comment

The 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?

Copy link
Member Author

Choose a reason for hiding this comment

The 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

Copy link

Choose a reason for hiding this comment

The 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).

Copy link
Member Author

Choose a reason for hiding this comment

The 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) {
Copy link

Choose a reason for hiding this comment

The 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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script is mentioned in django documentation

Copy link

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually I didn't even write the comment
https://docs.djangoproject.com/en/1.5/ref/contrib/csrf/
It was mentioned here

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, I saw it. It's still wrong, though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:) okay I just wasn't bother about it.. will remove

Copy link
Member Author

Choose a reason for hiding this comment

The 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>
Expand Down
7 changes: 7 additions & 0 deletions deploy/templates/rest-help-text.html
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>
4 changes: 4 additions & 0 deletions deploy/templates/search/includes/one-search-result.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{# The ``entry`` object must be from the ``submission.Revision`` class #}
{% if entry %}
{% load comments %}

<li class="media">
<a class="pull-left" href="#">
{% if entry.entry.sub_type == 'snippet' %}
Expand All @@ -25,6 +27,8 @@ <h4 class="media-heading">
</ul>

<ul class="inline pull-right muted">
{% get_comment_count for entry as comment_count %}
<li><small><a href="{{entry.get_absolute_url}}#spc-comment-list"><i class="icon-envelope"></i> {{comment_count}}</a></small></li>
{% if entry.short_human_revision_string %}
<li><small>{{entry.short_human_revision_string|safe}}</small><li>
{% endif %}
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ Sphinx
Pygments
Pillow
Mercurial
simplejson
13 changes: 13 additions & 0 deletions scipy_central/comments/__init__.py
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
36 changes: 36 additions & 0 deletions scipy_central/comments/admin.py
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)
35 changes: 35 additions & 0 deletions scipy_central/comments/forms.py
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
16 changes: 16 additions & 0 deletions scipy_central/comments/models.py
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)
Loading