Commit ec910cdafc116a9e0f1970349084ebc297e8d21e
Exists in
master
and in
3 other branches
fixed conflicts between commits
Showing
8 changed files
with
357 additions
and
401 deletions
Show diff stats
amadeus/static/css/base/amadeus.css
amadeus/templates/base.html
@@ -50,7 +50,7 @@ | @@ -50,7 +50,7 @@ | ||
50 | 50 | ||
51 | <!--Javascript block for specific-app ones --> | 51 | <!--Javascript block for specific-app ones --> |
52 | <script src="{% static 'js/base/amadeus.js' %}"></script> | 52 | <script src="{% static 'js/base/amadeus.js' %}"></script> |
53 | - <script src="{% static 'js/main.js' %}"></script> | 53 | + |
54 | 54 | ||
55 | {% block style %} | 55 | {% block style %} |
56 | {% endblock %} | 56 | {% endblock %} |
@@ -216,6 +216,7 @@ | @@ -216,6 +216,7 @@ | ||
216 | 216 | ||
217 | <!-- Init material Bootstrap --> | 217 | <!-- Init material Bootstrap --> |
218 | <script type="text/javascript">$.material.init()</script> | 218 | <script type="text/javascript">$.material.init()</script> |
219 | + <script src="{% static 'js/main.js' %}"></script> | ||
219 | <script type="text/javascript"> | 220 | <script type="text/javascript"> |
220 | $('.text_wysiwyg').summernote({ | 221 | $('.text_wysiwyg').summernote({ |
221 | height: 200 | 222 | height: 200 |
subjects/forms.py
1 | -from .models import Subject, Tag | ||
2 | from django import forms | 1 | from django import forms |
2 | +from django.utils.translation import ugettext_lazy as _ | ||
3 | + | ||
4 | +from .models import Subject, Tag | ||
5 | + | ||
3 | class CreateSubjectForm(forms.ModelForm): | 6 | class CreateSubjectForm(forms.ModelForm): |
7 | + def __init__(self, *args, **kwargs): | ||
8 | + super(CreateSubjectForm, self).__init__(*args, **kwargs) | ||
9 | + | ||
10 | + if not kwargs['instance'] is None: | ||
11 | + self.initial['tags'] = ", ".join(self.instance.tags.all().values_list("name", flat = True)) | ||
12 | + | ||
4 | # TODO: Define form fields here | 13 | # TODO: Define form fields here |
14 | + tags = forms.CharField(label = _('Tags'), required = False) | ||
15 | + | ||
5 | class Meta: | 16 | class Meta: |
6 | model = Subject | 17 | model = Subject |
7 | 18 | ||
8 | - fields = ('name', 'description_brief', 'description', 'tags', 'init_date', 'end_date', 'visible', 'professor', 'students', ) | 19 | + fields = ('name', 'description_brief', 'description', 'init_date', 'end_date', 'visible', 'professor', |
20 | + 'students', ) | ||
21 | + | ||
9 | 22 | ||
10 | widgets = { | 23 | widgets = { |
11 | 'description_brief': forms.Textarea, | 24 | 'description_brief': forms.Textarea, |
@@ -14,6 +27,36 @@ class CreateSubjectForm(forms.ModelForm): | @@ -14,6 +27,36 @@ class CreateSubjectForm(forms.ModelForm): | ||
14 | 'students': forms.SelectMultiple, | 27 | 'students': forms.SelectMultiple, |
15 | } | 28 | } |
16 | 29 | ||
30 | + def save(self, commit=True): | ||
31 | + super(CreateSubjectForm, self).save(commit = True) | ||
32 | + | ||
33 | + self.instance.save() | ||
34 | + | ||
35 | + previous_tags = self.instance.tags.all() | ||
36 | + | ||
37 | + tags = self.cleaned_data['tags'].split(",") | ||
38 | + | ||
39 | + #Excluding unwanted tags | ||
40 | + for prev in previous_tags: | ||
41 | + if not prev.name in tags: | ||
42 | + self.instance.tags.remove(prev) | ||
43 | + | ||
44 | + for tag in tags: | ||
45 | + tag = tag.strip() | ||
46 | + | ||
47 | + exist = Tag.objects.filter(name = tag).exists() | ||
48 | + | ||
49 | + if exist: | ||
50 | + new_tag = Tag.objects.get(name = tag) | ||
51 | + else: | ||
52 | + new_tag = Tag.objects.create(name = tag) | ||
53 | + | ||
54 | + if not new_tag in self.instance.tags.all(): | ||
55 | + self.instance.tags.add(new_tag) | ||
56 | + | ||
57 | + #self.instance.save() | ||
58 | + | ||
59 | + return self.instance | ||
17 | 60 | ||
18 | class CreateTagForm(forms.ModelForm): | 61 | class CreateTagForm(forms.ModelForm): |
19 | class Meta: | 62 | class Meta: |
@@ -0,0 +1,179 @@ | @@ -0,0 +1,179 @@ | ||
1 | +{% load widget_tweaks static i18n %} | ||
2 | + | ||
3 | +<form method="post" action="" enctype="multipart/form-data"> | ||
4 | + {% csrf_token %} | ||
5 | + {% for field in form %} | ||
6 | + {% if field.auto_id == 'id_students' %} | ||
7 | + <div class="panel-group" id="coordinators_accordion" role="tablist" aria-multiselectable="true"> | ||
8 | + <div class="panel panel-info"> | ||
9 | + <div class="panel-heading"> | ||
10 | + <div class="row"> | ||
11 | + <div class="col-md-12"> | ||
12 | + <a data-parent="#coordinators_accordion" data-toggle="collapse" href="#students"> | ||
13 | + <h4 class="panel-title"> | ||
14 | + <button class="btn btn-default btn-xs text-center cat-selector"><i class="fa fa-angle-right fa-2x" aria-hidden="true"></i></button><label for="{{ field.auto_id }}">{{ field.label }}</label> | ||
15 | + </h4> | ||
16 | + </a> | ||
17 | + </div> | ||
18 | + </div> | ||
19 | + </div> | ||
20 | + <div id="students" class="panel-collapse collapse"> | ||
21 | + <p><em>{% trans 'Attribute students to subject' %}:</em></p> | ||
22 | + {% render_field field class='form-control' %} | ||
23 | + </div> | ||
24 | + </div> | ||
25 | + </div> | ||
26 | + {% elif field.auto_id == 'id_professor' %} | ||
27 | + <div class="panel-group" id="professors_accordion" role="tablist" aria-multiselectable="true"> | ||
28 | + <div class="panel panel-info"> | ||
29 | + <div class="panel-heading"> | ||
30 | + <div class="row"> | ||
31 | + <div class="col-md-12"> | ||
32 | + <a data-parent="#professors_accordion" data-toggle="collapse" href="#professors"> | ||
33 | + <h4 class="panel-title"> | ||
34 | + <button class="btn btn-default btn-xs text-center cat-selector"><i class="fa fa-angle-right fa-2x" aria-hidden="true"></i></button><label for="{{ field.auto_id }}">{{ field.label }}</label> | ||
35 | + </h4> | ||
36 | + </a> | ||
37 | + </div> | ||
38 | + </div> | ||
39 | + </div> | ||
40 | + <div id="professors" class="panel-collapse collapse"> | ||
41 | + <p><em>{% trans 'Attribute professors to subject' %}:</em></p> | ||
42 | + {% render_field field class='form-control' %} | ||
43 | + </div> | ||
44 | + </div> | ||
45 | + </div> | ||
46 | + {% elif field.auto_id == 'id_tags'%} | ||
47 | + <label> {{field.label}} </label> | ||
48 | + {% render_field field class='form-control' data-role="tagsinput" %} | ||
49 | + {% else %} | ||
50 | + <div class="form-group {% if form.has_error %} has-error {% endif %} is-fileinput"> | ||
51 | + {% if field.auto_id != 'id_visible' %} | ||
52 | + <label for="{{ field.auto_id }}">{{ field.label }}</label> | ||
53 | + {% endif %} | ||
54 | + {% if field.auto_id == 'id_visible' %} | ||
55 | + <div class="checkbox"> | ||
56 | + <label for="{{ field.auto_id }}"> | ||
57 | + {% render_field field %} {{field.label}} | ||
58 | + </label> | ||
59 | + </div> | ||
60 | + {% elif field.auto_id == 'id_description' or field.auto_id == 'id_description_brief' %} | ||
61 | + {% render_field field class='form-control text_wysiwyg' %} | ||
62 | + {% elif field.auto_id == 'id_init_date' or field.auto_id == 'id_end_date' %} | ||
63 | + {% render_field field class='form-control date-picker' %} | ||
64 | + {% else %} | ||
65 | + {% render_field field class='form-control' %} | ||
66 | + {% endif %} | ||
67 | + </div> | ||
68 | + {% endif %} | ||
69 | + <span class="help-block">{{ field.help_text }}</span> | ||
70 | + {% if field.errors %} | ||
71 | + <div class="row"> | ||
72 | + </br> | ||
73 | + <div class="alert alert-danger alert-dismissible" role="alert"> | ||
74 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
75 | + <span aria-hidden="true">×</span> | ||
76 | + </button> | ||
77 | + <ul> | ||
78 | + {% for error in field.errors %} | ||
79 | + <li>{{ error }}</li> | ||
80 | + {% endfor %} | ||
81 | + </ul> | ||
82 | + </div> | ||
83 | + </div> | ||
84 | + {% endif %} | ||
85 | + {% endfor %} | ||
86 | + <div class="row text-center"> | ||
87 | + <input type="submit" value="{% trans 'Save' %}" class="btn btn-primary btn-raised" /> | ||
88 | + </div> | ||
89 | +</form> | ||
90 | + | ||
91 | +<script type="text/javascript"> | ||
92 | + $('#id_professor').multiSelect({ | ||
93 | + selectableHeader: "<input type='text' class='search-input category-search-users' autocomplete='off' placeholder=' '>", | ||
94 | + selectionHeader: "<input type='text' class='search-input category-search-users' autocomplete='off' placeholder=''>", | ||
95 | + afterInit: function(ms){ | ||
96 | + var that = this, | ||
97 | + $selectableSearch = that.$selectableUl.prev(), | ||
98 | + $selectionSearch = that.$selectionUl.prev(), | ||
99 | + selectableSearchString = '#'+that.$container.attr('id')+' .ms-elem-selectable:not(.ms-selected)', | ||
100 | + selectionSearchString = '#'+that.$container.attr('id')+' .ms-elem-selection.ms-selected'; | ||
101 | + | ||
102 | + that.qs1 = $selectableSearch.quicksearch(selectableSearchString) | ||
103 | + .on('keydown', function(e){ | ||
104 | + if (e.which === 40){ | ||
105 | + that.$selectableUl.focus(); | ||
106 | + return false; | ||
107 | + } | ||
108 | + }); | ||
109 | + | ||
110 | + that.qs2 = $selectionSearch.quicksearch(selectionSearchString) | ||
111 | + .on('keydown', function(e){ | ||
112 | + if (e.which == 40){ | ||
113 | + that.$selectionUl.focus(); | ||
114 | + return false; | ||
115 | + } | ||
116 | + }); | ||
117 | + }, | ||
118 | + afterSelect: function(){ | ||
119 | + this.qs1.cache(); | ||
120 | + this.qs2.cache(); | ||
121 | + }, | ||
122 | + afterDeselect: function(){ | ||
123 | + this.qs1.cache(); | ||
124 | + this.qs2.cache(); | ||
125 | + } | ||
126 | + });// Used to create multi-select css style | ||
127 | + | ||
128 | + $('#id_students').multiSelect({ | ||
129 | + selectableHeader: "<input type='text' class='search-input category-search-users' autocomplete='off' placeholder=' '>", | ||
130 | + selectionHeader: "<input type='text' class='search-input category-search-users' autocomplete='off' placeholder=''>", | ||
131 | + afterInit: function(ms){ | ||
132 | + var that = this, | ||
133 | + $selectableSearch = that.$selectableUl.prev(), | ||
134 | + $selectionSearch = that.$selectionUl.prev(), | ||
135 | + selectableSearchString = '#'+that.$container.attr('id')+' .ms-elem-selectable:not(.ms-selected)', | ||
136 | + selectionSearchString = '#'+that.$container.attr('id')+' .ms-elem-selection.ms-selected'; | ||
137 | + | ||
138 | + that.qs1 = $selectableSearch.quicksearch(selectableSearchString) | ||
139 | + .on('keydown', function(e){ | ||
140 | + if (e.which === 40){ | ||
141 | + that.$selectableUl.focus(); | ||
142 | + return false; | ||
143 | + } | ||
144 | + }); | ||
145 | + | ||
146 | + that.qs2 = $selectionSearch.quicksearch(selectionSearchString) | ||
147 | + .on('keydown', function(e){ | ||
148 | + if (e.which == 40){ | ||
149 | + that.$selectionUl.focus(); | ||
150 | + return false; | ||
151 | + } | ||
152 | + }); | ||
153 | + }, | ||
154 | + afterSelect: function(){ | ||
155 | + this.qs1.cache(); | ||
156 | + this.qs2.cache(); | ||
157 | + }, | ||
158 | + afterDeselect: function(){ | ||
159 | + this.qs1.cache(); | ||
160 | + this.qs2.cache(); | ||
161 | + } | ||
162 | + });// Used to create multi-select css style | ||
163 | + | ||
164 | + $('.collapse').on('show.bs.collapse', function (e) { | ||
165 | + if($(this).is(e.target)){ | ||
166 | + var btn = $(this).parent().find('.fa-angle-right'); | ||
167 | + | ||
168 | + btn.switchClass("fa-angle-right", "fa-angle-down", 250, "easeInOutQuad"); | ||
169 | + } | ||
170 | + }); | ||
171 | + | ||
172 | + $('.collapse').on('hide.bs.collapse', function (e) { | ||
173 | + if($(this).is(e.target)){ | ||
174 | + var btn = $(this).parent().find('.fa-angle-down'); | ||
175 | + | ||
176 | + btn.switchClass("fa-angle-down", "fa-angle-right", 250, "easeInOutQuad"); | ||
177 | + } | ||
178 | + }); | ||
179 | +</script> | ||
0 | \ No newline at end of file | 180 | \ No newline at end of file |
subjects/templates/subjects/create.html
1 | {% extends 'categories/home.html' %} | 1 | {% extends 'categories/home.html' %} |
2 | 2 | ||
3 | -{% load widget_tweaks static i18n permission_tags django_bootstrap_breadcrumbs switchevenodd %} | 3 | +{% load static i18n django_bootstrap_breadcrumbs switchevenodd %} |
4 | 4 | ||
5 | {% block style %} | 5 | {% block style %} |
6 | - | ||
7 | {{block.super}} | 6 | {{block.super}} |
8 | <link rel="stylesheet" type="text/css" href="{% static "css/bootstrap-tagsinput.css" %}"> | 7 | <link rel="stylesheet" type="text/css" href="{% static "css/bootstrap-tagsinput.css" %}"> |
9 | - | ||
10 | - | ||
11 | -{% endblock style %} | 8 | +{% endblock %} |
12 | 9 | ||
13 | {% block javascript %} | 10 | {% block javascript %} |
14 | {{block.super}} | 11 | {{block.super}} |
15 | <script type="text/javascript" src="{% static "js/bootstrap-tagsinput.js" %} "></script> | 12 | <script type="text/javascript" src="{% static "js/bootstrap-tagsinput.js" %} "></script> |
16 | - | ||
17 | -{% endblock javascript %} | 13 | +{% endblock %} |
18 | 14 | ||
19 | {% block breadcrumbs %} | 15 | {% block breadcrumbs %} |
20 | {% clear_breadcrumbs %} | 16 | {% clear_breadcrumbs %} |
@@ -25,190 +21,12 @@ | @@ -25,190 +21,12 @@ | ||
25 | {% endblock %} | 21 | {% endblock %} |
26 | 22 | ||
27 | {% block content %} | 23 | {% block content %} |
28 | - | ||
29 | <div class="card card-content"> | 24 | <div class="card card-content"> |
30 | <div class="card-body"> | 25 | <div class="card-body"> |
31 | - <form method="post" action="" enctype="multipart/form-data"> | ||
32 | - {% csrf_token %} | ||
33 | - {% for field in form %} | ||
34 | - {% if field.auto_id == 'id_students' %} | ||
35 | - <div class="panel-group" id="coordinators_accordion" role="tablist" aria-multiselectable="true"> | ||
36 | - <div class="panel panel-info"> | ||
37 | - <div class="panel-heading"> | ||
38 | - <div class="row"> | ||
39 | - <div class="col-md-12"> | ||
40 | - <a data-parent="#coordinators_accordion" data-toggle="collapse" href="#students"> | ||
41 | - <h4 class="panel-title"> | ||
42 | - <button class="btn btn-default btn-xs text-center cat-selector"><i class="fa fa-angle-right fa-2x" aria-hidden="true"></i></button><label for="{{ field.auto_id }}">{{ field.label }}</label> | ||
43 | - </h4> | ||
44 | - </a> | ||
45 | - </div> | ||
46 | - </div> | ||
47 | - </div> | ||
48 | - <div id="students" class="panel-collapse collapse"> | ||
49 | - <p><em>{% trans 'Attribute students to subject' %}:</em></p> | ||
50 | - {% render_field field class='form-control' %} | ||
51 | - </div> | ||
52 | - </div> | ||
53 | - </div> | ||
54 | - {% elif field.auto_id == 'id_professor' %} | ||
55 | - <div class="panel-group" id="professors_accordion" role="tablist" aria-multiselectable="true"> | ||
56 | - <div class="panel panel-info"> | ||
57 | - <div class="panel-heading"> | ||
58 | - <div class="row"> | ||
59 | - <div class="col-md-12"> | ||
60 | - <a data-parent="#professors_accordion" data-toggle="collapse" href="#professors"> | ||
61 | - <h4 class="panel-title"> | ||
62 | - <button class="btn btn-default btn-xs text-center cat-selector"><i class="fa fa-angle-right fa-2x" aria-hidden="true"></i></button><label for="{{ field.auto_id }}">{{ field.label }}</label> | ||
63 | - </h4> | ||
64 | - </a> | ||
65 | - </div> | ||
66 | - </div> | ||
67 | - </div> | ||
68 | - <div id="professors" class="panel-collapse collapse"> | ||
69 | - <p><em>{% trans 'Attribute professors to subject' %}:</em></p> | ||
70 | - {% render_field field class='form-control' %} | ||
71 | - </div> | ||
72 | - </div> | ||
73 | - </div> | ||
74 | - {% elif field.auto_id == 'id_markers'%} | ||
75 | - <label> {{field.label}} </label> | ||
76 | - {% render_field field class='form-control' data-role="tagsinput" %} | ||
77 | - {% else %} | ||
78 | - <div class="form-group {% if form.has_error %} has-error {% endif %} is-fileinput"> | ||
79 | - {% if field.auto_id != 'id_visible' %} | ||
80 | - <label for="{{ field.auto_id }}">{{ field.label }}</label> | ||
81 | - {% endif %} | ||
82 | - {% if field.auto_id == 'id_visible' %} | ||
83 | - <div class="checkbox"> | ||
84 | - <label for="{{ field.auto_id }}"> | ||
85 | - {% render_field field %} {{field.label}} | ||
86 | - </label> | ||
87 | - </div> | ||
88 | - {% elif field.auto_id == 'id_description' or field.auto_id == 'id_description_brief' %} | ||
89 | - {% render_field field class='form-control text_wysiwyg' %} | ||
90 | - {% else %} | ||
91 | - {% render_field field class='form-control' %} | ||
92 | - {% endif %} | ||
93 | - <span class="help-block">{{ field.help_text }}</span> | ||
94 | - {% if field.errors %} | ||
95 | - <div class="row"> | ||
96 | - </br> | ||
97 | - <div class="alert alert-danger alert-dismissible" role="alert"> | ||
98 | - <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
99 | - <span aria-hidden="true">×</span> | ||
100 | - </button> | ||
101 | - <ul> | ||
102 | - {% for error in field.errors %} | ||
103 | - <li>{{ error }}</li> | ||
104 | - {% endfor %} | ||
105 | - </ul> | ||
106 | - </div> | ||
107 | - </div> | ||
108 | - {% endif %} | ||
109 | - </div> | ||
110 | - {% endif %} | ||
111 | - | ||
112 | - {% endfor %} | ||
113 | - <div class="row text-center"> | ||
114 | - <input type="submit" value="{% trans 'Save' %}" class="btn btn-primary btn-raised" /> | 26 | + {% include 'subjects/_form.html' %} |
115 | </div> | 27 | </div> |
116 | - </form> | ||
117 | - </div> | ||
118 | </div> | 28 | </div> |
119 | <br clear="all" /> | 29 | <br clear="all" /> |
120 | <br clear="all" /> | 30 | <br clear="all" /> |
121 | - | ||
122 | - <script type="text/javascript"> | ||
123 | - $('#id_professor').multiSelect({ | ||
124 | - selectableHeader: "<input type='text' class='search-input category-search-users' autocomplete='off' placeholder=' '>", | ||
125 | - selectionHeader: "<input type='text' class='search-input category-search-users' autocomplete='off' placeholder=''>", | ||
126 | - afterInit: function(ms){ | ||
127 | - var that = this, | ||
128 | - $selectableSearch = that.$selectableUl.prev(), | ||
129 | - $selectionSearch = that.$selectionUl.prev(), | ||
130 | - selectableSearchString = '#'+that.$container.attr('id')+' .ms-elem-selectable:not(.ms-selected)', | ||
131 | - selectionSearchString = '#'+that.$container.attr('id')+' .ms-elem-selection.ms-selected'; | ||
132 | - | ||
133 | - that.qs1 = $selectableSearch.quicksearch(selectableSearchString) | ||
134 | - .on('keydown', function(e){ | ||
135 | - if (e.which === 40){ | ||
136 | - that.$selectableUl.focus(); | ||
137 | - return false; | ||
138 | - } | ||
139 | - }); | ||
140 | - | ||
141 | - that.qs2 = $selectionSearch.quicksearch(selectionSearchString) | ||
142 | - .on('keydown', function(e){ | ||
143 | - if (e.which == 40){ | ||
144 | - that.$selectionUl.focus(); | ||
145 | - return false; | ||
146 | - } | ||
147 | - }); | ||
148 | - }, | ||
149 | - afterSelect: function(){ | ||
150 | - this.qs1.cache(); | ||
151 | - this.qs2.cache(); | ||
152 | - }, | ||
153 | - afterDeselect: function(){ | ||
154 | - this.qs1.cache(); | ||
155 | - this.qs2.cache(); | ||
156 | - } | ||
157 | - });// Used to create multi-select css style | ||
158 | - | ||
159 | - $('#id_students').multiSelect({ | ||
160 | - selectableHeader: "<input type='text' class='search-input category-search-users' autocomplete='off' placeholder=' '>", | ||
161 | - selectionHeader: "<input type='text' class='search-input category-search-users' autocomplete='off' placeholder=''>", | ||
162 | - afterInit: function(ms){ | ||
163 | - var that = this, | ||
164 | - $selectableSearch = that.$selectableUl.prev(), | ||
165 | - $selectionSearch = that.$selectionUl.prev(), | ||
166 | - selectableSearchString = '#'+that.$container.attr('id')+' .ms-elem-selectable:not(.ms-selected)', | ||
167 | - selectionSearchString = '#'+that.$container.attr('id')+' .ms-elem-selection.ms-selected'; | ||
168 | - | ||
169 | - that.qs1 = $selectableSearch.quicksearch(selectableSearchString) | ||
170 | - .on('keydown', function(e){ | ||
171 | - if (e.which === 40){ | ||
172 | - that.$selectableUl.focus(); | ||
173 | - return false; | ||
174 | - } | ||
175 | - }); | ||
176 | - | ||
177 | - that.qs2 = $selectionSearch.quicksearch(selectionSearchString) | ||
178 | - .on('keydown', function(e){ | ||
179 | - if (e.which == 40){ | ||
180 | - that.$selectionUl.focus(); | ||
181 | - return false; | ||
182 | - } | ||
183 | - }); | ||
184 | - }, | ||
185 | - afterSelect: function(){ | ||
186 | - this.qs1.cache(); | ||
187 | - this.qs2.cache(); | ||
188 | - }, | ||
189 | - afterDeselect: function(){ | ||
190 | - this.qs1.cache(); | ||
191 | - this.qs2.cache(); | ||
192 | - } | ||
193 | - });// Used to create multi-select css style | ||
194 | - | ||
195 | - $('.collapse').on('show.bs.collapse', function (e) { | ||
196 | - if($(this).is(e.target)){ | ||
197 | - var btn = $(this).parent().find('.fa-angle-right'); | ||
198 | - | ||
199 | - btn.switchClass("fa-angle-right", "fa-angle-down", 250, "easeInOutQuad"); | ||
200 | - } | ||
201 | - }); | ||
202 | - | ||
203 | - $('.collapse').on('hide.bs.collapse', function (e) { | ||
204 | - if($(this).is(e.target)){ | ||
205 | - var btn = $(this).parent().find('.fa-angle-down'); | ||
206 | - | ||
207 | - btn.switchClass("fa-angle-down", "fa-angle-right", 250, "easeInOutQuad"); | ||
208 | - } | ||
209 | - }); | ||
210 | - | ||
211 | - | ||
212 | - </script> | ||
213 | -{% endblock content %} | 31 | +{% endblock %} |
214 | 32 |
subjects/templates/subjects/subject_card.html
1 | {% load static i18n permission_tags %} | 1 | {% load static i18n permission_tags %} |
2 | {% if subject.visible %} | 2 | {% if subject.visible %} |
3 | - | ||
4 | - | ||
5 | - | ||
6 | - | ||
7 | -<script type="text/javascript" src="{% static "subjects/js/subjects_card.js" %} "></script> | ||
8 | - | ||
9 | -<div class="panel panel-info subject-panel"> | ||
10 | - <div class="panel-heading"> | ||
11 | - | ||
12 | - | ||
13 | - | ||
14 | - <div class="row"> | ||
15 | - <div class="col-md-12 category-header"> | ||
16 | - <h4 class="panel-title"> | ||
17 | - <a class="category-course-link pull-left" data-parent="#{% if accordion_id %}{{ accordion_id }}{% else %}{{ subject.category.slug }}-accordion{% endif %}" data-toggle="collapse" href="#{{subject.slug}}"> | ||
18 | - <button class="btn btn-default btn-xs text-center cat-selector"><i class="fa fa-angle-right fa-2x" aria-hidden="true"></i></button> {{subject.name}} | ||
19 | - </a> | ||
20 | - </h4> | ||
21 | - | ||
22 | - <div class="col-md-5 pull-right category-card-items"> | ||
23 | - {% if request.user in subject.professor.all or request.user in category.coordinators.all or request.user.is_staff %} | ||
24 | - <a href="" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ||
25 | - <i class="fa fa-ellipsis-v" aria-hidden="true"></i> | 3 | + <div class="panel panel-info subject-panel"> |
4 | + <div class="panel-heading"> | ||
5 | + <div class="row"> | ||
6 | + <div class="col-md-12 category-header"> | ||
7 | + <h4 class="panel-title"> | ||
8 | + <a class="category-course-link pull-left" data-parent="#{% if accordion_id %}{{ accordion_id }}{% else %}{{ subject.category.slug }}-accordion{% endif %}" data-toggle="collapse" href="#{{subject.slug}}"> | ||
9 | + <button class="btn btn-default btn-xs text-center cat-selector"><i class="fa fa-angle-right fa-2x" aria-hidden="true"></i></button> {{subject.name}} | ||
26 | </a> | 10 | </a> |
27 | - <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> | ||
28 | - <li><a href="{% url 'subjects:replicate' subject.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> | ||
29 | - <li><a href="{% url 'subjects:update' subject.slug %}"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> | ||
30 | - <li><a href="javascript:delete_subject.get('{% url 'subjects:delete' subject.slug %}','#subject','#modal_subject')"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> | ||
31 | - </ul> | ||
32 | - {% endif %} | ||
33 | - <a href="" ><i class="fa fa-list" aria-hidden="true"></i></a> | ||
34 | - <a href=""><i class="fa fa-envelope-o" aria-hidden="true"></i></a> | ||
35 | - <a href=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></a> | ||
36 | - <a href=""><i class="fa fa-bar-chart" aria-hidden="true"></i></a> | ||
37 | - </div> | ||
38 | - </div> | ||
39 | - </div> | ||
40 | - </div> | ||
41 | - <div id="{{subject.slug}}" class="panel-collapse collapse category-panel-content"> | ||
42 | - <div class="row"> | ||
43 | - <div class="col-md-6"> | ||
44 | - {% if subject.professor.all|length > 0 %} | ||
45 | - <h4><b>{% trans "Professors(s) " %}: </b> | ||
46 | - {{ subject.professor.all|join:', ' }} | ||
47 | </h4> | 11 | </h4> |
48 | - {% else %} | ||
49 | - <h4> {% trans "It doesn't possess professors" %} </h4> | ||
50 | - {% endif %} | ||
51 | - </div> | ||
52 | - <div class="col-xs-6 col-md-3"> | ||
53 | - <p><b>{% trans "Beginning" %}:</b> {{subject.init_date}}</p> | ||
54 | - </div> | ||
55 | - <div class="col-xs-6 col-md-3"> | ||
56 | - <p><b>{% trans "End" %}:</b> {{subject.end_date}}</p> | 12 | + |
13 | + <div class="col-md-5 pull-right category-card-items"> | ||
14 | + {% if request.user in subject.professor.all or request.user in category.coordinators.all or request.user.is_staff %} | ||
15 | + <a href="" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ||
16 | + <i class="fa fa-ellipsis-v" aria-hidden="true"></i> | ||
17 | + </a> | ||
18 | + <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> | ||
19 | + <li><a href="{% url 'subjects:replicate' subject.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> | ||
20 | + <li><a href="{% url 'subjects:update' subject.slug %}"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> | ||
21 | + <li><a href="javascript:delete_subject.get('{% url 'subjects:delete' subject.slug %}','#subject','#modal_subject')"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> | ||
22 | + </ul> | ||
23 | + {% endif %} | ||
24 | + <a href="" ><i class="fa fa-list" aria-hidden="true"></i></a> | ||
25 | + <a href=""><i class="fa fa-envelope-o" aria-hidden="true"></i></a> | ||
26 | + <a href=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></a> | ||
27 | + <a href=""><i class="fa fa-bar-chart" aria-hidden="true"></i></a> | ||
28 | + </div> | ||
29 | + </div> | ||
57 | </div> | 30 | </div> |
58 | </div> | 31 | </div> |
59 | - | ||
60 | - <p>{{subject.description_brief|safe}}</p> | ||
61 | - | ||
62 | - {% if request.user in subject.students.all or request.user in subject.professor.all or request.user.is_staff or request.user in category.coordinators.all %} | ||
63 | - <a href="#"><button class="access-subject"> {% trans "Access Subject" %}</button></a> | ||
64 | - {% else %} | ||
65 | - <a href=""><button class="subscribe-subject"> {% trans "Subscribe to Subject" %}</button></a> | ||
66 | - {% endif %} | ||
67 | - </div> | ||
68 | -</div> | ||
69 | - {% elif request.user in subject.professor.all or request.user in category.coordinators.all %} | ||
70 | -<div class="panel panel-info subject-panel-invisible"> | ||
71 | - <div class="panel-heading panel-invisible"> | ||
72 | - | ||
73 | - | ||
74 | - | ||
75 | - <div class="row"> | ||
76 | - <div class="col-md-12 category-header"> | ||
77 | - <h4 class="panel-title"> | ||
78 | - <a class="category-course-link pull-left" data-parent="#{% if accordion_id %}{{ accordion_id }}{% else %}{{ subject.category.slug }}-accordion{% endif %}" data-toggle="collapse" href="#{{subject.slug}}"> | ||
79 | - <button class="btn btn-default btn-xs text-center cat-selector"><i class="fa fa-angle-right fa-2x" aria-hidden="true"></i></button> {{subject.name}} | ||
80 | - </a> | ||
81 | - </h4> | ||
82 | - | ||
83 | - <div class="col-md-5 pull-right category-card-items"> | ||
84 | - {% if request.user in subject.professor.all or request.user in category.coordinators.all or request.user.is_staff %} | ||
85 | - <a href="" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ||
86 | - <i class="fa fa-ellipsis-v" aria-hidden="true"></i> | ||
87 | - </a> | ||
88 | - <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> | ||
89 | - <li><a href="{% url 'subjects:replicate' subject.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> | ||
90 | - <li><a href="{% url 'subjects:update' subject.slug %}"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> | ||
91 | - <li><a href="#"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> | ||
92 | - </ul> | 32 | + <div id="{{subject.slug}}" class="panel-collapse collapse category-panel-content"> |
33 | + <div class="row"> | ||
34 | + <div class="col-md-6"> | ||
35 | + {% if subject.professor.all|length > 0 %} | ||
36 | + <h4><b>{% trans "Professors(s) " %}: </b> | ||
37 | + {{ subject.professor.all|join:', ' }} | ||
38 | + </h4> | ||
39 | + {% else %} | ||
40 | + <h4> {% trans "It doesn't possess professors" %} </h4> | ||
93 | {% endif %} | 41 | {% endif %} |
94 | - <a href="" ><i class="fa fa-list" aria-hidden="true"></i></a> | ||
95 | - <a href=""><i class="fa fa-envelope-o" aria-hidden="true"></i></a> | ||
96 | - <a href=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></a> | ||
97 | - <a href=""><i class="fa fa-bar-chart" aria-hidden="true"></i></a> | 42 | + </div> |
43 | + <div class="col-xs-6 col-md-3"> | ||
44 | + <p><b>{% trans "Beginning" %}:</b> {{subject.init_date}}</p> | ||
45 | + </div> | ||
46 | + <div class="col-xs-6 col-md-3"> | ||
47 | + <p><b>{% trans "End" %}:</b> {{subject.end_date}}</p> | ||
98 | </div> | 48 | </div> |
99 | </div> | 49 | </div> |
50 | + | ||
51 | + <p>{{subject.description_brief|safe}}</p> | ||
52 | + | ||
53 | + {% if request.user in subject.students.all or request.user in subject.professor.all or request.user.is_staff or request.user in category.coordinators.all %} | ||
54 | + <a href="#"><button class="access-subject"> {% trans "Access Subject" %}</button></a> | ||
55 | + {% else %} | ||
56 | + <a href="#"><button class="subscribe-subject"> {% trans "Subscribe to Subject" %}</button></a> | ||
57 | + {% endif %} | ||
100 | </div> | 58 | </div> |
101 | </div> | 59 | </div> |
102 | - <div id="{{subject.slug}}" class="panel-collapse collapse category-panel-content"> | ||
103 | - <div class="row"> | ||
104 | - <div class="col-md-6"> | ||
105 | - {% if subject.professor.all|length > 0 %} | ||
106 | - <h4><b>{% trans "Professors(s) " %}: </b> | ||
107 | - {{ subject.professor.all|join:', ' }} | 60 | +{% elif request.user in subject.professor.all or request.user in category.coordinators.all %} |
61 | + <div class="panel panel-info subject-panel-invisible"> | ||
62 | + <div class="panel-heading panel-invisible"> | ||
63 | + <div class="row"> | ||
64 | + <div class="col-md-12 category-header"> | ||
65 | + <h4 class="panel-title"> | ||
66 | + <a class="category-course-link pull-left" data-parent="#{% if accordion_id %}{{ accordion_id }}{% else %}{{ subject.category.slug }}-accordion{% endif %}" data-toggle="collapse" href="#{{subject.slug}}"> | ||
67 | + <button class="btn btn-default btn-xs text-center cat-selector"><i class="fa fa-angle-right fa-2x" aria-hidden="true"></i></button> {{subject.name}} | ||
68 | + </a> | ||
108 | </h4> | 69 | </h4> |
109 | - {% else %} | ||
110 | - <h4> {% trans "It doesn't possess professors" %} </h4> | ||
111 | - {% endif %} | ||
112 | - </div> | ||
113 | - <div class="col-xs-6 col-md-3"> | ||
114 | - <p><b>{% trans "Beginning" %}:</b> {{subject.init_date}}</p> | ||
115 | - </div> | ||
116 | - <div class="col-xs-6 col-md-3"> | ||
117 | - <p><b>{% trans "End" %}:</b> {{subject.end_date}}</p> | 70 | + |
71 | + <div class="col-md-5 pull-right category-card-items"> | ||
72 | + {% if request.user in subject.professor.all or request.user in category.coordinators.all or request.user.is_staff %} | ||
73 | + <a href="" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ||
74 | + <i class="fa fa-ellipsis-v" aria-hidden="true"></i> | ||
75 | + </a> | ||
76 | + <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> | ||
77 | + <li><a href="{% url 'subjects:replicate' subject.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> | ||
78 | + <li><a href="{% url 'subjects:update' subject.slug %}"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> | ||
79 | + <li><a href="javascript:delete_subject.get('{% url 'subjects:delete' subject.slug %}','#subject','#modal_subject')"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> | ||
80 | + </ul> | ||
81 | + {% endif %} | ||
82 | + <a href="" ><i class="fa fa-list" aria-hidden="true"></i></a> | ||
83 | + <a href=""><i class="fa fa-envelope-o" aria-hidden="true"></i></a> | ||
84 | + <a href=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></a> | ||
85 | + <a href=""><i class="fa fa-bar-chart" aria-hidden="true"></i></a> | ||
86 | + </div> | ||
87 | + </div> | ||
118 | </div> | 88 | </div> |
119 | </div> | 89 | </div> |
90 | + <div id="{{subject.slug}}" class="panel-collapse collapse category-panel-content"> | ||
91 | + <div class="row"> | ||
92 | + <div class="col-md-6"> | ||
93 | + {% if subject.professor.all|length > 0 %} | ||
94 | + <h4><b>{% trans "Professors(s) " %}: </b> | ||
95 | + {{ subject.professor.all|join:', ' }} | ||
96 | + </h4> | ||
97 | + {% else %} | ||
98 | + <h4> {% trans "It doesn't possess professors" %} </h4> | ||
99 | + {% endif %} | ||
100 | + </div> | ||
101 | + <div class="col-xs-6 col-md-3"> | ||
102 | + <p><b>{% trans "Beginning" %}:</b> {{subject.init_date}}</p> | ||
103 | + </div> | ||
104 | + <div class="col-xs-6 col-md-3"> | ||
105 | + <p><b>{% trans "End" %}:</b> {{subject.end_date}}</p> | ||
106 | + </div> | ||
107 | + </div> | ||
120 | 108 | ||
121 | - <p>{{subject.description_brief|safe}}</p> | ||
122 | - | ||
123 | - {% if request.user in subject.students.all or request.user in subject.professor.all or request.user.is_staff or request.user in category.coordinators.all %} | ||
124 | - <a href="#"><button class="access-subject"> {% trans "Access Subject" %}</button></a> | ||
125 | - {% else %} | ||
126 | - <a href="#"><button class="subscribe-subject"> {% trans "Subscribe to Subject" %}</button></a> | ||
127 | - {% endif %} | 109 | + <p>{{subject.description_brief|safe}}</p> |
110 | + | ||
111 | + {% if request.user in subject.students.all or request.user in subject.professor.all or request.user.is_staff or request.user in category.coordinators.all %} | ||
112 | + <a href="#"><button class="access-subject"> {% trans "Access Subject" %}</button></a> | ||
113 | + {% else %} | ||
114 | + <a href="#"><button class="subscribe-subject"> {% trans "Subscribe to Subject" %}</button></a> | ||
115 | + {% endif %} | ||
116 | + </div> | ||
128 | </div> | 117 | </div> |
129 | -</div> | ||
130 | {% endif %} | 118 | {% endif %} |
131 | \ No newline at end of file | 119 | \ No newline at end of file |
subjects/templates/subjects/update.html
1 | -{% extends template_extends %} | 1 | +{% extends 'categories/home.html' %} |
2 | 2 | ||
3 | {% load static i18n %} | 3 | {% load static i18n %} |
4 | {% load widget_tweaks django_bootstrap_breadcrumbs %} | 4 | {% load widget_tweaks django_bootstrap_breadcrumbs %} |
5 | 5 | ||
6 | +{% block style %} | ||
7 | + {{block.super}} | ||
8 | + <link rel="stylesheet" type="text/css" href="{% static "css/bootstrap-tagsinput.css" %}"> | ||
9 | +{% endblock %} | ||
10 | + | ||
11 | +{% block javascript %} | ||
12 | + {{block.super}} | ||
13 | + <script type="text/javascript" src="{% static "js/bootstrap-tagsinput.js" %} "></script> | ||
14 | +{% endblock %} | ||
15 | + | ||
6 | {% block breadcrumbs %} | 16 | {% block breadcrumbs %} |
7 | {{ block.super }} | 17 | {{ block.super }} |
8 | {% with 'Update '|add:object.slug as bread_slug %} | 18 | {% with 'Update '|add:object.slug as bread_slug %} |
9 | {% breadcrumb bread_slug 'subjects:update' %} | 19 | {% breadcrumb bread_slug 'subjects:update' %} |
10 | {% endwith %} | 20 | {% endwith %} |
11 | -{% endblock breadcrumbs %} | 21 | +{% endblock %} |
12 | 22 | ||
13 | {% block content %} | 23 | {% block content %} |
14 | <div class="card card-content"> | 24 | <div class="card card-content"> |
15 | <div class="card-body"> | 25 | <div class="card-body"> |
16 | - <form method="post" action="" enctype="multipart/form-data"> | ||
17 | - {% csrf_token %} | ||
18 | - {% for field in form %} | ||
19 | - {% if field.auto_id == 'id_students' %} | ||
20 | - <div class="panel-group" id="coordinators_accordion" role="tablist" aria-multiselectable="true"> | ||
21 | - <div class="panel panel-info"> | ||
22 | - <div class="panel-heading"> | ||
23 | - <div class="row"> | ||
24 | - <div class="col-md-12"> | ||
25 | - <a data-parent="#coordinators_accordion" data-toggle="collapse" href="#students"> | ||
26 | - <h4 class="panel-title"> | ||
27 | - <button class="btn btn-default btn-xs text-center cat-selector"><i class="fa fa-angle-right fa-2x" aria-hidden="true"></i></button><label for="{{ field.auto_id }}">{{ field.label }}</label> | ||
28 | - </h4> | ||
29 | - </a> | ||
30 | - </div> | ||
31 | - </div> | ||
32 | - </div> | ||
33 | - <div id="students" class="panel-collapse collapse"> | ||
34 | - <p><em>{% trans 'Attribute students to subject' %}:</em></p> | ||
35 | - {% render_field field class='form-control' %} | ||
36 | - </div> | ||
37 | - </div> | ||
38 | - </div> | ||
39 | - {% elif field.auto_id == 'id_professor' %} | ||
40 | - <div class="panel-group" id="professors_accordion" role="tablist" aria-multiselectable="true"> | ||
41 | - <div class="panel panel-info"> | ||
42 | - <div class="panel-heading"> | ||
43 | - <div class="row"> | ||
44 | - <div class="col-md-12"> | ||
45 | - <a data-parent="#professors_accordion" data-toggle="collapse" href="#professors"> | ||
46 | - <h4 class="panel-title"> | ||
47 | - <button class="btn btn-default btn-xs text-center cat-selector"><i class="fa fa-angle-right fa-2x" aria-hidden="true"></i></button><label for="{{ field.auto_id }}">{{ field.label }}</label> | ||
48 | - </h4> | ||
49 | - </a> | ||
50 | - </div> | ||
51 | - </div> | ||
52 | - </div> | ||
53 | - <div id="professors" class="panel-collapse collapse"> | ||
54 | - <p><em>{% trans 'Attribute professors to subject' %}:</em></p> | ||
55 | - {% render_field field class='form-control' %} | ||
56 | - </div> | ||
57 | - </div> | ||
58 | - </div> | ||
59 | - {% elif field.auto_id == 'id_markers'%} | ||
60 | - <label> {{field.label}} </label> | ||
61 | - {% render_field field class='form-control' data-role="tagsinput" %} | ||
62 | - {% else %} | ||
63 | - <div class="form-group {% if form.has_error %} has-error {% endif %} is-fileinput"> | ||
64 | - {% if field.auto_id != 'id_visible' %} | ||
65 | - <label for="{{ field.auto_id }}">{{ field.label }}</label> | ||
66 | - {% endif %} | ||
67 | - {% if field.auto_id == 'id_visible' %} | ||
68 | - <div class="checkbox"> | ||
69 | - <label for="{{ field.auto_id }}"> | ||
70 | - {% render_field field %} {{field.label}} | ||
71 | - </label> | ||
72 | - </div> | ||
73 | - {% elif field.auto_id == 'id_description' or field.auto_id == 'id_description_brief' %} | ||
74 | - {% render_field field class='form-control text_wysiwyg' %} | ||
75 | - {% else %} | ||
76 | - {% render_field field class='form-control' %} | ||
77 | - {% endif %} | ||
78 | - <span class="help-block">{{ field.help_text }}</span> | ||
79 | - {% if field.errors %} | ||
80 | - <div class="row"> | ||
81 | - </br> | ||
82 | - <div class="alert alert-danger alert-dismissible" role="alert"> | ||
83 | - <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
84 | - <span aria-hidden="true">×</span> | ||
85 | - </button> | ||
86 | - <ul> | ||
87 | - {% for error in field.errors %} | ||
88 | - <li>{{ error }}</li> | ||
89 | - {% endfor %} | ||
90 | - </ul> | ||
91 | - </div> | ||
92 | - </div> | ||
93 | - {% endif %} | ||
94 | - </div> | ||
95 | - {% endif %} | ||
96 | - | ||
97 | - {% endfor %} | ||
98 | - <div class="row text-center"> | ||
99 | - <input type="submit" value="{% trans 'Save' %}" class="btn btn-primary btn-raised" /> | 26 | + {% include 'subjects/_form.html' %} |
100 | </div> | 27 | </div> |
101 | - </form> | ||
102 | - </div> | ||
103 | </div> | 28 | </div> |
104 | <br clear="all" /> | 29 | <br clear="all" /> |
105 | <br clear="all" /> | 30 | <br clear="all" /> |
106 | - | ||
107 | {% endblock %} | 31 | {% endblock %} |
108 | \ No newline at end of file | 32 | \ No newline at end of file |
subjects/views.py
@@ -138,8 +138,6 @@ class SubjectCreateView(CreateView): | @@ -138,8 +138,6 @@ class SubjectCreateView(CreateView): | ||
138 | initial['end_date'] = subject.end_date | 138 | initial['end_date'] = subject.end_date |
139 | initial['students'] = subject.students.all() | 139 | initial['students'] = subject.students.all() |
140 | initial['description_brief'] = subject.description_brief | 140 | initial['description_brief'] = subject.description_brief |
141 | - | ||
142 | - | ||
143 | 141 | ||
144 | return initial | 142 | return initial |
145 | 143 | ||
@@ -163,41 +161,42 @@ class SubjectCreateView(CreateView): | @@ -163,41 +161,42 @@ class SubjectCreateView(CreateView): | ||
163 | if self.kwargs.get('subject_slug'): | 161 | if self.kwargs.get('subject_slug'): |
164 | subject = get_object_or_404(Subject, slug = self.kwargs['subject_slug']) | 162 | subject = get_object_or_404(Subject, slug = self.kwargs['subject_slug']) |
165 | self.object.category = subject.category | 163 | self.object.category = subject.category |
166 | - self.object.save() | ||
167 | - | 164 | + self.object.save() |
168 | 165 | ||
169 | return super(SubjectCreateView, self).form_valid(form) | 166 | return super(SubjectCreateView, self).form_valid(form) |
170 | 167 | ||
171 | def get_success_url(self): | 168 | def get_success_url(self): |
169 | + | ||
172 | if not self.object.category.visible: | 170 | if not self.object.category.visible: |
173 | self.object.visible = False | 171 | self.object.visible = False |
174 | self.object.save() | 172 | self.object.save() |
175 | 173 | ||
174 | + | ||
176 | messages.success(self.request, _('Subject "%s" was registered on "%s" successfully!')%(self.object.name, self.object.category.name )) | 175 | messages.success(self.request, _('Subject "%s" was registered on "%s" successfully!')%(self.object.name, self.object.category.name )) |
177 | return reverse_lazy('subjects:index') | 176 | return reverse_lazy('subjects:index') |
178 | 177 | ||
179 | - | ||
180 | - | ||
181 | - | ||
182 | class SubjectUpdateView(LogMixin, UpdateView): | 178 | class SubjectUpdateView(LogMixin, UpdateView): |
183 | - | ||
184 | model = Subject | 179 | model = Subject |
185 | form_class = CreateSubjectForm | 180 | form_class = CreateSubjectForm |
186 | template_name = 'subjects/update.html' | 181 | template_name = 'subjects/update.html' |
187 | 182 | ||
188 | login_url = reverse_lazy("users:login") | 183 | login_url = reverse_lazy("users:login") |
189 | redirect_field_name = 'next' | 184 | redirect_field_name = 'next' |
185 | + | ||
190 | def get_context_data(self, **kwargs): | 186 | def get_context_data(self, **kwargs): |
191 | context = super(SubjectUpdateView, self).get_context_data(**kwargs) | 187 | context = super(SubjectUpdateView, self).get_context_data(**kwargs) |
192 | context['title'] = _('Update Subject') | 188 | context['title'] = _('Update Subject') |
193 | - context['template_extends'] = 'base.html' | 189 | + context['template_extends'] = 'categories/home.html' |
194 | context['subjects_menu_active'] = 'subjects_menu_active' | 190 | context['subjects_menu_active'] = 'subjects_menu_active' |
191 | + | ||
195 | return context | 192 | return context |
196 | 193 | ||
197 | def get_success_url(self): | 194 | def get_success_url(self): |
195 | + | ||
198 | if not self.object.category.visible: | 196 | if not self.object.category.visible: |
199 | self.object.visible = False | 197 | self.object.visible = False |
200 | self.object.save() | 198 | self.object.save() |
199 | + | ||
201 | 200 | ||
202 | messages.success(self.request, _('Subject "%s" was updated on "%s" successfully!')%(self.object.name, self.object.category.name )) | 201 | messages.success(self.request, _('Subject "%s" was updated on "%s" successfully!')%(self.object.name, self.object.category.name )) |
203 | return reverse_lazy('subjects:index') | 202 | return reverse_lazy('subjects:index') |