Commit 1716dfaea00a94470508732f37469c52b3532d7f
1 parent
6b6b8caa
Exists in
master
and in
5 other branches
Adding url to subscribe in course [Issue: #194]
Showing
2 changed files
with
12 additions
and
5 deletions
Show diff stats
courses/urls.py
... | ... | @@ -8,6 +8,7 @@ urlpatterns = [ |
8 | 8 | url(r'^edit/(?P<slug>[\w_-]+)/$', views.UpdateCourseView.as_view(), name='update'), |
9 | 9 | url(r'^(?P<slug>[\w_-]+)/$', views.CourseView.as_view(), name='view'), |
10 | 10 | url(r'^delete/(?P<slug>[\w_-]+)/$', views.DeleteCourseView.as_view(), name='delete'), |
11 | + url(r'^register/(?P<slug>[\w_-]+)/$', views.subscribe_course, name='subscribe'), | |
11 | 12 | url(r'^category/(?P<slug>[\w_-]+)/$', views.FilteredView.as_view(), name='filter'), |
12 | 13 | url(r'^categories/view/$', views.IndexCatView.as_view(), name='manage_cat'), |
13 | 14 | url(r'^categories/create/$', views.CreateCatView.as_view(), name="create_cat"), |
... | ... | @@ -31,7 +32,4 @@ urlpatterns = [ |
31 | 32 | url(r'^files/', include('files.urls', namespace = 'file')), |
32 | 33 | url(r'^upload-material/$', views.UploadMaterialView.as_view(), name='upload_material'), |
33 | 34 | url(r'^links/',include('links.urls',namespace = 'links')), |
34 | - | |
35 | - | |
36 | - | |
37 | -] | |
35 | +] | |
38 | 36 | \ No newline at end of file | ... | ... |
courses/views.py
... | ... | @@ -10,7 +10,7 @@ from django.utils.translation import ugettext_lazy as _ |
10 | 10 | from rolepermissions.verifications import has_role |
11 | 11 | from django.db.models import Q |
12 | 12 | from rolepermissions.verifications import has_object_permission |
13 | -from django.http import HttpResponseRedirect | |
13 | +from django.http import HttpResponseRedirect, JsonResponse | |
14 | 14 | |
15 | 15 | from .forms import CourseForm, UpdateCourseForm, CategoryCourseForm, SubjectForm,TopicForm,ActivityForm |
16 | 16 | from .models import Course, Subject, CourseCategory,Topic, SubjectCategory,Activity, CategorySubject |
... | ... | @@ -227,6 +227,15 @@ class DeleteView(LoginRequiredMixin, HasRoleMixin, NotificationMixin, generic.De |
227 | 227 | |
228 | 228 | return self.response_class(request=self.request, template=self.get_template_names(), context=context, using=self.template_engine) |
229 | 229 | |
230 | +@login_required | |
231 | +def subscribe_course(request, slug): | |
232 | + course = get_object_or_404(Course, slug = slug) | |
233 | + | |
234 | + if course.students.add(request.user): | |
235 | + return JsonResponse({"status": "ok", "message": _("Successfully subscribed to the course!")}) | |
236 | + else: | |
237 | + return JsonResponse({"status": "erro", "message": _("An error has occured. Could not subscribe to this course, try again later")}) | |
238 | + | |
230 | 239 | class FilteredView(LoginRequiredMixin, generic.ListView): |
231 | 240 | |
232 | 241 | login_url = reverse_lazy("core:home") | ... | ... |