Commit fed1c8fc2262df5a31c38caf1ca7dd29e752e9e2
1 parent
a81d9d51
Exists in
master
and in
3 other branches
started building links app, createview and form
Showing
11 changed files
with
653 additions
and
20 deletions
Show diff stats
amadeus/settings.py
amadeus/urls.py
@@ -35,6 +35,7 @@ urlpatterns = [ | @@ -35,6 +35,7 @@ urlpatterns = [ | ||
35 | url(r'^security/', include('security.urls', namespace = 'security')), | 35 | url(r'^security/', include('security.urls', namespace = 'security')), |
36 | url(r'^themes/', include('themes.urls', namespace = 'themes')), | 36 | url(r'^themes/', include('themes.urls', namespace = 'themes')), |
37 | url(r'^notifications/', include('notifications.urls', namespace = 'notifications')), | 37 | url(r'^notifications/', include('notifications.urls', namespace = 'notifications')), |
38 | + url(r'^links/', include('links.urls', namespace='links')), | ||
38 | #API | 39 | #API |
39 | url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')), | 40 | url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')), |
40 | #S3Direct | 41 | #S3Direct |
@@ -0,0 +1,88 @@ | @@ -0,0 +1,88 @@ | ||
1 | +# coding=utf-8 | ||
2 | +from django import forms | ||
3 | +from django.utils.translation import ugettext_lazy as _ | ||
4 | +from django.utils.html import strip_tags | ||
5 | + | ||
6 | +from subjects.models import Tag | ||
7 | + | ||
8 | +from pendencies.forms import PendenciesForm | ||
9 | +from .models import Link | ||
10 | + | ||
11 | +class LinkForm(forms.ModelForm): | ||
12 | + subject = None | ||
13 | + MAX_UPLOAD_SIZE = 10*1024*1024 | ||
14 | + | ||
15 | + def __init__(self, *args, **kwargs): | ||
16 | + super(LinkForm, self).__init__(*args, **kwargs) | ||
17 | + | ||
18 | + self.subject = kwargs['initial'].get('subject', None) | ||
19 | + | ||
20 | + if self.instance.id: | ||
21 | + self.subject = self.instance.topic.subject | ||
22 | + self.initial['tags'] = ", ".join(self.instance.tags.all().values_list("name", flat = True)) | ||
23 | + | ||
24 | + self.fields['students'].queryset = self.subject.students.all() | ||
25 | + self.fields['groups'].queryset = self.subject.group_subject.all() | ||
26 | + | ||
27 | + tags = forms.CharField(label = _('Tags'), required = False) | ||
28 | + link_url = forms.URLField(label = _('Website URL'),required=True) | ||
29 | + class Meta: | ||
30 | + model = Link | ||
31 | + fields = ['name','link_url', 'initial_view','initial_view_date', 'end_view','end_view_date', 'brief_description', 'all_students', 'students', 'groups', 'visible'] | ||
32 | + labels = { | ||
33 | + 'name': _('Link name'), | ||
34 | + } | ||
35 | + widgets = { | ||
36 | + 'brief_description': forms.Textarea, | ||
37 | + 'students': forms.SelectMultiple, | ||
38 | + 'groups': forms.SelectMultiple, | ||
39 | + } | ||
40 | + | ||
41 | + def clean_name(self): | ||
42 | + name = self.cleaned_data.get('name', '') | ||
43 | + | ||
44 | + topics = self.subject.topic_subject.all() | ||
45 | + | ||
46 | + for topic in topics: | ||
47 | + if self.instance.id: | ||
48 | + same_name = topic.resource_topic.filter(name__unaccent__iexact = name).exclude(id = self.instance.id).count() | ||
49 | + else: | ||
50 | + same_name = topic.resource_topic.filter(name__unaccent__iexact = name).count() | ||
51 | + | ||
52 | + if same_name > 0: | ||
53 | + self._errors['name'] = [_('This subject already has a link with this name')] | ||
54 | + | ||
55 | + return ValueError | ||
56 | + | ||
57 | + return name | ||
58 | + | ||
59 | + | ||
60 | + | ||
61 | + def save(self, commit = True): | ||
62 | + super(LinkForm, self).save(commit = True) | ||
63 | + | ||
64 | + self.instance.save() | ||
65 | + | ||
66 | + previous_tags = self.instance.tags.all() | ||
67 | + | ||
68 | + tags = self.cleaned_data['tags'].split(",") | ||
69 | + | ||
70 | + #Excluding unwanted tags | ||
71 | + for prev in previous_tags: | ||
72 | + if not prev.name in tags: | ||
73 | + self.instance.tags.remove(prev) | ||
74 | + | ||
75 | + for tag in tags: | ||
76 | + tag = tag.strip() | ||
77 | + | ||
78 | + exist = Tag.objects.filter(name = tag).exists() | ||
79 | + | ||
80 | + if exist: | ||
81 | + new_tag = Tag.objects.get(name = tag) | ||
82 | + else: | ||
83 | + new_tag = Tag.objects.create(name = tag) | ||
84 | + | ||
85 | + if not new_tag in self.instance.tags.all(): | ||
86 | + self.instance.tags.add(new_tag) | ||
87 | + | ||
88 | + return self.instance | ||
0 | \ No newline at end of file | 89 | \ No newline at end of file |
links/models.py
1 | from django.db import models | 1 | from django.db import models |
2 | -from subject.models import Tag | 2 | +from django.utils.translation import ugettext_lazy as _ |
3 | +from autoslug.fields import AutoSlugField | ||
3 | 4 | ||
4 | -from topics.models import Topic | 5 | +import datetime |
6 | +from topics.models import Topic, Resource | ||
5 | from users.models import User | 7 | from users.models import User |
8 | +from django.utils import timezone | ||
6 | # Create your models here. | 9 | # Create your models here. |
7 | -class Link(models.Model): | ||
8 | - name = models.CharField( _("Name"), unique = True,max_length= 200) | ||
9 | - slug = AutoSlugField(_("Slug"),populate_from='name',unique=True) | 10 | +class Link(Resource): |
11 | + | ||
10 | 12 | ||
11 | - description_brief = models.TextField(_("simpler_description"), blank=True) | ||
12 | - description = models.TextField(_("description"), blank= True) | 13 | + description = models.TextField(_("simpler_description"), blank=True) |
13 | 14 | ||
14 | link_url = models.URLField(verbose_name = _("Link_URL")) | 15 | link_url = models.URLField(verbose_name = _("Link_URL")) |
15 | - | ||
16 | - tags = models.ManyToManyField(Tag, verbose_name='tags', blank=True, null=True) | ||
17 | - visible = models.BooleanField(_('Visible'), default = True) | ||
18 | - all_students = models.BooleanField(_('all_students'), default= False) | ||
19 | - students = models.ManyToManyField(User,verbose_name=_('Students'), related_name='students', blank = True) | ||
20 | - topic = models.ForeignKey(Topic, verbose_name='topic') | 16 | + |
21 | initial_view = models.BooleanField(_('Initial View'), default = False) | 17 | initial_view = models.BooleanField(_('Initial View'), default = False) |
22 | - initia_view_date = models.DateField(_('Initial View Date'), required= False) | 18 | + initial_view_date = models.DateField(_('Initial View Date'), default=timezone.now) |
19 | + end_view = models.BooleanField(_('Initial View'), default = False) | ||
20 | + end_view_date = models.DateField(_('Initial View Date'), default=timezone.now) | ||
23 | class Meta: | 21 | class Meta: |
24 | verbose_name = "Link" | 22 | verbose_name = "Link" |
25 | verbose_name_plural = "Links" | 23 | verbose_name_plural = "Links" |
@@ -0,0 +1,370 @@ | @@ -0,0 +1,370 @@ | ||
1 | +{% load static i18n %} | ||
2 | +{% load widget_tweaks %} | ||
3 | + | ||
4 | +<form method="post" action="" enctype="multipart/form-data"> | ||
5 | + {% csrf_token %} | ||
6 | + | ||
7 | + {% render_field form.control_subject %} | ||
8 | + | ||
9 | + <div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput"> | ||
10 | + <label for="{{ form.name.auto_id }}">{{ form.name.label }} <span>*</span></label> | ||
11 | + {% render_field form.name class='form-control' %} | ||
12 | + | ||
13 | + <span id="helpBlock" class="help-block">{{ form.name.help_text }}</span> | ||
14 | + | ||
15 | + {% if form.name.errors %} | ||
16 | + <div class="alert alert-danger alert-dismissible" role="alert"> | ||
17 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
18 | + <span aria-hidden="true">×</span> | ||
19 | + </button> | ||
20 | + <ul> | ||
21 | + {% for error in form.name.errors %} | ||
22 | + <li>{{ error }}</li> | ||
23 | + {% endfor %} | ||
24 | + </ul> | ||
25 | + </div> | ||
26 | + {% endif %} | ||
27 | + </div> | ||
28 | + | ||
29 | + <div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput"> | ||
30 | + <label for="{{ form.link_url.auto_id }}">{{ form.link_url.label }} <span>*</span></label> | ||
31 | + {% render_field form.link_url class='form-control' %} | ||
32 | + | ||
33 | + <span id="helpBlock" class="help-block">{{ form.link_url.help_text }}</span> | ||
34 | + | ||
35 | + {% if form.link_url.errors %} | ||
36 | + <div class="alert alert-danger alert-dismissible" role="alert"> | ||
37 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
38 | + <span aria-hidden="true">×</span> | ||
39 | + </button> | ||
40 | + <ul> | ||
41 | + {% for error in form.link_url.errors %} | ||
42 | + <li>{{ error }}</li> | ||
43 | + {% endfor %} | ||
44 | + </ul> | ||
45 | + </div> | ||
46 | + {% endif %} | ||
47 | + </div> | ||
48 | + | ||
49 | + | ||
50 | + <div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput"> | ||
51 | + <label for="{{ form.brief_description.auto_id }}">{{ form.brief_description.label }}</label> | ||
52 | + {% render_field form.brief_description class='form-control text_wysiwyg' %} | ||
53 | + | ||
54 | + <span id="helpBlock" class="help-block">{{ form.brief_description.help_text }}</span> | ||
55 | + | ||
56 | + {% if form.brief_description.errors %} | ||
57 | + <div class="alert alert-danger alert-dismissible" role="alert"> | ||
58 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
59 | + <span aria-hidden="true">×</span> | ||
60 | + </button> | ||
61 | + <ul> | ||
62 | + {% for error in form.brief_description.errors %} | ||
63 | + <li>{{ error }}</li> | ||
64 | + {% endfor %} | ||
65 | + </ul> | ||
66 | + </div> | ||
67 | + {% endif %} | ||
68 | + </div> | ||
69 | + | ||
70 | + <div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput"> | ||
71 | + <label for="{{ form.tags.auto_id }}">{{ form.tags.label }}</label> | ||
72 | + {% render_field form.tags class='form-control' data-role="tagsinput" %} | ||
73 | + | ||
74 | + <span id="helpBlock" class="help-block">{{ form.tags.help_text }}</span> | ||
75 | + | ||
76 | + {% if form.tags.errors %} | ||
77 | + <div class="alert alert-danger alert-dismissible" role="alert"> | ||
78 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
79 | + <span aria-hidden="true">×</span> | ||
80 | + </button> | ||
81 | + <ul> | ||
82 | + {% for error in form.tags.errors %} | ||
83 | + <li>{{ error }}</li> | ||
84 | + {% endfor %} | ||
85 | + </ul> | ||
86 | + </div> | ||
87 | + {% endif %} | ||
88 | + </div> | ||
89 | + | ||
90 | + <div class="form-group{% if form.has_error %} has-error {% endif %}"> | ||
91 | + <label for="{{ form.initial_view_date.auto_id }}">{{ form.initial_view_date.label }}</label> | ||
92 | + | ||
93 | + {% render_field form.initial_view_date class='form-control datetime-picker' %} | ||
94 | + | ||
95 | + <span id="helpBlock" class="help-block">{{ form.initial_view.help_text }}</span> | ||
96 | + | ||
97 | + {% if form.initial_view_date.errors %} | ||
98 | + <div class="alert alert-danger alert-dismissible" role="alert"> | ||
99 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
100 | + <span aria-hidden="true">×</span> | ||
101 | + </button> | ||
102 | + <ul> | ||
103 | + {% for error in form.initial_view_date.errors %} | ||
104 | + <li>{{ error }}</li> | ||
105 | + {% endfor %} | ||
106 | + </ul> | ||
107 | + </div> | ||
108 | + {% endif %} | ||
109 | + </div> | ||
110 | + | ||
111 | + <div class="form-group{% if form.has_error %} has-error {% endif %}"> | ||
112 | + <div class=" checkbox"> | ||
113 | + <label for="{{ form.initial_view.auto_id }}"> | ||
114 | + {% render_field form.initial_view %} {{ form.initial_view.label }} | ||
115 | + </label> | ||
116 | + </div> | ||
117 | + | ||
118 | + <span id="helpBlock" class="help-block">{{ form.initial_view.help_text }}</span> | ||
119 | + | ||
120 | + {% if form.initial_view.errors %} | ||
121 | + <div class="alert alert-danger alert-dismissible" role="alert"> | ||
122 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
123 | + <span aria-hidden="true">×</span> | ||
124 | + </button> | ||
125 | + <ul> | ||
126 | + {% for error in form.initial_view.errors %} | ||
127 | + <li>{{ error }}</li> | ||
128 | + {% endfor %} | ||
129 | + </ul> | ||
130 | + </div> | ||
131 | + {% endif %} | ||
132 | + </div> | ||
133 | + | ||
134 | + | ||
135 | + <div class=" form-group panel-group" id="professors_accordion" role="tablist" aria-multiselectable="true"> | ||
136 | + <div class="panel panel-info"> | ||
137 | + <div class="panel-heading"> | ||
138 | + <div class="row"> | ||
139 | + <div class="col-md-12"> | ||
140 | + <a data-parent="#professors_accordion" data-toggle="collapse" href="#notifications"> | ||
141 | + <h4 class="panel-title"> | ||
142 | + <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>{% trans 'Pendencies Notifications' %}</label> | ||
143 | + </h4> | ||
144 | + </a> | ||
145 | + </div> | ||
146 | + </div> | ||
147 | + </div> | ||
148 | + | ||
149 | + | ||
150 | + <div id="notifications" class="panel-collapse collapse"> | ||
151 | + | ||
152 | + <div class="notifies"> | ||
153 | + <div style="text-align:left"> | ||
154 | + {% render_field pendencies_form.id %} | ||
155 | + {% render_field pendencies_form.resource %} | ||
156 | + {% render_field pendencies_form.subject class='pend_subj' %} | ||
157 | + | ||
158 | + <div class="form-group{% if pendencies_form.has_error %} has-error {% endif %} row"> | ||
159 | + <label for="{{ pendencies_form.action.auto_id }}" class="pull-left action_label contol-label"> | ||
160 | + {% trans 'Action not performed by the user' %}: | ||
161 | + </label> | ||
162 | + <div class="col-md-3"> | ||
163 | + {% render_field pendencies_form.action class='form-control' %} | ||
164 | + </div> | ||
165 | + | ||
166 | + <br clear="all" /> | ||
167 | + | ||
168 | + <span id="helpBlock" class="help-block">{{ pendencies_form.action.help_text }}</span> | ||
169 | + | ||
170 | + {% if pendencies_form.action.errors %} | ||
171 | + <div class="alert alert-danger alert-dismissible" role="alert"> | ||
172 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
173 | + <span aria-hidden="true">×</span> | ||
174 | + </button> | ||
175 | + <ul> | ||
176 | + {% for error in pendencies_form.action.errors %} | ||
177 | + <li>{{ error }}</li> | ||
178 | + {% endfor %} | ||
179 | + </ul> | ||
180 | + </div> | ||
181 | + {% endif %} | ||
182 | + </div> | ||
183 | + <br clear="all" /> | ||
184 | + <div class="row"> | ||
185 | + <div class="col-md-12"> | ||
186 | + <p>{% trans 'Wished period' %}: </p> | ||
187 | + </div> | ||
188 | + </div> | ||
189 | + <div class="form-group{% if pendencies_form.has_error %} has-error {% endif %} row"> | ||
190 | + <div class="col-lg-2 col-md-2 col-sm-2 col-xs-3 checkbox"> | ||
191 | + <label> | ||
192 | + {% render_field pendencies_form.begin_date_check class="begin_date" %} {{ pendencies_form.begin_date.label }} | ||
193 | + </label> | ||
194 | + </div> | ||
195 | + <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4"> | ||
196 | + {% render_field pendencies_form.begin_date class='form-control datetime-picker begin_date_input' %} | ||
197 | + </div> | ||
198 | + </div> | ||
199 | + <div class="row"> | ||
200 | + <span id="helpBlock" class="help-block">{{ pendencies_form.begin_date.help_text }}</span> | ||
201 | + | ||
202 | + {% if pendencies_form.begin_date.errors %} | ||
203 | + <div class="alert alert-danger alert-dismissible" role="alert"> | ||
204 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
205 | + <span aria-hidden="true">×</span> | ||
206 | + </button> | ||
207 | + <ul> | ||
208 | + {% for error in pendencies_form.begin_date.errors %} | ||
209 | + <li>{{ error }}</li> | ||
210 | + {% endfor %} | ||
211 | + </ul> | ||
212 | + </div> | ||
213 | + {% endif %} | ||
214 | + </div> | ||
215 | + <div class="form-group{% if pendencies_form.has_error %} has-error {% endif %} row"> | ||
216 | + <div class="col-lg-2 col-md-2 col-sm-2 col-xs-3 checkbox"> | ||
217 | + <label> | ||
218 | + {% render_field pendencies_form.end_date_check class="end_date" %} {{ pendencies_form.end_date.label }} | ||
219 | + </label> | ||
220 | + </div> | ||
221 | + <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4"> | ||
222 | + {% render_field pendencies_form.end_date class='form-control datetime-picker end_date_input' %} | ||
223 | + </div> | ||
224 | + </div> | ||
225 | + <div class="row"> | ||
226 | + <span id="helpBlock" class="help-block">{{ pendencies_form.end_date.help_text }}</span> | ||
227 | + | ||
228 | + {% if pendencies_form.end_date.errors %} | ||
229 | + <div class="alert alert-danger alert-dismissible" role="alert"> | ||
230 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
231 | + <span aria-hidden="true">×</span> | ||
232 | + </button> | ||
233 | + <ul> | ||
234 | + {% for error in pendencies_form.end_date.errors %} | ||
235 | + <li>{{ error }}</li> | ||
236 | + {% endfor %} | ||
237 | + </ul> | ||
238 | + </div> | ||
239 | + {% endif %} | ||
240 | + </div> | ||
241 | + </div> | ||
242 | + </div> | ||
243 | + </div> | ||
244 | + </div> | ||
245 | + | ||
246 | + <div class="panel panel-info"> | ||
247 | + <div class="panel-heading"> | ||
248 | + <div class="row"> | ||
249 | + <div class="col-md-12"> | ||
250 | + <a data-parent="#professors_accordion" data-toggle="collapse" href="#students"> | ||
251 | + <h4 class="panel-title"> | ||
252 | + <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="{{ form.students.auto_id }}">{{ form.students.label }}</label> | ||
253 | + </h4> | ||
254 | + </a> | ||
255 | + </div> | ||
256 | + </div> | ||
257 | + </div> | ||
258 | + <div id="students" class="panel-collapse collapse"> | ||
259 | + <div class="form-group{% if form.has_error %} has-error {% endif %}"> | ||
260 | + <div class=" checkbox"> | ||
261 | + <label for="{{ form.all_students.auto_id }}"> | ||
262 | + {% render_field form.all_students %} {{ form.all_students.label }} | ||
263 | + </label> | ||
264 | + </div> | ||
265 | + | ||
266 | + <span id="helpBlock" class="help-block">{{ form.all_students.help_text }}</span> | ||
267 | + | ||
268 | + {% if form.all_students.errors %} | ||
269 | + <div class="alert alert-danger alert-dismissible" role="alert"> | ||
270 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
271 | + <span aria-hidden="true">×</span> | ||
272 | + </button> | ||
273 | + <ul> | ||
274 | + {% for error in form.all_students.errors %} | ||
275 | + <li>{{ error }}</li> | ||
276 | + {% endfor %} | ||
277 | + </ul> | ||
278 | + </div> | ||
279 | + {% endif %} | ||
280 | + </div> | ||
281 | + | ||
282 | + <p><em>{% trans 'Attribute students to file link' %}:</em></p> | ||
283 | + {% render_field form.students class='form-control' %} | ||
284 | + | ||
285 | + <span id="helpBlock" class="help-block">{{ form.students.help_text }}</span> | ||
286 | + | ||
287 | + {% if form.students.errors %} | ||
288 | + <div class="alert alert-danger alert-dismissible" role="alert"> | ||
289 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
290 | + <span aria-hidden="true">×</span> | ||
291 | + </button> | ||
292 | + <ul> | ||
293 | + {% for error in form.students.errors %} | ||
294 | + <li>{{ error }}</li> | ||
295 | + {% endfor %} | ||
296 | + </ul> | ||
297 | + </div> | ||
298 | + {% endif %} | ||
299 | + | ||
300 | + <br clear="all" /> | ||
301 | + | ||
302 | + <p><em>{% trans 'Attribute groups to file link' %}:</em></p> | ||
303 | + {% render_field form.groups class='form-control' %} | ||
304 | + | ||
305 | + <span id="helpBlock" class="help-block">{{ form.groups.help_text }}</span> | ||
306 | + | ||
307 | + {% if form.groups.errors %} | ||
308 | + <div class="alert alert-danger alert-dismissible" role="alert"> | ||
309 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
310 | + <span aria-hidden="true">×</span> | ||
311 | + </button> | ||
312 | + <ul> | ||
313 | + {% for error in form.groups.errors %} | ||
314 | + <li>{{ error }}</li> | ||
315 | + {% endfor %} | ||
316 | + </ul> | ||
317 | + </div> | ||
318 | + {% endif %} | ||
319 | + </div> | ||
320 | + </div> | ||
321 | + </div> | ||
322 | + | ||
323 | + <div class="form-group{% if form.has_error %} has-error {% endif %}"> | ||
324 | + <div class=" checkbox"> | ||
325 | + <label for="{{ form.visible.auto_id }}"> | ||
326 | + {% render_field form.visible %} {{ form.visible.label }} | ||
327 | + </label> | ||
328 | + </div> | ||
329 | + | ||
330 | + <span id="helpBlock" class="help-block">{{ form.visible.help_text }}</span> | ||
331 | + | ||
332 | + {% if form.visible.errors %} | ||
333 | + <div class="alert alert-danger alert-dismissible" role="alert"> | ||
334 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
335 | + <span aria-hidden="true">×</span> | ||
336 | + </button> | ||
337 | + <ul> | ||
338 | + {% for error in form.visible.errors %} | ||
339 | + <li>{{ error }}</li> | ||
340 | + {% endfor %} | ||
341 | + </ul> | ||
342 | + </div> | ||
343 | + {% endif %} | ||
344 | + </div> | ||
345 | + | ||
346 | + <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12"> | ||
347 | + <div class="text-center"> | ||
348 | + <input type="submit" value="{% trans 'Save' %}" class="btn btn-raised btn-success" /> | ||
349 | + </div> | ||
350 | + </div> | ||
351 | +</form> | ||
352 | +<script type="text/javascript"> | ||
353 | + $(function() { | ||
354 | + var begin_val = $('.begin_date_input').val(), | ||
355 | + end_val = $('.end_date_input').val(); | ||
356 | + | ||
357 | + if (begin_val != '') { | ||
358 | + $(".begin_date").prop('checked', true); | ||
359 | + } | ||
360 | + | ||
361 | + if (end_val != '') { | ||
362 | + $(".end_date").prop('checked', true); | ||
363 | + } | ||
364 | + | ||
365 | + {% if not pendencies_form.is_valid and pendencies_form.is_bound %} | ||
366 | + $("#notifications").collapse('toggle'); | ||
367 | + {% endif %} | ||
368 | + }); | ||
369 | +</script> | ||
370 | +<script type="text/javascript" src="{% static 'js/resources.js' %}"></script> | ||
0 | \ No newline at end of file | 371 | \ No newline at end of file |
@@ -0,0 +1,34 @@ | @@ -0,0 +1,34 @@ | ||
1 | +{% extends 'subjects/view.html' %} | ||
2 | + | ||
3 | +{% load static i18n django_bootstrap_breadcrumbs %} | ||
4 | + | ||
5 | +{% block style %} | ||
6 | + {{block.super}} | ||
7 | + <link rel="stylesheet" type="text/css" href="{% static "css/bootstrap-tagsinput.css" %}"> | ||
8 | +{% endblock %} | ||
9 | + | ||
10 | +{% block javascript %} | ||
11 | + {{block.super}} | ||
12 | + <script type="text/javascript" src="{% static "js/bootstrap-tagsinput.js" %} "></script> | ||
13 | +{% endblock %} | ||
14 | + | ||
15 | +{% block breadcrumbs %} | ||
16 | + {{ block.super }} | ||
17 | + | ||
18 | + {% breadcrumb topic 'subjects:topic_view' topic.subject.slug topic.slug %} | ||
19 | + | ||
20 | + {% trans 'Create File Link' as bread %} | ||
21 | + {% breadcrumb bread 'links:create' topic.slug %} | ||
22 | +{% endblock %} | ||
23 | + | ||
24 | +{% block content %} | ||
25 | + <div class="card"> | ||
26 | + <div class="card-content"> | ||
27 | + <div class="card-body"> | ||
28 | + {% include 'links/_form.html' %} | ||
29 | + </div> | ||
30 | + </div> | ||
31 | + </div> | ||
32 | + <br clear="all" /> | ||
33 | + <br clear="all" /> | ||
34 | +{% endblock %} |
@@ -0,0 +1,7 @@ | @@ -0,0 +1,7 @@ | ||
1 | +from django.conf.urls import url | ||
2 | +from django.contrib.auth import views as auth_views | ||
3 | + | ||
4 | +from . import views | ||
5 | + | ||
6 | +urlpatterns = [ | ||
7 | + url(r'^create/(?P<slug>[\w_-]+)/$', views.CreateLinkView.as_view(), name='create'),] | ||
0 | \ No newline at end of file | 8 | \ No newline at end of file |
links/views.py
1 | -from django.shortcuts import render | 1 | +from django.shortcuts import render, get_object_or_404, redirect |
2 | +from django.views import generic | ||
3 | +from .models import Link | ||
4 | +from django.utils.translation import ugettext_lazy as _ | ||
5 | +from django.core.urlresolvers import reverse_lazy | ||
6 | +from django.contrib.auth.mixins import LoginRequiredMixin | ||
2 | 7 | ||
8 | +from .forms import LinkForm | ||
9 | +from rolepermissions.mixins import HasRoleMixin | ||
10 | + | ||
11 | +from log.mixins import LogMixin | ||
12 | +from log.decorators import log_decorator_ajax | ||
13 | +from log.models import Log | ||
14 | + | ||
15 | +from pendencies.forms import PendenciesForm | ||
16 | + | ||
17 | +from amadeus.permissions import has_subject_permissions, has_resource_permissions | ||
18 | + | ||
19 | +from topics.models import Topic | ||
3 | # Create your views here. | 20 | # Create your views here. |
21 | +class CreateLinkView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): | ||
22 | + log_component = 'resources' | ||
23 | + log_action = 'create' | ||
24 | + log_resource = 'file_link' | ||
25 | + log_context = {} | ||
26 | + | ||
27 | + login_url = reverse_lazy("users:login") | ||
28 | + redirect_field_name = 'next' | ||
29 | + | ||
30 | + template_name = 'links/create.html' | ||
31 | + form_class = LinkForm | ||
32 | + | ||
33 | + def dispatch(self, request, *args, **kwargs): | ||
34 | + slug = self.kwargs.get('slug', '') | ||
35 | + topic = get_object_or_404(Topic, slug = slug) | ||
36 | + | ||
37 | + if not has_subject_permissions(request.user, topic.subject): | ||
38 | + return redirect(reverse_lazy('subjects:home')) | ||
39 | + | ||
40 | + return super(CreateLinkView, self).dispatch(request, *args, **kwargs) | ||
41 | + | ||
42 | + def get(self, request, *args, **kwargs): | ||
43 | + self.object = None | ||
44 | + | ||
45 | + form_class = self.get_form_class() | ||
46 | + form = self.get_form(form_class) | ||
47 | + | ||
48 | + slug = self.kwargs.get('slug', '') | ||
49 | + topic = get_object_or_404(Topic, slug = slug) | ||
50 | + | ||
51 | + pendencies_form = PendenciesForm(initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) | ||
52 | + | ||
53 | + return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) | ||
54 | + | ||
55 | + def post(self, request, *args, **kwargs): | ||
56 | + self.object = None | ||
57 | + | ||
58 | + form_class = self.get_form_class() | ||
59 | + form = self.get_form(form_class) | ||
60 | + | ||
61 | + slug = self.kwargs.get('slug', '') | ||
62 | + topic = get_object_or_404(Topic, slug = slug) | ||
63 | + | ||
64 | + pendencies_form = PendenciesForm(self.request.POST, initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) | ||
65 | + | ||
66 | + if (form.is_valid() and pendencies_form.is_valid()): | ||
67 | + return self.form_valid(form, pendencies_form) | ||
68 | + else: | ||
69 | + return self.form_invalid(form, pendencies_form) | ||
70 | + | ||
71 | + def get_initial(self): | ||
72 | + initial = super(CreateLinkView, self).get_initial() | ||
73 | + | ||
74 | + slug = self.kwargs.get('slug', '') | ||
75 | + | ||
76 | + topic = get_object_or_404(Topic, slug = slug) | ||
77 | + initial['subject'] = topic.subject | ||
78 | + | ||
79 | + return initial | ||
80 | + | ||
81 | + def form_invalid(self, form, pendencies_form): | ||
82 | + return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) | ||
83 | + | ||
84 | + def form_valid(self, form, pendencies_form): | ||
85 | + self.object = form.save(commit = False) | ||
86 | + | ||
87 | + slug = self.kwargs.get('slug', '') | ||
88 | + topic = get_object_or_404(Topic, slug = slug) | ||
89 | + | ||
90 | + self.object.topic = topic | ||
91 | + self.object.order = topic.resource_topic.count() + 1 | ||
92 | + | ||
93 | + if not self.object.topic.visible and not self.object.topic.repository: | ||
94 | + self.object.visible = False | ||
95 | + | ||
96 | + self.object.save() | ||
97 | + | ||
98 | + pend_form = pendencies_form.save(commit = False) | ||
99 | + pend_form.resource = self.object | ||
100 | + | ||
101 | + if not pend_form.action == "": | ||
102 | + pend_form.save() | ||
103 | + | ||
104 | + self.log_context['category_id'] = self.object.topic.subject.category.id | ||
105 | + self.log_context['category_name'] = self.object.topic.subject.category.name | ||
106 | + self.log_context['category_slug'] = self.object.topic.subject.category.slug | ||
107 | + self.log_context['subject_id'] = self.object.topic.subject.id | ||
108 | + self.log_context['subject_name'] = self.object.topic.subject.name | ||
109 | + self.log_context['subject_slug'] = self.object.topic.subject.slug | ||
110 | + self.log_context['topic_id'] = self.object.topic.id | ||
111 | + self.log_context['topic_name'] = self.object.topic.name | ||
112 | + self.log_context['topic_slug'] = self.object.topic.slug | ||
113 | + self.log_context['link_id'] = self.object.id | ||
114 | + self.log_context['link_name'] = self.object.name | ||
115 | + self.log_context['link_slug'] = self.object.slug | ||
116 | + | ||
117 | + super(CreateLinkView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | ||
118 | + | ||
119 | + return redirect(self.get_success_url()) | ||
120 | + | ||
121 | + def get_context_data(self, **kwargs): | ||
122 | + context = super(CreateLinkView, self).get_context_data(**kwargs) | ||
123 | + | ||
124 | + context['title'] = _('Create Webiste Link') | ||
125 | + | ||
126 | + slug = self.kwargs.get('slug', '') | ||
127 | + topic = get_object_or_404(Topic, slug = slug) | ||
128 | + | ||
129 | + context['topic'] = topic | ||
130 | + context['subject'] = topic.subject | ||
131 | + | ||
132 | + return context | ||
133 | + | ||
134 | + def get_success_url(self): | ||
135 | + messages.success(self.request, _('The Link "%s" was added to the Topic "%s" of the virtual environment "%s" successfully!')%(self.object.name, self.object.topic.name, self.object.topic.subject.name)) | ||
136 | + | ||
137 | + return reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) | ||
4 | \ No newline at end of file | 138 | \ No newline at end of file |
subjects/forms.py
@@ -131,8 +131,8 @@ class UpdateSubjectForm(forms.ModelForm): | @@ -131,8 +131,8 @@ class UpdateSubjectForm(forms.ModelForm): | ||
131 | class Meta: | 131 | class Meta: |
132 | model = Subject | 132 | model = Subject |
133 | 133 | ||
134 | - fields = ('name', 'description_brief', 'description', | ||
135 | - 'visible', 'professor', 'students', ) | 134 | + fields = ('name', 'description_brief', 'description', 'init_date', 'end_date','subscribe_begin', 'subscribe_end', |
135 | + 'visible', 'professor', 'students', ) | ||
136 | 136 | ||
137 | 137 | ||
138 | widgets = { | 138 | widgets = { |
subjects/models.py
@@ -27,7 +27,7 @@ class Subject(models.Model): | @@ -27,7 +27,7 @@ class Subject(models.Model): | ||
27 | init_date = models.DateField(_('Begin of Subject Date')) | 27 | init_date = models.DateField(_('Begin of Subject Date')) |
28 | end_date = models.DateField(_('End of Subject Date')) | 28 | end_date = models.DateField(_('End of Subject Date')) |
29 | 29 | ||
30 | - tags = models.ManyToManyField(Tag, verbose_name='tags', blank=True, null=True) | 30 | + tags = models.ManyToManyField(Tag, verbose_name='tags', blank=True) |
31 | 31 | ||
32 | create_date = models.DateTimeField(_('Creation Date'), auto_now_add = True) | 32 | create_date = models.DateTimeField(_('Creation Date'), auto_now_add = True) |
33 | update_date = models.DateTimeField(_('Date of last update'), auto_now=True) | 33 | update_date = models.DateTimeField(_('Date of last update'), auto_now=True) |
topics/templates/topics/list.html
@@ -55,7 +55,7 @@ | @@ -55,7 +55,7 @@ | ||
55 | <li><a href="#"><i class="fa fa-video-camera"></i> {% trans 'Video Embed' %}</a></li> | 55 | <li><a href="#"><i class="fa fa-video-camera"></i> {% trans 'Video Embed' %}</a></li> |
56 | <li><a href="#"><i class="fa fa-comments-o"></i> {% trans 'Forum' %}</a></li> | 56 | <li><a href="#"><i class="fa fa-comments-o"></i> {% trans 'Forum' %}</a></li> |
57 | <li><a href="{% url 'file_links:create' topic.slug %}"><i class="fa fa-file-archive-o"></i> {% trans 'File Link' %}</a></li> | 57 | <li><a href="{% url 'file_links:create' topic.slug %}"><i class="fa fa-file-archive-o"></i> {% trans 'File Link' %}</a></li> |
58 | - <li><a href="#" > <i class="fa fa-globe"></i> {% trans "Link to Website" %}</a> | 58 | + <li><a href="{% url 'links:create' topic.slug %}" > <i class="fa fa-globe"></i> {% trans "Link to Website" %}</a> |
59 | <li><a href="{% url 'webpages:create' topic.slug %}"><i class="fa fa-file-code-o"></i> {% trans 'Webpage' %}</a></li> | 59 | <li><a href="{% url 'webpages:create' topic.slug %}"><i class="fa fa-file-code-o"></i> {% trans 'Webpage' %}</a></li> |
60 | <li><a href="#"><i class="fa fa-question-circle-o"></i> {% trans 'Questionary' %}</a></li> | 60 | <li><a href="#"><i class="fa fa-question-circle-o"></i> {% trans 'Questionary' %}</a></li> |
61 | </ul> | 61 | </ul> |