Commit a225b178bf42da5980e9edb477241d6702ee7c17
Exists in
master
and in
5 other branches
Merge branch 'dev' of https://github.com/amadeusproject/amadeuslms into dev
Showing
21 changed files
with
399 additions
and
155 deletions
Show diff stats
app/templates/home.html
@@ -31,11 +31,11 @@ | @@ -31,11 +31,11 @@ | ||
31 | // Configure the url we're about to hit | 31 | // Configure the url we're about to hit |
32 | setTimeout(function (){ | 32 | setTimeout(function (){ |
33 | $.ajax({ | 33 | $.ajax({ |
34 | - url: baseUrl, | 34 | + url: baseUrl, |
35 | data: {'page': pageNum}, | 35 | data: {'page': pageNum}, |
36 | success: function(data) { | 36 | success: function(data) { |
37 | $("#loading").hide(); | 37 | $("#loading").hide(); |
38 | - | 38 | + |
39 | $("#timeline").append(data); | 39 | $("#timeline").append(data); |
40 | }, | 40 | }, |
41 | complete: function(data, textStatus){ | 41 | complete: function(data, textStatus){ |
@@ -46,7 +46,7 @@ | @@ -46,7 +46,7 @@ | ||
46 | }, 1000) | 46 | }, 1000) |
47 | }; | 47 | }; |
48 | 48 | ||
49 | - $(document).ready(function(){ | 49 | + $(document).ready(function(){ |
50 | $(window).bind('scroll', loadOnScroll); | 50 | $(window).bind('scroll', loadOnScroll); |
51 | }); | 51 | }); |
52 | </script> | 52 | </script> |
@@ -62,70 +62,48 @@ | @@ -62,70 +62,48 @@ | ||
62 | {% endblock %} | 62 | {% endblock %} |
63 | 63 | ||
64 | {% block sidebar %} | 64 | {% block sidebar %} |
65 | - <div class="panel panel-primary"> | 65 | + <div class="panel panel-primary navigation"> |
66 | <div class="panel-heading"> | 66 | <div class="panel-heading"> |
67 | - <img src="{{ user.image_url }}" id="img" class="img-rounded"> | ||
68 | - <p></p> | ||
69 | - <div class="row"> | ||
70 | - <div class="col-xs-3 col-md-3"> | ||
71 | - <i class="fa fa-facebook-official fa-2x" aria-hidden="true"></i> | ||
72 | - </div> | ||
73 | - <div class="col-xs-3 col-md-3"> | ||
74 | - <i class="fa fa-twitter fa-2x" aria-hidden="true"></i> | ||
75 | - </div> | ||
76 | - <div class="col-xs-3 col-md-3"> | ||
77 | - <i class="fa fa-linkedin-square fa-2x" aria-hidden="true"></i> | ||
78 | - </div> | ||
79 | - <div class="col-xs-3 col-md-3"> | ||
80 | - <i class="fa fa-google-plus-official fa-2x" aria-hidden="true"></i> | ||
81 | - </div> | ||
82 | - </div> | ||
83 | - </div> | ||
84 | - <div class="panel-body"> | ||
85 | - <ul class="nav nav-pills nav-stacked"> | ||
86 | - <li> <a href="{% url 'app:index' %}">{% trans 'Home' %}</a></li> | ||
87 | - <li> <a href="{% url 'users:profile' %}">{% trans 'Profile' %}</a></li> | ||
88 | - <li> <a href="#">{% trans 'Pending Tasks' %}</a></li> | ||
89 | - {% if user|has_role:'student' and not user.is_staff %} | ||
90 | - <li> <a href="{% url 'course:manage' %}">{% trans 'My courses' %}</a></li> | ||
91 | - {% endif %} | ||
92 | - {% if user|has_role:'system_admin' %} | ||
93 | - <li> <a href="{% url 'users:manage' %}">{% trans 'Manage Users' %}</a></li> | ||
94 | - {% endif %} | ||
95 | - {% if user|has_role:'system_admin' or user|has_role:'professor' %} | ||
96 | - <li> | ||
97 | - <a href="#courses_list" class="accordion" data-toggle="collapse">{% trans 'Manage Courses' %}</a> | ||
98 | - | ||
99 | - <div id="courses_list" class="collapse"> | ||
100 | - <ul class="nav nav-pill nav-stacked accordion_list"> | ||
101 | - {% for course in courses_list %} | ||
102 | - <li><a href="{% url 'course:view' course.slug %}">{{ course }}</a></li> | ||
103 | - {% endfor %} | ||
104 | - </ul> | ||
105 | - </div> | ||
106 | - </li> | ||
107 | - {% endif %} | ||
108 | - </ul> | ||
109 | - </div> | ||
110 | - </div> | 67 | + <h4>Menu</h4> |
68 | + </div> | ||
69 | + <div class="panel-body"> | ||
70 | + <ul class="nav nav-pills nav-stacked"> | ||
71 | + <li><a href="{% url 'app:index' %}">{% trans 'Home' %}</a></li> | ||
72 | + <li><a href="{% url 'users:profile' %}">{% trans 'Profile' %}</a></li> | ||
73 | + {% if user|has_role:'student' or not user.is_staff %} | ||
74 | + <li><a href="{% url 'course:manage' %}">{% trans 'My courses' %}</a></li> | ||
75 | + {% endif %} | ||
76 | + {% if user|has_role:'system_admin' %} | ||
77 | + <li> <a href="{% url 'users:manage' %}">{% trans 'Manage Users' %}</a></li> | ||
78 | + {% endif %} | ||
79 | + {% if user|has_role:'system_admin' or user|has_role:'professor' %} | ||
80 | + <li> | ||
81 | + <a href="#courses_list" class="accordion" data-toggle="collapse">{% trans 'Manage Courses' %}</a> | ||
82 | + <div id="courses_list" class="collapse"> | ||
83 | + <ul class="nav nav-pill nav-stacked accordion_list"> | ||
84 | + {% for course in courses_list %} | ||
85 | + <li><a href="{% url 'course:view' course.slug %}">{{ course }}</a></li> | ||
86 | + {% endfor %} | ||
87 | + </ul> | ||
88 | + </div> | ||
89 | + </li> | ||
90 | + {% endif %} | ||
91 | + </ul> | ||
92 | + </div> | ||
93 | + </div> | ||
111 | {% endblock %} | 94 | {% endblock %} |
112 | 95 | ||
113 | {% block content %} | 96 | {% block content %} |
114 | {% if user|has_role:'system_admin' %} | 97 | {% if user|has_role:'system_admin' %} |
115 | - <h3>{% trans 'Courses' %}</h3> | ||
116 | - | ||
117 | - <div id="timeline"> | ||
118 | - {% include page_template %} | ||
119 | - </div> | ||
120 | - | 98 | + <h3>{% trans 'Courses' %}</h3> |
99 | + <div id="timeline"> | ||
100 | + {% include page_template %} | ||
101 | + </div> | ||
121 | {% else %} | 102 | {% else %} |
122 | - | ||
123 | - <div id="timeline"> | ||
124 | - {% include page_template %} | ||
125 | - </div> | ||
126 | - | 103 | + <div id="timeline"> |
104 | + {% include page_template %} | ||
105 | + </div> | ||
127 | {% endif %} | 106 | {% endif %} |
128 | - | ||
129 | <div id="loading" class="alert alert-primary" role="alert" style="display: none"> | 107 | <div id="loading" class="alert alert-primary" role="alert" style="display: none"> |
130 | <center> | 108 | <center> |
131 | <span class="fa fa-spin fa-circle-o-notch"></span> | 109 | <span class="fa fa-spin fa-circle-o-notch"></span> |
app/templates/home_student.html
@@ -18,7 +18,7 @@ | @@ -18,7 +18,7 @@ | ||
18 | {% block sidebar %} | 18 | {% block sidebar %} |
19 | <div class="panel panel-primary navigation"> | 19 | <div class="panel panel-primary navigation"> |
20 | <div class="panel-heading"> | 20 | <div class="panel-heading"> |
21 | - <h5>{% trans 'Menu' %}</h5> | 21 | + <h4>{% trans 'Menu' %}</h4> |
22 | </div> | 22 | </div> |
23 | <div class="panel-body"> | 23 | <div class="panel-body"> |
24 | <ul class="nav nav-pills nav-stacked"> | 24 | <ul class="nav nav-pills nav-stacked"> |
core/static/css/base/amadeus.css
@@ -276,7 +276,7 @@ a.alert_message:hover{color : grey} | @@ -276,7 +276,7 @@ a.alert_message:hover{color : grey} | ||
276 | 276 | ||
277 | /*Logo register user*/ | 277 | /*Logo register user*/ |
278 | #logo{ | 278 | #logo{ |
279 | - max-width: 30%; | 279 | + max-width: 40%; |
280 | margin-top: 1em; | 280 | margin-top: 1em; |
281 | margin-bottom: 1em; | 281 | margin-bottom: 1em; |
282 | } | 282 | } |
core/templates/base.html
@@ -109,7 +109,7 @@ | @@ -109,7 +109,7 @@ | ||
109 | {% endblock %} | 109 | {% endblock %} |
110 | </div> | 110 | </div> |
111 | 111 | ||
112 | - | 112 | + |
113 | </div> | 113 | </div> |
114 | </div> | 114 | </div> |
115 | </div> | 115 | </div> |
@@ -117,7 +117,7 @@ | @@ -117,7 +117,7 @@ | ||
117 | <script src="{% static 'js/main.js' %}"></script> | 117 | <script src="{% static 'js/main.js' %}"></script> |
118 | <script type="text/javascript" src="{% static 'js/topic_editation_presentation.js' %}"></script> | 118 | <script type="text/javascript" src="{% static 'js/topic_editation_presentation.js' %}"></script> |
119 | {% block script_file %} | 119 | {% block script_file %} |
120 | - | 120 | + |
121 | {% endblock script_file %} | 121 | {% endblock script_file %} |
122 | </body> | 122 | </body> |
123 | 123 |
@@ -0,0 +1,177 @@ | @@ -0,0 +1,177 @@ | ||
1 | +{% extends 'base.html' %} | ||
2 | + | ||
3 | +{% block breadcrumbs %} | ||
4 | + <div class="col-md-12"> | ||
5 | + <form id="searchform" action="{% url 'course:manage' %}" method="get" accept-charset="utf-8"> | ||
6 | + <div class="input-group"> | ||
7 | + <div class="form-group is-empty"> | ||
8 | + <input type="search" class="form-control" placeholder="Search Courses" name="q" id="searchbox"></div> | ||
9 | + <span class="input-group-btn input-group-sm"> | ||
10 | + <button type="button" class="btn btn-fab btn-fab-mini"> | ||
11 | + <i class="material-icons">search</i> | ||
12 | + </button> | ||
13 | + </span> | ||
14 | + </div> | ||
15 | + </form> | ||
16 | + </div> | ||
17 | + | ||
18 | + <div class="col-md-12"> | ||
19 | + <div class="btn-group btn-group-justified btn-group-raised"> | ||
20 | + <a href="?category=all" class="btn btn-raised btn-info">Todos</a> | ||
21 | + {% for category_course in categorys_courses %} | ||
22 | + <a href="?category={{category_course.name}}" class="btn btn-raised btn-primary">{{category_course.name}}</a> | ||
23 | + {% endfor %} | ||
24 | + </div> | ||
25 | + </div> | ||
26 | + | ||
27 | +{% endblock %} | ||
28 | + | ||
29 | + | ||
30 | +{% block content %} | ||
31 | + | ||
32 | + {% for course in courses %} | ||
33 | + <div class="panel panel-info"> | ||
34 | + <div class="panel-heading"> | ||
35 | + <h3 class="panel-title">{{course.name}}</h3> | ||
36 | + </div> | ||
37 | + | ||
38 | + <div class="panel-body"> | ||
39 | + <p><b>Course Name: </b>{{course.name}}</p> | ||
40 | + <p><b>Begining: </b>{{course.init_date}}</p> | ||
41 | + <p><b>End: </b>{{course.end_date}}</p> | ||
42 | + <p><b>Professor: </b>{{course.professors.name}}</p> | ||
43 | + <p> | ||
44 | + <b>Description:</b> | ||
45 | + <i> | ||
46 | + {{course.content}} | ||
47 | + </i> | ||
48 | + </p> | ||
49 | + </div> | ||
50 | + </div> | ||
51 | + {% endfor %} | ||
52 | +{% endblock %} | ||
53 | + | ||
54 | + | ||
55 | + | ||
56 | +{% comment %} | ||
57 | + | ||
58 | + | ||
59 | + | ||
60 | + | ||
61 | +</fieldset> | ||
62 | + <div class="col-md-12"> | ||
63 | + {% if courses|length > 0 %} | ||
64 | + {% if request.GET.category == 'all' or none or request.GET.category == '' %} | ||
65 | + {% for course in list_courses %} | ||
66 | + <div class="panel-group ui-accordion ui-widget ui-helper-reset ui-sortable" id="accordion" role="tablist" aria-multiselectable="false"> | ||
67 | + <div class="group"> | ||
68 | + <div class="panel panel-info"> | ||
69 | + <div class="panel-heading" role="tab"> | ||
70 | + <div class="row"> | ||
71 | + <div class="col-xs-9 col-md-9 titleTopic"> | ||
72 | + <a role="button" data-toggle="collapse" data-parent="#accordion" href=".collapseOne" aria-expanded="false" aria-controls="collapseOne" class="collapsed"> | ||
73 | + <h4 style="color:white">{{course.name}}</h4> | ||
74 | + </a> | ||
75 | + </div> | ||
76 | + </div> | ||
77 | + </div> | ||
78 | + <div class="panel-collapse collapseOne collapse in" role="tabpanel" aria-labelledby="headingOne" aria-expanded="true" aria-hidden="false" tabindex="0"> | ||
79 | + <div class="panel-body"> | ||
80 | + <p><b>Course Name: </b>{{course.name}}</p> | ||
81 | + <p><b>Duration (in semesters): </b>09</p> | ||
82 | + <p><b>Coordinator: </b>{{course.professors}}</p> | ||
83 | + <p> | ||
84 | + <b>Description:</b> | ||
85 | + <i> | ||
86 | + {{course.description}} | ||
87 | + </i> | ||
88 | + </p> | ||
89 | + <a href="{% url 'course:view' course.slug %}" class="btn btn-raised btn-default center-block">'View Course<div class="ripple-container"></div></a> | ||
90 | + </div> | ||
91 | + </div> | ||
92 | + </div> | ||
93 | + </div> | ||
94 | + </div> | ||
95 | + {% endfor %} | ||
96 | + {% else %} | ||
97 | + {% for course in courses_category %} | ||
98 | + {% if course.category.name == request.GET.category %} | ||
99 | + <!-- Put your content here! --> | ||
100 | + <div class="panel-group ui-accordion ui-widget ui-helper-reset ui-sortable" id="accordion" role="tablist" aria-multiselectable="false"> | ||
101 | + <div class="group"> | ||
102 | + <div class="panel panel-info"> | ||
103 | + <div class="panel-heading" role="tab"> | ||
104 | + <div class="row"> | ||
105 | + <div class="col-xs-9 col-md-9 titleTopic"> | ||
106 | + <a role="button" data-toggle="collapse" data-parent="#accordion" href=".collapseOne" aria-expanded="false" aria-controls="collapseOne" class="collapsed"> | ||
107 | + <h4 style="color:white">{{course.name}}</h4> | ||
108 | + </a> | ||
109 | + </div> | ||
110 | + </div> | ||
111 | + </div> | ||
112 | + <div class="panel-collapse collapseOne collapse in" role="tabpanel" aria-labelledby="headingOne" aria-expanded="true" aria-hidden="false" tabindex="0"> | ||
113 | + <div class="panel-body"> | ||
114 | + <p><b>Course Name: </b>{{course.name}}</p> | ||
115 | + <p><b>Duration (in semesters): </b>09</p> | ||
116 | + <p><b>Coordinator: </b>{{course.professors}}</p> | ||
117 | + <p> | ||
118 | + <b>Description:</b> | ||
119 | + <i> | ||
120 | + {{course.description}} | ||
121 | + </i> | ||
122 | + </p> | ||
123 | + <a href="{% url 'course:view' course.slug %}" class="btn btn-raised btn-default center-block">View Course<div class="ripple-container"></div></a> | ||
124 | + </div> | ||
125 | + </div> | ||
126 | + </div> | ||
127 | + </div> | ||
128 | + </div> | ||
129 | + {% endif %} | ||
130 | + {% endfor %} | ||
131 | + {% endif %} | ||
132 | + {% else %} | ||
133 | + No courses found | ||
134 | + {% endif %} | ||
135 | + <div class="group"> | ||
136 | + <div class="modal" id="removeCourse"> | ||
137 | + <div class="modal-dialog"> | ||
138 | + <div class="modal-content"> | ||
139 | + <div class="modal-header"> | ||
140 | + <button type="button" class="close" data-dismiss="modal" aria-hidden="true">X</button> | ||
141 | + <h4 class="modal-title"></h4> | ||
142 | + </div> | ||
143 | + <div class="modal-body"> | ||
144 | + <p>Delete your course?</p> | ||
145 | + </div> | ||
146 | + <div class="modal-footer"> | ||
147 | + | ||
148 | + <a href="http://127.0.0.1:8080/html/screens/users/profile_user.html" target="_self"><button type="button" class="btn btn-primary">Confirm</button></a> | ||
149 | + | ||
150 | + </div> | ||
151 | + </div> | ||
152 | + </div> | ||
153 | + </div> | ||
154 | + </div> | ||
155 | + </div> | ||
156 | + <div class="col-md-12"> | ||
157 | + <nav aria-label="Page navigation"> | ||
158 | + <ul class="pagination"> | ||
159 | + {% if page_obj.has_previous %} | ||
160 | + <li> | ||
161 | + <a href="?page={{ page_obj.previous_page_number }}"><span><<</span></a> | ||
162 | + </li> | ||
163 | + {% endif %} | ||
164 | + {% for page_number in paginator.page_range %} | ||
165 | + <li{% if page_obj.number == page_number %} class="active"{% endif %}> | ||
166 | + <a href="?page={{ page_number }}">{{ page_number }}</a> | ||
167 | + </li> | ||
168 | + {% endfor %} | ||
169 | + {% if page_obj.has_next %} | ||
170 | + <li> | ||
171 | + <a href="?page={{ page_obj.next_page_number }}"><span>>></span></a> | ||
172 | + </li> | ||
173 | + {% endif %} | ||
174 | + </ul> | ||
175 | + </nav> | ||
176 | + </div> | ||
177 | +{% endcomment %} |
core/templates/index.html
@@ -61,7 +61,7 @@ | @@ -61,7 +61,7 @@ | ||
61 | <a href="{% url 'core:password_reset' %}">{% trans "Forgot your password?" %}</a> | 61 | <a href="{% url 'core:password_reset' %}">{% trans "Forgot your password?" %}</a> |
62 | </div> | 62 | </div> |
63 | <div class="col-md-6 col-xs-6 col-sm-6 col-lg-6 text-center"> | 63 | <div class="col-md-6 col-xs-6 col-sm-6 col-lg-6 text-center"> |
64 | - <button type="button" class="btn btn-flat" formaction="#" style="position: initial;">{% trans 'Guest' %}</button> | 64 | + <a class="btn btn-flat" href="{% url 'core:guest' %}" formaction="#" style="position: initial;">{% trans 'Guest' %}</a> |
65 | </div> | 65 | </div> |
66 | <div class="col-md-6 col-xs-6 col-sm-6 col-lg-6 text-center"> | 66 | <div class="col-md-6 col-xs-6 col-sm-6 col-lg-6 text-center"> |
67 | <button type="submite" class="btn btn-flat btn-success" form="form-login" style="position: initial;">{% trans 'Login' %}</button> | 67 | <button type="submite" class="btn btn-flat btn-success" form="form-login" style="position: initial;">{% trans 'Login' %}</button> |
core/templates/register_user.html
@@ -18,14 +18,16 @@ | @@ -18,14 +18,16 @@ | ||
18 | </div> | 18 | </div> |
19 | {% endfor %} | 19 | {% endfor %} |
20 | {% endif %} | 20 | {% endif %} |
21 | - <div class="row logo-row"> | ||
22 | - <div class="col-lg-offset-2 col-lg-9"> | 21 | + <div class="row"> |
22 | + <div class="col-lg-offset-2 col-lg-8 col-md-offset-2 col-md-8 col-xs-offset-2 col-xs-8 col-sm-offset-2 col-sm-8"> | ||
23 | + <div class="col-lg-8 col-md-8 col-xs-8 col-sm-8"> | ||
23 | <img src="{% static 'img/amadeus.png' %}" class="img-responsive center-block " alt="logo amadeus" id="logo"> | 24 | <img src="{% static 'img/amadeus.png' %}" class="img-responsive center-block " alt="logo amadeus" id="logo"> |
25 | + </div> | ||
24 | </div> | 26 | </div> |
25 | </div> | 27 | </div> |
26 | 28 | ||
27 | <div class="row"> | 29 | <div class="row"> |
28 | - <div class=""> | 30 | + <div class="col-lg-8 col-lg-offset-1 col-md-8 col-md-offset-1 col-sm-8 col-sm-offset-1 col-xs-8 col-xs-offset-1"> |
29 | <div class="card"> | 31 | <div class="card"> |
30 | <div class="card-content"> | 32 | <div class="card-content"> |
31 | <div class="card-body"> | 33 | <div class="card-body"> |
core/urls.py
@@ -11,6 +11,7 @@ urlpatterns = [ | @@ -11,6 +11,7 @@ urlpatterns = [ | ||
11 | url(r'^logout/$', auth_views.logout, {'next_page': 'core:home'}, name='logout'), | 11 | url(r'^logout/$', auth_views.logout, {'next_page': 'core:home'}, name='logout'), |
12 | url(r'^notification/([0-9]+)/$', views.processNotification, name='notification_read'), | 12 | url(r'^notification/([0-9]+)/$', views.processNotification, name='notification_read'), |
13 | url(r'^getNotifications/$', views.getNotifications, name='getNotifications'), | 13 | url(r'^getNotifications/$', views.getNotifications, name='getNotifications'), |
14 | + url(r'^guest/$', views.guest, name='guest'), | ||
14 | 15 | ||
15 | #Reset Password | 16 | #Reset Password |
16 | 17 |
core/views.py
@@ -18,7 +18,7 @@ from .forms import RegisterUserForm | @@ -18,7 +18,7 @@ from .forms import RegisterUserForm | ||
18 | from .decorators import log_decorator, notification_decorator | 18 | from .decorators import log_decorator, notification_decorator |
19 | 19 | ||
20 | from users.models import User | 20 | from users.models import User |
21 | - | 21 | +from courses.models import Course, CourseCategory |
22 | 22 | ||
23 | def index(request): | 23 | def index(request): |
24 | context = { | 24 | context = { |
@@ -113,3 +113,9 @@ def getNotifications(request): | @@ -113,3 +113,9 @@ def getNotifications(request): | ||
113 | 113 | ||
114 | html = render_to_string("notifications.html", context) | 114 | html = render_to_string("notifications.html", context) |
115 | return HttpResponse(html) | 115 | return HttpResponse(html) |
116 | + | ||
117 | +def guest (request): | ||
118 | + context = { | ||
119 | + 'courses': Course.objects.filter(public=True) | ||
120 | + } | ||
121 | + return render(request, 'guest.html', context) | ||
116 | \ No newline at end of file | 122 | \ No newline at end of file |
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +# -*- coding: utf-8 -*- | ||
2 | +# Generated by Django 1.10 on 2016-10-19 13:19 | ||
3 | +from __future__ import unicode_literals | ||
4 | + | ||
5 | +from django.db import migrations, models | ||
6 | + | ||
7 | + | ||
8 | +class Migration(migrations.Migration): | ||
9 | + | ||
10 | + dependencies = [ | ||
11 | + ('courses', '0002_auto_20161018_1842'), | ||
12 | + ] | ||
13 | + | ||
14 | + operations = [ | ||
15 | + migrations.AddField( | ||
16 | + model_name='course', | ||
17 | + name='public', | ||
18 | + field=models.BooleanField(default=False, verbose_name='Public'), | ||
19 | + preserve_default=False, | ||
20 | + ), | ||
21 | + ] |
courses/models.py
@@ -46,6 +46,7 @@ class Course(models.Model): | @@ -46,6 +46,7 @@ class Course(models.Model): | ||
46 | category = models.ForeignKey(CourseCategory, verbose_name = _('Category'), related_name='course_category') | 46 | category = models.ForeignKey(CourseCategory, verbose_name = _('Category'), related_name='course_category') |
47 | professors = models.ManyToManyField(User,verbose_name=_('Professors'), related_name='courses_professors') | 47 | professors = models.ManyToManyField(User,verbose_name=_('Professors'), related_name='courses_professors') |
48 | students = models.ManyToManyField(User,verbose_name=_('Students'), related_name='courses_student') | 48 | students = models.ManyToManyField(User,verbose_name=_('Students'), related_name='courses_student') |
49 | + public = models.BooleanField(_('Public')) | ||
49 | 50 | ||
50 | class Meta: | 51 | class Meta: |
51 | ordering = ('create_date','name') | 52 | ordering = ('create_date','name') |
courses/static/js/course.js
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +/* | ||
2 | +* | ||
3 | +* Function to subscribe (works for courses and subjects) | ||
4 | +* | ||
5 | +*/ | ||
6 | +function subscribe(elem, url, confirm_message) { | ||
7 | + alertify.confirm(confirm_message, function(){ | ||
8 | + $.ajax({ | ||
9 | + dataType: "json", | ||
10 | + url: url, | ||
11 | + success: function (data) { | ||
12 | + if (data.status == "ok") { | ||
13 | + elem.disabled(true); | ||
14 | + alertify.success(data.message); | ||
15 | + } else { | ||
16 | + alertify.error(data.message); | ||
17 | + } | ||
18 | + } | ||
19 | + }); | ||
20 | + }); | ||
21 | +} | ||
0 | \ No newline at end of file | 22 | \ No newline at end of file |
@@ -0,0 +1,30 @@ | @@ -0,0 +1,30 @@ | ||
1 | + | ||
2 | +var Submite = { | ||
3 | + remove: function(url,dados,id_li_link){ | ||
4 | + $('#category').modal('hide'); | ||
5 | + $.post(url,dados, function(data){ | ||
6 | + $(id_li_link).remove(); | ||
7 | + $("#modal_category").empty(); | ||
8 | + $("div.modal-backdrop.fade.in").remove(); | ||
9 | + alertify.success("Category removed successfully!"); | ||
10 | + }).fail(function(){ | ||
11 | + $("#modal_category").empty(); | ||
12 | + $("#modal_category").append(data); | ||
13 | + $('#category').modal('show'); | ||
14 | + }); | ||
15 | + } | ||
16 | +} | ||
17 | + | ||
18 | +var modal = { | ||
19 | + get: function (url, id_modal, id_div_modal){ | ||
20 | + $.get(url, function(data){ | ||
21 | + if($(id_modal).length){ | ||
22 | + $(id_div_modal).empty(); | ||
23 | + $(id_div_modal).append(data); | ||
24 | + } else { | ||
25 | + $(id_div_modal).append(data); | ||
26 | + } | ||
27 | + $(id_modal).modal('show'); | ||
28 | + }); | ||
29 | + } | ||
30 | +}; | ||
0 | \ No newline at end of file | 31 | \ No newline at end of file |
courses/templates/category/create.html
@@ -74,7 +74,7 @@ | @@ -74,7 +74,7 @@ | ||
74 | {% endif %} | 74 | {% endif %} |
75 | {% endfor %} | 75 | {% endfor %} |
76 | <div class="row text-center"> | 76 | <div class="row text-center"> |
77 | - <input type="submit" value="{% trans 'Save' %}" class="btn btn-sm btn-success" /> | 77 | + <button type="submit" class="btn btn-primary btn-raised">{% trans "Save" %}</button> |
78 | </div> | 78 | </div> |
79 | </form> | 79 | </form> |
80 | </div> | 80 | </div> |
courses/templates/category/delete.html
1 | -{% extends 'base.html' %} | ||
2 | - | ||
3 | -{% load static i18n %} | ||
4 | {% load static i18n permission_tags %} | 1 | {% load static i18n permission_tags %} |
5 | 2 | ||
6 | -{% block breadcrumbs %} | ||
7 | - <ol class="breadcrumb"> | ||
8 | - <li><a href="{% url 'app:index' %}">{% trans 'Home' %}</a></li> | ||
9 | - <li class="active">{% trans 'Manage Categories' %}</li> | ||
10 | - </ol> | ||
11 | -{% endblock %} | 3 | +<!-- Modal (remember to change the ids!!!) --> |
4 | +<div class="modal fade" id="category" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> | ||
5 | + <div class="modal-dialog" role="document"> | ||
6 | + <div class="modal-content"> | ||
7 | + <!-- Modal Header --> | ||
8 | + <div class="modal-header"> | ||
12 | 9 | ||
13 | -{% block sidebar %} | ||
14 | - <div class="panel panel-primary navigation"> | ||
15 | - <div class="panel-heading"> | ||
16 | - <h5>{% trans 'Menu' %}</h5> | ||
17 | - </div> | ||
18 | - <div class="panel-body"> | ||
19 | - <ul class="nav nav-pills nav-stacked"> | ||
20 | - <li><a href="{% url 'users:profile' %}">{% trans 'Profile' %}</a></li> | ||
21 | - <li><a href="{% url 'course:manage' %}">{% trans 'My Courses' %}</a></li> | ||
22 | - </ul> | ||
23 | - </div> | 10 | + <h4 class="modal-title" id="myModalLabel">{% trans "Delete Category" %}</h4> |
11 | + </div> | ||
12 | + <!-- Modal Body --> | ||
13 | + <div class="modal-body"> | ||
14 | + <!-- Put ONLY your content here!!! --> | ||
15 | + <form id="delete_form" action="" method="post"> | ||
16 | + {% csrf_token %} | ||
17 | + <p>{% trans 'Are you sure you want to delete the subject' %} "{{category.name}}"?</p> | ||
18 | + </form> | ||
19 | + </div> | ||
20 | + <!-- Modal Footer --> | ||
21 | + <div class="modal-footer"> | ||
22 | + <!-- Don't remove that!!! --> | ||
23 | + <button type="button" class="btn btn-danger btn-raised" data-dismiss="modal">{% trans "Close" %}</button> | ||
24 | + <button type="submit" id="button" form="delete_form" class="btn btn-primary btn-raised">{% trans "Delete" %}</button> | ||
25 | + <script> | ||
26 | + $("#delete_form").submit(function(event) { | ||
27 | + Submite.remove("{% url 'course:delete_cat' category.slug %}",$(this).serialize(),"#category_{{category.slug}}"); | ||
28 | + event.preventDefault(); | ||
29 | + }); | ||
30 | + </script> | ||
31 | + </div> | ||
24 | </div> | 32 | </div> |
25 | - | ||
26 | -{% if user|has_role:'professor' or user|has_role:'system_admin' %} | ||
27 | - | ||
28 | - <div class="panel panel-primary navigation"> | ||
29 | - <div class="panel-heading"> | ||
30 | - <h3 class="panel-title">Actions</h3> | ||
31 | - </div> | ||
32 | - <div class="panel-body"> | ||
33 | - <ul class="nav nav-pills nav-stacked"> | ||
34 | - <li><a href="javascript:void(0)">Replicate Course</a></li> | ||
35 | - <li><a href="{% url 'course:create' %}">Create Course</a></li> | ||
36 | - <li><a href="{% url 'course:create_cat' %}">Create Category</a></li> | ||
37 | - </ul> | ||
38 | - </div> | ||
39 | - </div> | ||
40 | - <div class="panel panel-primary navigation"> | ||
41 | - <div class="panel-heading"> | ||
42 | - <h3 class="panel-title">Category</h3> | ||
43 | - </div> | ||
44 | - <div class="panel-body"> | ||
45 | - <ul class="nav nav-pills nav-stacked"> | ||
46 | - <li><a href="{% url 'course:create_cat' %}">Create Category</a></li> | ||
47 | - <li><a href="{% url 'course:manage_cat' %}">List Category</a></li> | ||
48 | - </ul> | ||
49 | - </div> | ||
50 | - </div> | ||
51 | -{% endif %} | ||
52 | -{% endblock %} | ||
53 | - | ||
54 | -{% block content %} | ||
55 | - <div class="card card-content"> | ||
56 | - <div class="card-body"> | ||
57 | - <form action="" method="post">{% csrf_token %} | ||
58 | - <h1>{% trans 'Are you sure you want to delete the category' %} "{{ object }}"?</h1> | ||
59 | - <input type="submit" class="btn btn-success btn-sm" value="{% trans 'Yes' %}" /> | ||
60 | - <a href="{% url 'course:manage_cat' %}" class="btn btn-danger btn-sm">{% trans 'No' %}</a> | ||
61 | - </form> | ||
62 | - </div> | ||
63 | - </div> | ||
64 | -{% endblock %} | 33 | + </div> |
34 | +</div> | ||
35 | +<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> | ||
36 | +<script src="{% static 'js/modal_category.js' %}"></script> |
courses/templates/category/index.html
@@ -82,7 +82,8 @@ | @@ -82,7 +82,8 @@ | ||
82 | <td class="text-center"> | 82 | <td class="text-center"> |
83 | <a href="{% url 'course:view_cat' category.slug %}" class="btn btn-info btn-sm"><span class="glyphicon glyphicon-eye-open"></span></a> | 83 | <a href="{% url 'course:view_cat' category.slug %}" class="btn btn-info btn-sm"><span class="glyphicon glyphicon-eye-open"></span></a> |
84 | <a href="{% url 'course:update_cat' category.slug %}" class="btn btn-primary btn-sm"><span class="glyphicon glyphicon-edit"></span></a> | 84 | <a href="{% url 'course:update_cat' category.slug %}" class="btn btn-primary btn-sm"><span class="glyphicon glyphicon-edit"></span></a> |
85 | - <a href="{% url 'course:delete_cat' category.slug %}" class="btn btn-danger btn-sm"><span class="glyphicon glyphicon-trash"></span></a> | 85 | + <a href="javascript:modal.get('{% url 'course:delete_cat' category.slug %}','#category','#modal_category');" class="btn btn-danger btn-sm"><span class="glyphicon glyphicon-trash"></span></a> |
86 | + | ||
86 | </td> | 87 | </td> |
87 | </tr> | 88 | </tr> |
88 | {% endfor %} | 89 | {% endfor %} |
@@ -96,4 +97,6 @@ | @@ -96,4 +97,6 @@ | ||
96 | </tbody> | 97 | </tbody> |
97 | </table> | 98 | </table> |
98 | </div> | 99 | </div> |
99 | -{% endblock %} | 100 | + <div class="row" id="modal_category"> |
101 | +<script src="{% static 'js/modal_category.js' %}"></script> | ||
102 | +{% endblock %} | ||
100 | \ No newline at end of file | 103 | \ No newline at end of file |
courses/templates/category/update.html
@@ -87,7 +87,7 @@ | @@ -87,7 +87,7 @@ | ||
87 | {% endif %} | 87 | {% endif %} |
88 | {% endfor %} | 88 | {% endfor %} |
89 | <div class="row text-center"> | 89 | <div class="row text-center"> |
90 | - <input type="submit" value="{% trans 'Save' %}" class="btn btn-sm btn-success" /> | 90 | + <button type="submit" class="btn btn-primary btn-raised">{% trans "Save" %}</button> |
91 | </div> | 91 | </div> |
92 | </form> | 92 | </form> |
93 | </div> | 93 | </div> |
courses/templates/course/index.html
@@ -11,18 +11,18 @@ | @@ -11,18 +11,18 @@ | ||
11 | {% endblock %} | 11 | {% endblock %} |
12 | 12 | ||
13 | {% block sidebar %} | 13 | {% block sidebar %} |
14 | - <div class="panel panel-primary navigation"> | ||
15 | - <div class="panel-heading"> | ||
16 | - <h5>{% trans 'Menu' %}</h5> | ||
17 | - </div> | ||
18 | - <div class="panel-body"> | ||
19 | - <ul class="nav nav-pills nav-stacked"> | ||
20 | - <li><a href="{% url 'core:home' %}">{% trans 'Home' %}</a></li> | ||
21 | - <li><a href="{% url 'users:profile' %}">{% trans 'Profile' %}</a></li> | ||
22 | - <li><a href="{% url 'course:manage' %}">{% trans 'My Courses' %}</a></li> | ||
23 | - </ul> | ||
24 | - </div> | 14 | +<div class="panel panel-primary navigation"> |
15 | + <div class="panel-heading"> | ||
16 | + <h4>{% trans 'Menu' %}</h4> | ||
17 | + </div> | ||
18 | + <div class="panel-body"> | ||
19 | + <ul class="nav nav-pills nav-stacked"> | ||
20 | + <li><a href="{% url 'core:home' %}">{% trans 'Home' %}</a></li> | ||
21 | + <li><a href="{% url 'users:profile' %}">{% trans 'Profile' %}</a></li> | ||
22 | + <li><a href="{% url 'course:manage' %}">{% trans 'My Courses' %}</a></li> | ||
23 | + </ul> | ||
25 | </div> | 24 | </div> |
25 | +</div> | ||
26 | 26 | ||
27 | {% if user|has_role:'professor' or user|has_role:'system_admin' %} | 27 | {% if user|has_role:'professor' or user|has_role:'system_admin' %} |
28 | 28 | ||
@@ -98,13 +98,13 @@ | @@ -98,13 +98,13 @@ | ||
98 | <div class="panel panel-info"> | 98 | <div class="panel panel-info"> |
99 | <div class="panel-heading" role="tab"> | 99 | <div class="panel-heading" role="tab"> |
100 | <div class="row"> | 100 | <div class="row"> |
101 | - <div class="col-xs-9 col-md-9 titleTopic"> | 101 | + <div class="col-xs-9 col-md-10 titleTopic"> |
102 | <a role="button" data-toggle="collapse" data-parent="#accordion" href=".collapseOne" aria-expanded="false" aria-controls="collapseOne" class="collapsed"> | 102 | <a role="button" data-toggle="collapse" data-parent="#accordion" href=".collapseOne" aria-expanded="false" aria-controls="collapseOne" class="collapsed"> |
103 | <h4 style="color:white">{{course.name}}</h4> | 103 | <h4 style="color:white">{{course.name}}</h4> |
104 | </a> | 104 | </a> |
105 | </div> | 105 | </div> |
106 | {% if user|has_role:'professor' or user|has_role:'system_admin' %} | 106 | {% if user|has_role:'professor' or user|has_role:'system_admin' %} |
107 | - <div class="col-xs-4 col-md-3" id="divMoreActions"> | 107 | + <div class="col-xs-4 col-md-2" id="divMoreActions"> |
108 | <div class="btn-group"> | 108 | <div class="btn-group"> |
109 | <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | 109 | <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
110 | <i class="fa fa-ellipsis-v fa-2x" aria-hidden="true"></i> | 110 | <i class="fa fa-ellipsis-v fa-2x" aria-hidden="true"></i> |
courses/templates/subject/index.html
@@ -36,12 +36,12 @@ | @@ -36,12 +36,12 @@ | ||
36 | <div class="panel panel-info"> | 36 | <div class="panel panel-info"> |
37 | <div class="panel-heading"> | 37 | <div class="panel-heading"> |
38 | <div class="row"> | 38 | <div class="row"> |
39 | - <div class="col-md-10 col-sm-9"> | 39 | + <div class="col-md-10 col-sm-10"> |
40 | <h3>{{subject}}</h3> | 40 | <h3>{{subject}}</h3> |
41 | </div> | 41 | </div> |
42 | {% professor_subject subject user as subject_professor%} | 42 | {% professor_subject subject user as subject_professor%} |
43 | {% if subject_professor %} | 43 | {% if subject_professor %} |
44 | - <div class="col-xs-4 col-md-3 divMoreActions"> | 44 | + <div class="col-xs-4 col-md-2 divMoreActions"> |
45 | <div class="btn-group"> | 45 | <div class="btn-group"> |
46 | <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | 46 | <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
47 | <i class="fa fa-ellipsis-v fa-2x" aria-hidden="true"></i> | 47 | <i class="fa fa-ellipsis-v fa-2x" aria-hidden="true"></i> |
courses/urls.py
@@ -8,6 +8,7 @@ urlpatterns = [ | @@ -8,6 +8,7 @@ urlpatterns = [ | ||
8 | url(r'^edit/(?P<slug>[\w_-]+)/$', views.UpdateCourseView.as_view(), name='update'), | 8 | url(r'^edit/(?P<slug>[\w_-]+)/$', views.UpdateCourseView.as_view(), name='update'), |
9 | url(r'^(?P<slug>[\w_-]+)/$', views.CourseView.as_view(), name='view'), | 9 | url(r'^(?P<slug>[\w_-]+)/$', views.CourseView.as_view(), name='view'), |
10 | url(r'^delete/(?P<slug>[\w_-]+)/$', views.DeleteCourseView.as_view(), name='delete'), | 10 | url(r'^delete/(?P<slug>[\w_-]+)/$', views.DeleteCourseView.as_view(), name='delete'), |
11 | + url(r'^subscribe/(?P<slug>[\w_-]+)/$', views.subscribe_course, name='subscribe'), | ||
11 | url(r'^category/(?P<slug>[\w_-]+)/$', views.FilteredView.as_view(), name='filter'), | 12 | url(r'^category/(?P<slug>[\w_-]+)/$', views.FilteredView.as_view(), name='filter'), |
12 | url(r'^categories/view/$', views.IndexCatView.as_view(), name='manage_cat'), | 13 | url(r'^categories/view/$', views.IndexCatView.as_view(), name='manage_cat'), |
13 | url(r'^categories/create/$', views.CreateCatView.as_view(), name="create_cat"), | 14 | url(r'^categories/create/$', views.CreateCatView.as_view(), name="create_cat"), |
@@ -18,6 +19,7 @@ urlpatterns = [ | @@ -18,6 +19,7 @@ urlpatterns = [ | ||
18 | url(r'^subjects/create/(?P<slug>[\w_-]+)/$', views.CreateSubjectView.as_view(), name='create_subject'), | 19 | url(r'^subjects/create/(?P<slug>[\w_-]+)/$', views.CreateSubjectView.as_view(), name='create_subject'), |
19 | url(r'^subjects/update/(?P<slug>[\w_-]+)/$', views.UpdateSubjectView.as_view(), name='update_subject'), | 20 | url(r'^subjects/update/(?P<slug>[\w_-]+)/$', views.UpdateSubjectView.as_view(), name='update_subject'), |
20 | url(r'^subjects/delete/(?P<slug>[\w_-]+)/$', views.DeleteSubjectView.as_view(), name='delete_subject'), | 21 | url(r'^subjects/delete/(?P<slug>[\w_-]+)/$', views.DeleteSubjectView.as_view(), name='delete_subject'), |
22 | + url(r'^subjects/subscribe/(?P<slug>[\w_-]+)/$', views.subscribe_subject, name='subscribe_subject'), | ||
21 | url(r'^topics/create/(?P<slug>[\w_-]+)/$', views.CreateTopicView.as_view(), name='create_topic'), | 23 | url(r'^topics/create/(?P<slug>[\w_-]+)/$', views.CreateTopicView.as_view(), name='create_topic'), |
22 | url(r'^topics/update/(?P<slug>[\w_-]+)/$', views.UpdateTopicView.as_view(), name='update_topic'), | 24 | url(r'^topics/update/(?P<slug>[\w_-]+)/$', views.UpdateTopicView.as_view(), name='update_topic'), |
23 | url(r'^topics/createlink/$', linkviews.CreateLink.as_view(),name = 'create_link'), | 25 | url(r'^topics/createlink/$', linkviews.CreateLink.as_view(),name = 'create_link'), |
@@ -31,7 +33,4 @@ urlpatterns = [ | @@ -31,7 +33,4 @@ urlpatterns = [ | ||
31 | url(r'^files/', include('files.urls', namespace = 'file')), | 33 | url(r'^files/', include('files.urls', namespace = 'file')), |
32 | url(r'^upload-material/$', views.UploadMaterialView.as_view(), name='upload_material'), | 34 | url(r'^upload-material/$', views.UploadMaterialView.as_view(), name='upload_material'), |
33 | url(r'^links/',include('links.urls',namespace = 'links')), | 35 | url(r'^links/',include('links.urls',namespace = 'links')), |
34 | - | ||
35 | - | ||
36 | - | ||
37 | -] | 36 | +] |
38 | \ No newline at end of file | 37 | \ No newline at end of file |
courses/views.py
@@ -10,7 +10,7 @@ from django.utils.translation import ugettext_lazy as _ | @@ -10,7 +10,7 @@ from django.utils.translation import ugettext_lazy as _ | ||
10 | from rolepermissions.verifications import has_role | 10 | from rolepermissions.verifications import has_role |
11 | from django.db.models import Q | 11 | from django.db.models import Q |
12 | from rolepermissions.verifications import has_object_permission | 12 | from rolepermissions.verifications import has_object_permission |
13 | -from django.http import HttpResponseRedirect | 13 | +from django.http import HttpResponseRedirect, JsonResponse |
14 | 14 | ||
15 | from .forms import CourseForm, UpdateCourseForm, CategoryCourseForm, SubjectForm,TopicForm,ActivityForm | 15 | from .forms import CourseForm, UpdateCourseForm, CategoryCourseForm, SubjectForm,TopicForm,ActivityForm |
16 | from .models import Course, Subject, CourseCategory,Topic, SubjectCategory,Activity, CategorySubject | 16 | from .models import Course, Subject, CourseCategory,Topic, SubjectCategory,Activity, CategorySubject |
@@ -35,10 +35,10 @@ class IndexView(LoginRequiredMixin, NotificationMixin, generic.ListView): | @@ -35,10 +35,10 @@ class IndexView(LoginRequiredMixin, NotificationMixin, generic.ListView): | ||
35 | list_courses = None | 35 | list_courses = None |
36 | categorys_courses = None | 36 | categorys_courses = None |
37 | if has_role(self.request.user,'professor') or has_role(self.request.user,'system_admin'): | 37 | if has_role(self.request.user,'professor') or has_role(self.request.user,'system_admin'): |
38 | - list_courses = Course.objects.filter(professors__name = self.request.user.name).order_by('name') | 38 | + list_courses = Course.objects.filter(Q(professors = True)|Q(professors__name = self.request.user.name)).order_by('name') |
39 | categorys_courses = CourseCategory.objects.filter(course_category__professors__name = self.request.user.name).distinct() | 39 | categorys_courses = CourseCategory.objects.filter(course_category__professors__name = self.request.user.name).distinct() |
40 | else: | 40 | else: |
41 | - list_courses = Course.objects.filter(students__name = self.request.user.name) | 41 | + list_courses = Course.objects.filter(Q(students = True)|Q(students__name = self.request.user.name)).order_by('name') |
42 | categorys_courses = CourseCategory.objects.filter(course_category__students__name = self.request.user.name).distinct() | 42 | categorys_courses = CourseCategory.objects.filter(course_category__students__name = self.request.user.name).distinct() |
43 | 43 | ||
44 | courses_category = Course.objects.filter(category__name = self.request.GET.get('category')) | 44 | courses_category = Course.objects.filter(category__name = self.request.GET.get('category')) |
@@ -227,6 +227,15 @@ class DeleteView(LoginRequiredMixin, HasRoleMixin, NotificationMixin, generic.De | @@ -227,6 +227,15 @@ class DeleteView(LoginRequiredMixin, HasRoleMixin, NotificationMixin, generic.De | ||
227 | 227 | ||
228 | return self.response_class(request=self.request, template=self.get_template_names(), context=context, using=self.template_engine) | 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 | class FilteredView(LoginRequiredMixin, generic.ListView): | 239 | class FilteredView(LoginRequiredMixin, generic.ListView): |
231 | 240 | ||
232 | login_url = reverse_lazy("core:home") | 241 | login_url = reverse_lazy("core:home") |
@@ -296,6 +305,19 @@ class DeleteCatView(LoginRequiredMixin, HasRoleMixin, generic.DeleteView): | @@ -296,6 +305,19 @@ class DeleteCatView(LoginRequiredMixin, HasRoleMixin, generic.DeleteView): | ||
296 | model = CourseCategory | 305 | model = CourseCategory |
297 | template_name = 'category/delete.html' | 306 | template_name = 'category/delete.html' |
298 | 307 | ||
308 | + def dispatch(self, *args, **kwargs): | ||
309 | + category = get_object_or_404(CourseCategory, slug = self.kwargs.get('slug')) | ||
310 | + if(not has_object_permission('delete_category', self.request.user, category)): | ||
311 | + return self.handle_no_permission() | ||
312 | + return super(DeleteCatView, self).dispatch(*args, **kwargs) | ||
313 | + | ||
314 | + | ||
315 | + def get_context_data(self, **kwargs): | ||
316 | + context = super(DeleteCatView, self).get_context_data(**kwargs) | ||
317 | + context['course'] = self.object.course_category | ||
318 | + context['category'] = self.object | ||
319 | + return context | ||
320 | + | ||
299 | def get_success_url(self): | 321 | def get_success_url(self): |
300 | messages.success(self.request, _('Category deleted successfully!')) | 322 | messages.success(self.request, _('Category deleted successfully!')) |
301 | return reverse_lazy('course:manage_cat') | 323 | return reverse_lazy('course:manage_cat') |
@@ -526,6 +548,17 @@ class DeleteSubjectView(LoginRequiredMixin, HasRoleMixin, generic.DeleteView): | @@ -526,6 +548,17 @@ class DeleteSubjectView(LoginRequiredMixin, HasRoleMixin, generic.DeleteView): | ||
526 | def get_success_url(self): | 548 | def get_success_url(self): |
527 | return reverse_lazy('course:view', kwargs={'slug' : self.object.course.slug}) | 549 | return reverse_lazy('course:view', kwargs={'slug' : self.object.course.slug}) |
528 | 550 | ||
551 | +@login_required | ||
552 | +def subscribe_subject(request, slug): | ||
553 | + subject = get_object_or_404(Subject, slug = slug) | ||
554 | + | ||
555 | + if request.user.courses_student.filter(slug = slug).exists(): | ||
556 | + if subject.students.add(request.user): | ||
557 | + return JsonResponse({"status": "ok", "message": _("Successfully subscribed to the subject!")}) | ||
558 | + else: | ||
559 | + return JsonResponse({"status": "erro", "message": _("An error has occured. Could not subscribe to this subject, try again later")}) | ||
560 | + else: | ||
561 | + return JsonResponse({"status": "erro", "message": _("You're not subscribed in the course yet.")}) | ||
529 | 562 | ||
530 | class IndexSubjectCategoryView(LoginRequiredMixin, generic.ListView): | 563 | class IndexSubjectCategoryView(LoginRequiredMixin, generic.ListView): |
531 | allowed_roles = ['professor', 'system_admin'] | 564 | allowed_roles = ['professor', 'system_admin'] |