return super(NoteSearchView, self).get_context_data(**kwargs)
-def thank_note(request, pk):
- """Record that somebody has thanked a note."""
+def ajaxIncrementBase(request, pk, field):
+ """Increment a note's field by one."""
if not (request.method == 'POST' and request.is_ajax()):
# return that the api call failed
return HttpResponseBadRequest(json.dumps({'status': 'fail', 'message': 'must be a POST ajax request'}),
try:
note = Note.objects.get(pk=pk)
- note.thanks += 1
+ note.__dict__[field] += 1
note.save()
except ObjectDoesNotExist:
return HttpResponseNotFound(json.dumps({'status': 'fail', 'message': 'note id does not match a note'}),
return HttpResponse(status=204)
+def thank_note(request, pk):
+ """Record that somebody has thanked a note."""
+ return ajaxIncrementBase(request, pk, 'thanks')
+
+def flag_note(request, pk):
+ """Record that somebody has flagged a note."""
+ return ajaxIncrementBase(request, pk, 'flags')
+
+
margin-right: 10px;
}
+#thank-button-disabled,
+#flag-button-disabled
+{
+ cursor: default;
+}
+
/* COURSES */
#course_meta, #school_meta
type: 'POST'
});
});
+
+ $("#flag-button").click(function() {
+ event.preventDefault();
+
+ // disable thank button so it can't
+ // be pressed again
+ $(this).hide();
+ $('#flag-button-disabled').show();
+ $(this).unbind('click');
+
+ // tell server that somebody thanked
+ // this note
+ $.ajax({
+ url: note_flag_url,
+ dataType: "json",
+ type: 'POST'
+ });
+ });
});
{% block pagescripts %}
<script type="text/javascript">
var note_thank_url = "{% url 'thank_note' note.id %}"
+ var note_flag_url = "{% url 'flag_note' note.id %}"
var csrf_token = "{{ csrf_token }}";
</script>
<script src="{{ STATIC_URL }}js/setup-ajax.js"></script>
</div>
<div class="row">
- <div id="note_actions" class="large-2 medium-4 small-6 columns small-centered">
+ <div id="note_actions" class="large-3 medium-6 small-12 columns small-centered">
<div class="row">
- <!--
<div class="small-4 column">
- <img src="{{ STATIC_URL }}img/note_flag.png" alt="note_flag" width="25" height="35"/>
+ <a href="#" id="flag-button"><img src="{{ STATIC_URL }}img/note_flag.png" alt="note_flag" width="25" height="35"/></a>
+ <a href="#" id="flag-button-disabled" class="hide"><img src="{{ STATIC_URL }}img/note_flag_disabled.png" alt="note_flag" width="25" height="35"/></a>
</div>
- -->
- <div class="small-6 column">
+ <div class="small-4 column">
<a href="#" id="thank-button"><img src="{{ STATIC_URL }}img/note_thank.png" alt="note_thank" width="34" height="34"/></a>
<a href="#" id="thank-button-disabled" class="hide"><img src="{{ STATIC_URL }}img/note_thank_disabled.png" alt="note_thank" width="34" height="34"/></a>
</div>
- <div class="small-6 column">
+ <div class="small-4 column">
<a href="{{ note.fp_file }}">
<img src="{{ STATIC_URL }}img/note_download.png" alt="note_download" width="51" height="36" />
</a>
from karmaworld.apps.courses.views import school_course_list
from karmaworld.apps.courses.views import school_course_instructor_list
from karmaworld.apps.notes.models import Note
-from karmaworld.apps.notes.views import NoteView, thank_note, NoteSearchView
+from karmaworld.apps.notes.views import NoteView, thank_note, NoteSearchView, flag_note
from karmaworld.apps.notes.views import RawNoteDetailView
from karmaworld.apps.notes.views import PDFView
from karmaworld.apps.moderation import moderator
## NOTE MODEL
# Ajax endpoint to thank a note
url(r'^ajax/note/thank/(?P<pk>[\d]+)/$', thank_note, name='thank_note'),
+ # Ajax endpoint to flag a note
+ url(r'^ajax/note/flag/(?P<pk>[\d]+)/$', flag_note, name='flag_note'),
# Valid url cases to the Note page
# a: school/course/id