from django.core import serializers
from django.core.exceptions import ValidationError
from django.forms.formsets import formset_factory
+from karmaworld.apps.courses.forms import CourseForm
from karmaworld.apps.courses.models import Course
from karmaworld.apps.notes.search import SearchIndex
from karmaworld.apps.quizzes.create_quiz import quiz_from_keywords
return super(NoteSearchView, self).get_context_data(**kwargs)
-def handle_edit_note(request):
- course = Course.objects.get(pk=pk)
- original_name = course.name
- course_form = CourseForm(request.POST or None, instance=course)
-
- if course_form.is_valid():
- course_form.save()
-
- course_json = serializers.serialize('json', [course,])
- resp = json.loads(course_json)[0]
-
- if (course.name != original_name):
- course.set_slug()
- resp['fields']['new_url'] = course.get_absolute_url()
-
- return HttpResponse(json.dumps(resp), mimetype="application/json")
- else:
- return HttpResponseBadRequest(json.dumps({'status': 'fail', 'message': 'Validation error',
- 'errors': course_form.errors}),
- mimetype="application/json")
-
-def edit_note(request, pk):
- """
- Saves the edited note metadata
- """
- ajax_base(request, edit_note, ['POST'])
-
-
def process_note_thank_events(request_user, note):
# Give points to the person who uploaded this note
if note.user != request_user and note.user:
opacity: 0.8;
font-size: 0.8em;
}
+
+
+#add-course-form p {
+ margin: 0 0 0 0;
+}
+
+#add-course-form .results_on_deck {
+ margin-top: -10px;
+}
+
+.required-field {
+ opacity: 0.5;
+}
+
+ul.validation_error {
+ margin: 0 0 0 0;
+ list-style-type: none;
+}
+
+label.validation_error {
+ color: #F04124;
+}
+
box-shadow: 1px 1px 3px black;
}
-#add-course-form p {
- margin: 0 0 0 0;
-}
-
-#add-course-form .results_on_deck {
- margin-top: -10px;
-}
-
-.required-field {
- opacity: 0.5;
-}
-
-ul.validation_error {
- margin: 0 0 0 0;
- list-style-type: none;
-}
-
-label.validation_error {
- color: #F04124;
-}
-
#add-course-btn {
width: 100%;
font-size: 1.2em;
<span style="display: inline;">
<span class="show-for-large-up">
{% if user.is_authenticated %}
+ {% comment %}
{% if user.get_profile.can_edit_items %}
<button id="edit-button" data-reveal-id="edit-course-form" class="modify-button"> <i class="fa fa-edit"></i> Edit this course</button>
{% endif %}
+ {% endcomment %}
{% if already_flagged %}
<i class="fa fa-flag"></i> You have reported this course as inappropriate
</div><!-- /course_header -->
+ {% comment %}
{% if user.get_profile.can_edit_items %}
- <section id="edit-course-form" class="reveal-modal" data-reveal>
- <a class="close-reveal-modal">×</a>
- <form>
- {% csrf_token %}
-
- <div class="row">
- <div id="course_form_errors" class="small-12 columns">
- {{ course_form.non_field_errors }}
- </div>
- </div>
-
- <div class="row hide">
- <div class="small-12 columns">
- <label for="id_school">School</label>
- <div>
- <input id="id_school" value="{{ course.school.id }}" name="school" type='hidden'/>
- </div>
- </div>
- </div> <!-- .row -->
-
- <div class="row">
- <div class="small-12 columns">
- <label for="id_name">Course Name:</label>
- <input id="id_name" class="" type="text" name="name" maxlength="255" value="{{ course.name }}"/>
- </div>
- </div> <!-- .row -->
-
- <div class="row">
- <div class="small-12 columns large-6">
- <label for="id_instructor_name">Instructor Name:</label>
- <input id="id_instructor_name" class="" type="text" name="instructor_name" maxlength="75" value="{{ course.instructor_name }}"/>
- </div>
-
- <div class="small-12 columns large-6">
- <label for="id_instructor_email">Instructor Email:</label>
- <input id="id_instructor_email" class="" type="text" name="instructor_email" maxlength="75" value="{{ course.instructor_email }}"/>
- </div>
- </div> <!-- .row -->
-
- <div class="row">
- <div class="small-12 columns">
- <label for="id_url">Course url:</label>
- <input id="id_url" class="" type="text" name="url" maxlength="255" value="{{ course.url }}"/>
- </div>
- </div> <!-- .row -->
-
- <div class="row">
- <div class="small-4 large-8 columns small-centered text-center">
- <button id="edit-save-btn" type=button><i class="fa fa-save"></i> Save</button>
- </div>
- </div>
- </form>
- </section>
+ {% include 'partial/edit_course.html' %}
{% endif %}
+ {% endcomment %}
<div id="note-search-bar" class="row">
<div class="small-12 large-3 columns">
var annotator_js_url = "{{ STATIC_URL }}js/annotator-full.min.js";
var annotator_css_url = "{{ STATIC_URL }}css/annotator.min.css";
var setup_ajax_url = "{{ STATIC_URL }}js/setup-ajax.js";
- var note_edit_url = "{% url 'edit_note' note.id %}";
var user_authenticated = {% if user.is_authenticated %}true{% else %}false{% endif %};
</script>
{% compress js %}
--- /dev/null
+{% load url from future %}
+
+<section id="edit-course-form" class="reveal-modal" data-reveal>
+ <a class="close-reveal-modal">×</a>
+
+ <h2>Edit this course KarmaNotes</h2>
+
+ <form method="POST" action="">
+ {% csrf_token %}
+
+ {% if course_form.non_field_errors %}
+ <div class="row">
+ <div class="small-12 columns">
+ <ul class="validation_error">{% for error in course_form.non_field_errors %}
+ <li><label class="validation_error">{{ error }}</label></li>
+ {% endfor %}</ul>
+ </div>
+ </div>
+ {% endif %}
+
+ {% for form in course_form.get_forms.itervalues %}
+ {% for hidden in form.hidden_fields %}
+ {{ hidden }}
+ {% endfor %}
+ {% endfor %}
+ {% for hidden in course_form.hidden_fields %}
+ {{ hidden }}
+ {% endfor %}
+ <div class="row">
+ <div class="small-12 large-6 columns add-course-field">
+ {% with course_form.get_forms.professor.name as field %}
+ {{ field.errors|safe }}
+ <label for="{{ field.id_for_label }}">{{ field.label }}:</label>
+ {{ field }}
+ {% endwith %}
+ </div>
+ <div class="small-12 large-6 columns add-course-field">
+ {% with course_form.get_forms.professor.email as field %}
+ {{ field.errors|safe }}
+ <label for="{{ field.id_for_label }}">{{ field.label }}:</label>
+ {{ field }}
+ {% endwith %}
+ </div>
+ </div>
+
+ <div class="row">
+ <div class="small-12 large-6 columns add-course-field">
+ {% with course_form.name as field %}
+ {{ field.errors|safe }}
+ <label for="{{ field.id_for_label }}">{{ field.label }}:</label>
+ {{ field }}
+ {% endwith %}
+ </div>
+ <div class="small-12 large-6 columns add-course-field">
+ {% with course_form.url as field %}
+ {{ field.errors|safe }}
+ <label for="{{ field.id_for_label }}">{{ field.label }}:</label>
+ {{ field }}
+ {% endwith %}
+ </div>
+ </div>
+
+ <div class="row">
+ <div class="small-12 columns add-course-field">
+ {% with course_form.instruction_url as field %}
+ {{ field.errors|safe }}
+ <label for="{{ field.id_for_label }}">{{ field.label }}:</label>
+ {{ field }}
+ {% endwith %}
+ </div>
+ </div>
+
+ <div class="row">
+ <div class="small-12 columns small-centered text-center">
+ <button id="save-btn" type="submit">
+ <i class="fa fa-save"></i> Save
+ </button>
+ </div>
+ </div>
+
+ </form>
+</section>
from karmaworld.apps.courses.views import school_course_list
from karmaworld.apps.courses.views import school_course_instructor_list
from karmaworld.apps.notes.views import NoteView, thank_note, NoteSearchView, flag_note, downloaded_note, edit_note_tags, \
- NoteKeywordsView, NoteQuizView, edit_note, NoteDeleteView
+ NoteKeywordsView, NoteQuizView, NoteDeleteView
from karmaworld.apps.moderation import moderator
from karmaworld.apps.document_upload.views import save_fp_upload
from karmaworld.apps.quizzes.views import set_delete_keyword_annotator, get_keywords_annotator
url(r'^ajax/course/flag/(?P<pk>[\d]+)/$', flag_course, name='flag_course'),
# Ajax endpoint to edit a course
url(r'^ajax/course/edit/(?P<pk>[\d]+)/$', edit_course, name='edit_course'),
- url(r'^ajax/note/edit/(?P<pk>[\d]+)/$', edit_note, name='edit_note'),
url(r'^ajax/annotations/annotations$', set_delete_keyword_annotator, name='set_keyword'),
url(r'^ajax/annotations/search/$', get_keywords_annotator, name='get_keywords'),