Commit f1874254b50ec08babe2cac880a8b18869d0522f
Exists in
master
and in
2 other branches
Merge branch 'refactoring' of https://github.com/amadeusproject/amadeuslms into refactoring
Showing
21 changed files
with
273 additions
and
141 deletions
Show diff stats
amadeus/static/bootstrap-3.3.7/css/bootstrap.css
@@ -6319,7 +6319,7 @@ button.close { | @@ -6319,7 +6319,7 @@ button.close { | ||
6319 | top: 0; | 6319 | top: 0; |
6320 | bottom: 0; | 6320 | bottom: 0; |
6321 | left: 0; | 6321 | left: 0; |
6322 | - width: 15%; | 6322 | + width: 5%; |
6323 | font-size: 20px; | 6323 | font-size: 20px; |
6324 | color: #fff; | 6324 | color: #fff; |
6325 | text-align: center; | 6325 | text-align: center; |
@@ -6407,14 +6407,14 @@ button.close { | @@ -6407,14 +6407,14 @@ button.close { | ||
6407 | cursor: pointer; | 6407 | cursor: pointer; |
6408 | background-color: #000 \9; | 6408 | background-color: #000 \9; |
6409 | background-color: rgba(0, 0, 0, 0); | 6409 | background-color: rgba(0, 0, 0, 0); |
6410 | - border: 1px solid #fff; | 6410 | + border: 1px solid #bcbcbc; |
6411 | border-radius: 10px; | 6411 | border-radius: 10px; |
6412 | } | 6412 | } |
6413 | .carousel-indicators .active { | 6413 | .carousel-indicators .active { |
6414 | width: 12px; | 6414 | width: 12px; |
6415 | height: 12px; | 6415 | height: 12px; |
6416 | margin: 0; | 6416 | margin: 0; |
6417 | - background-color: #fff; | 6417 | + background-color: #d6d6d6; |
6418 | } | 6418 | } |
6419 | .carousel-caption { | 6419 | .carousel-caption { |
6420 | position: absolute; | 6420 | position: absolute; |
@@ -6455,7 +6455,7 @@ button.close { | @@ -6455,7 +6455,7 @@ button.close { | ||
6455 | padding-bottom: 30px; | 6455 | padding-bottom: 30px; |
6456 | } | 6456 | } |
6457 | .carousel-indicators { | 6457 | .carousel-indicators { |
6458 | - bottom: 20px; | 6458 | + bottom: -30px; |
6459 | } | 6459 | } |
6460 | } | 6460 | } |
6461 | .clearfix:before, | 6461 | .clearfix:before, |
amadeus/static/css/base/amadeus.css
@@ -48,7 +48,7 @@ a:focus { | @@ -48,7 +48,7 @@ a:focus { | ||
48 | 48 | ||
49 | /* Initial page starts */ | 49 | /* Initial page starts */ |
50 | .users-cloud { | 50 | .users-cloud { |
51 | - | 51 | + |
52 | width: 100%; | 52 | width: 100%; |
53 | height: 100%; | 53 | height: 100%; |
54 | overflow: hidden; | 54 | overflow: hidden; |
@@ -87,7 +87,7 @@ a:focus { | @@ -87,7 +87,7 @@ a:focus { | ||
87 | 87 | ||
88 | .my-subjects-title { | 88 | .my-subjects-title { |
89 | font-family: Roboto; | 89 | font-family: Roboto; |
90 | - font-size: 18px; | 90 | + font-size: 18px; |
91 | } | 91 | } |
92 | 92 | ||
93 | /* initial page ends */ | 93 | /* initial page ends */ |
@@ -172,7 +172,7 @@ a:focus { | @@ -172,7 +172,7 @@ a:focus { | ||
172 | } | 172 | } |
173 | 173 | ||
174 | .subject-group { | 174 | .subject-group { |
175 | - margin-left: 20px; | 175 | + margin-left: 20px; |
176 | } | 176 | } |
177 | 177 | ||
178 | .category-header > h4{ | 178 | .category-header > h4{ |
@@ -298,9 +298,9 @@ a:focus { | @@ -298,9 +298,9 @@ a:focus { | ||
298 | } | 298 | } |
299 | 299 | ||
300 | .navbar .logo { | 300 | .navbar .logo { |
301 | - text-align: center; | 301 | + text-align: center; |
302 | margin-top: -6px; | 302 | margin-top: -6px; |
303 | - height: 32px; | 303 | + height: 32px; |
304 | width: 32px; | 304 | width: 32px; |
305 | } | 305 | } |
306 | .navbar .project_name { | 306 | .navbar .project_name { |
@@ -385,8 +385,8 @@ a:focus { | @@ -385,8 +385,8 @@ a:focus { | ||
385 | padding-bottom: 15px !important; | 385 | padding-bottom: 15px !important; |
386 | } | 386 | } |
387 | .modal-footer { | 387 | .modal-footer { |
388 | - text-align: right; | ||
389 | - padding-top: 5px !important; | 388 | + text-align: right; |
389 | + padding-top: 5px !important; | ||
390 | } | 390 | } |
391 | 391 | ||
392 | /* HEADER */ | 392 | /* HEADER */ |
@@ -427,7 +427,7 @@ a:focus { | @@ -427,7 +427,7 @@ a:focus { | ||
427 | /* Breadcrumbs */ | 427 | /* Breadcrumbs */ |
428 | .breadcrumb{ | 428 | .breadcrumb{ |
429 | font-size: 16px; | 429 | font-size: 16px; |
430 | - margin-bottom: 5px; | 430 | + margin-bottom: 0px; |
431 | font-style: italic; | 431 | font-style: italic; |
432 | } | 432 | } |
433 | /* End Breadcrumbs */ | 433 | /* End Breadcrumbs */ |
@@ -535,8 +535,8 @@ a:focus { | @@ -535,8 +535,8 @@ a:focus { | ||
535 | 535 | ||
536 | /* Icon Topic */ | 536 | /* Icon Topic */ |
537 | .divMoreActions { | 537 | .divMoreActions { |
538 | - text-align: right; | ||
539 | - height: 30px; | 538 | + text-align: right; |
539 | + height: 30px; | ||
540 | float: right; | 540 | float: right; |
541 | width: 3%; | 541 | width: 3%; |
542 | } | 542 | } |
@@ -550,12 +550,12 @@ a:focus { | @@ -550,12 +550,12 @@ a:focus { | ||
550 | } | 550 | } |
551 | 551 | ||
552 | .moreAccordion button { | 552 | .moreAccordion button { |
553 | - margin-bottom: 0px; | 553 | + margin-bottom: 0px; |
554 | margin-top: 8px; | 554 | margin-top: 8px; |
555 | } | 555 | } |
556 | 556 | ||
557 | .titleTopic { | 557 | .titleTopic { |
558 | - padding-top: 10px; | 558 | + padding-top: 10px; |
559 | padding-bottom: 10px; | 559 | padding-bottom: 10px; |
560 | } | 560 | } |
561 | 561 | ||
@@ -567,9 +567,9 @@ a:focus { | @@ -567,9 +567,9 @@ a:focus { | ||
567 | right: 0; | 567 | right: 0; |
568 | } | 568 | } |
569 | 569 | ||
570 | -.cards-content{ | ||
571 | - padding-left: 0px; | ||
572 | - padding-right: 0px; | 570 | +.cards-content{ |
571 | + padding-left: 0px; | ||
572 | + padding-right: 0px; | ||
573 | font-family: Roboto; | 573 | font-family: Roboto; |
574 | font-size: 18px; | 574 | font-size: 18px; |
575 | } | 575 | } |
@@ -577,12 +577,12 @@ a:focus { | @@ -577,12 +577,12 @@ a:focus { | ||
577 | margin-left: 4%; | 577 | margin-left: 4%; |
578 | } | 578 | } |
579 | 579 | ||
580 | -.course, .subject, .topic { | ||
581 | - padding-top: 0px; | ||
582 | - padding-bottom: 0px; | 580 | +.course, .subject, .topic { |
581 | + padding-top: 0px; | ||
582 | + padding-bottom: 0px; | ||
583 | } | 583 | } |
584 | .course-detail { | 584 | .course-detail { |
585 | - padding-top: 10px; | 585 | + padding-top: 10px; |
586 | padding-bottom: 10px; | 586 | padding-bottom: 10px; |
587 | } | 587 | } |
588 | 588 | ||
@@ -1153,8 +1153,8 @@ li.item .notify_badge { | @@ -1153,8 +1153,8 @@ li.item .notify_badge { | ||
1153 | 1153 | ||
1154 | /*Carrosel change*/ | 1154 | /*Carrosel change*/ |
1155 | 1155 | ||
1156 | - | ||
1157 | - | 1156 | + |
1157 | + | ||
1158 | .carousel-control.right{ | 1158 | .carousel-control.right{ |
1159 | background-image: none !important; | 1159 | background-image: none !important; |
1160 | } | 1160 | } |
@@ -1165,8 +1165,8 @@ li.item .notify_badge { | @@ -1165,8 +1165,8 @@ li.item .notify_badge { | ||
1165 | 1165 | ||
1166 | /* CHART APP */ | 1166 | /* CHART APP */ |
1167 | .pie-tooltip{ | 1167 | .pie-tooltip{ |
1168 | - | ||
1169 | - | 1168 | + |
1169 | + | ||
1170 | font-size: 30px; | 1170 | font-size: 30px; |
1171 | left: 130px; | 1171 | left: 130px; |
1172 | padding: 10px; | 1172 | padding: 10px; |
@@ -1186,7 +1186,7 @@ li.item .notify_badge { | @@ -1186,7 +1186,7 @@ li.item .notify_badge { | ||
1186 | background: rgba(0, 0, 0, 0.8); | 1186 | background: rgba(0, 0, 0, 0.8); |
1187 | color: #fff; | 1187 | color: #fff; |
1188 | border-radius: 2px; | 1188 | border-radius: 2px; |
1189 | - pointer-events: none; | 1189 | + pointer-events: none; |
1190 | } | 1190 | } |
1191 | 1191 | ||
1192 | 1192 | ||
@@ -1257,7 +1257,7 @@ div.dataTables_wrapper div.dataTables_paginate { | @@ -1257,7 +1257,7 @@ div.dataTables_wrapper div.dataTables_paginate { | ||
1257 | 1257 | ||
1258 | #resources_accordion .panel-heading{ | 1258 | #resources_accordion .panel-heading{ |
1259 | background-color: #c4c4c4 !important; | 1259 | background-color: #c4c4c4 !important; |
1260 | - | 1260 | + |
1261 | } | 1261 | } |
1262 | 1262 | ||
1263 | .delete-row{ | 1263 | .delete-row{ |
@@ -1287,7 +1287,7 @@ div.dataTables_wrapper div.dataTables_paginate { | @@ -1287,7 +1287,7 @@ div.dataTables_wrapper div.dataTables_paginate { | ||
1287 | margin-top: 0; | 1287 | margin-top: 0; |
1288 | color: #bdbdbd; | 1288 | color: #bdbdbd; |
1289 | } | 1289 | } |
1290 | - | 1290 | + |
1291 | h5.one:before { | 1291 | h5.one:before { |
1292 | content: ""; | 1292 | content: ""; |
1293 | display: block; | 1293 | display: block; |
@@ -1298,7 +1298,7 @@ div.dataTables_wrapper div.dataTables_paginate { | @@ -1298,7 +1298,7 @@ div.dataTables_wrapper div.dataTables_paginate { | ||
1298 | top: 50%; | 1298 | top: 50%; |
1299 | z-index: 1; | 1299 | z-index: 1; |
1300 | } | 1300 | } |
1301 | - | 1301 | + |
1302 | h5.one span { | 1302 | h5.one span { |
1303 | background: #eee; | 1303 | background: #eee; |
1304 | padding-right: 20px; | 1304 | padding-right: 20px; |
@@ -1617,4 +1617,4 @@ div.dataTables_wrapper div.dataTables_paginate { | @@ -1617,4 +1617,4 @@ div.dataTables_wrapper div.dataTables_paginate { | ||
1617 | display: none; | 1617 | display: none; |
1618 | } | 1618 | } |
1619 | } | 1619 | } |
1620 | -/* End Chat */ | ||
1621 | \ No newline at end of file | 1620 | \ No newline at end of file |
1621 | +/* End Chat */ |
amadeus/static/js/crop.js
@@ -1,66 +0,0 @@ | @@ -1,66 +0,0 @@ | ||
1 | -$(function () { | ||
2 | - | ||
3 | - /* Script para abrir o modal com a imagem selecionada */ | ||
4 | - $("#id_image").change(function () { | ||
5 | - if (this.files && this.files[0]) { | ||
6 | - var reader = new FileReader(); | ||
7 | - reader.onload = function (e) { | ||
8 | - $("#image").attr("src", e.target.result); | ||
9 | - $("#modalCrop").modal("show"); | ||
10 | - } | ||
11 | - reader.readAsDataURL(this.files[0]); | ||
12 | - } | ||
13 | - }); | ||
14 | - | ||
15 | - /* Scripts da caixa de corte da imagem */ | ||
16 | - var $image = $("#image"); | ||
17 | - var cropBoxData; | ||
18 | - var canvasData; | ||
19 | - $("#modalCrop").on("shown.bs.modal", function () { | ||
20 | - $image.cropper({ | ||
21 | - viewMode: 1, | ||
22 | - aspectRatio: 1/1, | ||
23 | - minCropBoxWidth: 200, | ||
24 | - minCropBoxHeight: 200, | ||
25 | - ready: function () { | ||
26 | - $image.cropper("setCanvasData", canvasData); | ||
27 | - $image.cropper("setCropBoxData", cropBoxData); | ||
28 | - } | ||
29 | - }); | ||
30 | - }).on("hidden.bs.modal", function () { | ||
31 | - cropBoxData = $image.cropper("getCropBoxData"); | ||
32 | - canvasData = $image.cropper("getCanvasData"); | ||
33 | - $image.cropper("destroy"); | ||
34 | - }); | ||
35 | - | ||
36 | - $(".js-zoom-in").click(function () { | ||
37 | - $image.cropper("zoom", 0.1); | ||
38 | - }); | ||
39 | - | ||
40 | - $(".js-zoom-out").click(function () { | ||
41 | - $image.cropper("zoom", -0.1); | ||
42 | - }); | ||
43 | - | ||
44 | - /* Script para pegar os valores das dimensões e depois fechar o modal */ | ||
45 | - $(".js-crop-and-upload").click(function () { | ||
46 | - var cropData = $image.cropper("getData"); | ||
47 | - $("#id_x").val(cropData["x"]); | ||
48 | - $("#id_y").val(cropData["y"]); | ||
49 | - $("#id_height").val(cropData["height"]); | ||
50 | - $("#id_width").val(cropData["width"]); | ||
51 | - $("#modalCrop").modal('hide'); | ||
52 | - }); | ||
53 | - | ||
54 | - /* Script para remover o arquivo enviado caso o usuário clique em cancelar*/ | ||
55 | - $("#id_image").on('change', function(){ | ||
56 | - console.log(this.value); | ||
57 | - }); | ||
58 | - | ||
59 | - $('#crop_cancel').on('click', function(e){ | ||
60 | - var input = $("#id_image"); | ||
61 | - var holder = $("#pic_holder"); | ||
62 | - input.replaceWith(input.val('').clone(true)); | ||
63 | - holder.replaceWith(holder.val('').clone(true)); | ||
64 | - }); | ||
65 | - | ||
66 | -}); |
amadeus/static/js/crop_news.js
@@ -18,10 +18,11 @@ $(function () { | @@ -18,10 +18,11 @@ $(function () { | ||
18 | var canvasData; | 18 | var canvasData; |
19 | $("#modalCrop").on("shown.bs.modal", function () { | 19 | $("#modalCrop").on("shown.bs.modal", function () { |
20 | $image.cropper({ | 20 | $image.cropper({ |
21 | - viewMode: 1, | ||
22 | - aspectRatio: 1/1, | ||
23 | - minCropBoxWidth: 700, | 21 | + viewMode: 1 , |
22 | + aspectRatio: 24/5, | ||
23 | + minCropBoxWidth: 200, | ||
24 | minCropBoxHeight: 200, | 24 | minCropBoxHeight: 200, |
25 | + dragMode: 'move', | ||
25 | ready: function () { | 26 | ready: function () { |
26 | $image.cropper("setCanvasData", canvasData); | 27 | $image.cropper("setCanvasData", canvasData); |
27 | $image.cropper("setCropBoxData", cropBoxData); | 28 | $image.cropper("setCropBoxData", cropBoxData); |
amadeus/templates/base.html
@@ -31,8 +31,6 @@ | @@ -31,8 +31,6 @@ | ||
31 | <link rel="stylesheet" type="text/css" href="{% static 'css/jPages.css' %}"> | 31 | <link rel="stylesheet" type="text/css" href="{% static 'css/jPages.css' %}"> |
32 | 32 | ||
33 | <script src="{% static 'js/cropper.min.js' %}"></script> <!-- Js for cropper--> | 33 | <script src="{% static 'js/cropper.min.js' %}"></script> <!-- Js for cropper--> |
34 | - <script src="{% static 'js/crop.js' %}"></script> <!-- Js for cropper--> | ||
35 | - <script src="{% static 'js/crop_news.js' %}"></script> | ||
36 | <link href="{% static 'css/cropper.min.css' %}" rel="stylesheet"> <!-- CSS for cropper--> | 34 | <link href="{% static 'css/cropper.min.css' %}" rel="stylesheet"> <!-- CSS for cropper--> |
37 | 35 | ||
38 | <script type="text/javascript" src="{% static 'js/printThis.js' %}"></script> <!-- Print this plugin js--> | 36 | <script type="text/javascript" src="{% static 'js/printThis.js' %}"></script> <!-- Print this plugin js--> |
news/admin.py
1 | from django.contrib import admin | 1 | from django.contrib import admin |
2 | - | 2 | +from .models import News |
3 | # Register your models here. | 3 | # Register your models here. |
4 | + | ||
5 | +class NewsAdmin(admin.ModelAdmin): | ||
6 | + list_display = ['title', 'slug', 'creator', 'create_date'] | ||
7 | + search_fields = ['title'] | ||
8 | + | ||
9 | +admin.site.register(News, NewsAdmin) |
news/forms.py
@@ -7,6 +7,7 @@ from os.path import join | @@ -7,6 +7,7 @@ from os.path import join | ||
7 | from PIL import Image | 7 | from PIL import Image |
8 | import os | 8 | import os |
9 | from amadeus import settings | 9 | from amadeus import settings |
10 | +from django.utils.html import strip_tags | ||
10 | 11 | ||
11 | class NewsForm(forms.ModelForm): | 12 | class NewsForm(forms.ModelForm): |
12 | MAX_UPLOAD_SIZE = 5*1024*1024 | 13 | MAX_UPLOAD_SIZE = 5*1024*1024 |
@@ -30,7 +31,7 @@ class NewsForm(forms.ModelForm): | @@ -30,7 +31,7 @@ class NewsForm(forms.ModelForm): | ||
30 | image = Image.open(self.instance.image) | 31 | image = Image.open(self.instance.image) |
31 | if not x is None: | 32 | if not x is None: |
32 | cropped_image = image.crop((x, y, w+x, h+y)) | 33 | cropped_image = image.crop((x, y, w+x, h+y)) |
33 | - resized_image = cropped_image.resize((700, 200), Image.ANTIALIAS) | 34 | + resized_image = cropped_image.resize((1200, 250), Image.ANTIALIAS) |
34 | 35 | ||
35 | folder_path = join(settings.MEDIA_ROOT, 'news') | 36 | folder_path = join(settings.MEDIA_ROOT, 'news') |
36 | #check if the folder already exists | 37 | #check if the folder already exists |
@@ -78,3 +79,13 @@ class NewsForm(forms.ModelForm): | @@ -78,3 +79,13 @@ class NewsForm(forms.ModelForm): | ||
78 | return ValueError | 79 | return ValueError |
79 | 80 | ||
80 | return image | 81 | return image |
82 | + def clean_content(self): | ||
83 | + content = self.cleaned_data.get('content', '') | ||
84 | + cleaned_content = strip_tags(content) | ||
85 | + | ||
86 | + if cleaned_content == '': | ||
87 | + self._errors['content'] = [_('This field is required.')] | ||
88 | + | ||
89 | + return ValueError | ||
90 | + | ||
91 | + return content |
news/models.py
@@ -18,7 +18,7 @@ class News(models.Model): | @@ -18,7 +18,7 @@ class News(models.Model): | ||
18 | title = models.CharField( _("Title"), unique = True,max_length= 200) | 18 | title = models.CharField( _("Title"), unique = True,max_length= 200) |
19 | slug = AutoSlugField(_("Slug"),populate_from='title',unique=True) | 19 | slug = AutoSlugField(_("Slug"),populate_from='title',unique=True) |
20 | image = models.ImageField(verbose_name = _('News Image'), upload_to = 'news/', validators = [validate_img_extension],blank= True) | 20 | image = models.ImageField(verbose_name = _('News Image'), upload_to = 'news/', validators = [validate_img_extension],blank= True) |
21 | - content = models.TextField(_('News Content')) | 21 | + content = models.TextField(_('News Content'), blank = True) |
22 | create_date = models.DateTimeField(_('Create Date'), auto_now_add = True) | 22 | create_date = models.DateTimeField(_('Create Date'), auto_now_add = True) |
23 | creator = models.ForeignKey(User, verbose_name = _('Creator'), related_name = "news_creator_user", null = True) | 23 | creator = models.ForeignKey(User, verbose_name = _('Creator'), related_name = "news_creator_user", null = True) |
24 | class Meta: | 24 | class Meta: |
news/templates/news/_form.html
@@ -19,13 +19,8 @@ | @@ -19,13 +19,8 @@ | ||
19 | 19 | ||
20 | 20 | ||
21 | {% elif field.auto_id == 'id_content' %} | 21 | {% elif field.auto_id == 'id_content' %} |
22 | - {% if field.field.required %} | ||
23 | <label for="{{ field.auto_id }}">{{ field.label }} <span>*</span></label> | 22 | <label for="{{ field.auto_id }}">{{ field.label }} <span>*</span></label> |
24 | - {% else %} | ||
25 | - | ||
26 | - <label for="{{ field.auto_id }}">{{ field.label }}</label> | ||
27 | - {% endif %} | ||
28 | - {% render_field field class='form-control text_wysiwyg' %} | 23 | + {% render_field field class='form-control text_wysiwyg' %} |
29 | {% else %} | 24 | {% else %} |
30 | 25 | ||
31 | {% if field.auto_id == 'id_title' %} | 26 | {% if field.auto_id == 'id_title' %} |
@@ -66,4 +61,6 @@ | @@ -66,4 +61,6 @@ | ||
66 | </div> | 61 | </div> |
67 | 62 | ||
68 | </form> | 63 | </form> |
64 | +<script src="{% static 'js/crop_news.js' %}"></script> <!-- Js for cropper--> | ||
65 | + | ||
69 | {% include 'users/modal_crop.html' %} | 66 | {% include 'users/modal_crop.html' %} |
news/templates/news/create.html
news/templates/news/list.html
@@ -3,11 +3,17 @@ | @@ -3,11 +3,17 @@ | ||
3 | {% load static i18n django_bootstrap_breadcrumbs permission_tags pagination %} | 3 | {% load static i18n django_bootstrap_breadcrumbs permission_tags pagination %} |
4 | 4 | ||
5 | {% block breadcrumbs %} | 5 | {% block breadcrumbs %} |
6 | - {{ block.super }} | 6 | + {{ block.super }} |
7 | + {% if user.is_staff %} | ||
7 | {% trans 'Manage News' as manage_news %} | 8 | {% trans 'Manage News' as manage_news %} |
8 | {% breadcrumb manage_news 'news:manage_news' %} | 9 | {% breadcrumb manage_news 'news:manage_news' %} |
10 | + {% else %} | ||
11 | + {% trans 'News' as news %} | ||
12 | + {% breadcrumb news 'news:manage_news' %} | ||
13 | + {% endif %} | ||
9 | {% endblock %} | 14 | {% endblock %} |
10 | 15 | ||
16 | + | ||
11 | {% block render_breadcrumbs %} | 17 | {% block render_breadcrumbs %} |
12 | {% render_breadcrumbs %} | 18 | {% render_breadcrumbs %} |
13 | {% endblock %} | 19 | {% endblock %} |
@@ -41,9 +47,11 @@ | @@ -41,9 +47,11 @@ | ||
41 | </div> | 47 | </div> |
42 | </form> | 48 | </form> |
43 | </div> | 49 | </div> |
50 | + {% if user.is_staff %} | ||
44 | <div class="col-md-3"> | 51 | <div class="col-md-3"> |
45 | <a href="{% url 'news:create' %}" class="pull-right btn btn-success btn-raised btn-md"><i class="fa fa-plus"></i> {% trans 'Create News' %}</a> | 52 | <a href="{% url 'news:create' %}" class="pull-right btn btn-success btn-raised btn-md"><i class="fa fa-plus"></i> {% trans 'Create News' %}</a> |
46 | </div> | 53 | </div> |
54 | + {% endif %} | ||
47 | </div> | 55 | </div> |
48 | 56 | ||
49 | {% if news %} | 57 | {% if news %} |
@@ -54,12 +62,14 @@ | @@ -54,12 +62,14 @@ | ||
54 | <a href="{% url 'news:view' new.slug %}"><h3> <b>{{ new }}</b> </h3></a> | 62 | <a href="{% url 'news:view' new.slug %}"><h3> <b>{{ new }}</b> </h3></a> |
55 | <p>{{ new.creator}}, em {{ new.create_date }}</p> | 63 | <p>{{ new.creator}}, em {{ new.create_date }}</p> |
56 | </div> | 64 | </div> |
65 | + {% if user.is_staff %} | ||
57 | <div class="col-md-6"> | 66 | <div class="col-md-6"> |
58 | <div align="right"> | 67 | <div align="right"> |
59 | <a href="{% url 'news:update' new.slug %}" class="btn btn-success btn-raised btn-sm"><i class="fa fa-edit"></i> {% trans 'Edit' %}</a> | 68 | <a href="{% url 'news:update' new.slug %}" class="btn btn-success btn-raised btn-sm"><i class="fa fa-edit"></i> {% trans 'Edit' %}</a> |
60 | <a href="javascript:delete_news.get('{% url 'news:delete' new.slug %}','#news','#modal_remove')" class="btn btn-default btn-raised btn-sm" class="btn btn-default btn-raised btn-sm"><i class="fa fa-trash"></i> {% trans 'Delete' %}</a> | 69 | <a href="javascript:delete_news.get('{% url 'news:delete' new.slug %}','#news','#modal_remove')" class="btn btn-default btn-raised btn-sm" class="btn btn-default btn-raised btn-sm"><i class="fa fa-trash"></i> {% trans 'Delete' %}</a> |
61 | </div> | 70 | </div> |
62 | </div> | 71 | </div> |
72 | + {% endif %} | ||
63 | </div> | 73 | </div> |
64 | 74 | ||
65 | </div> | 75 | </div> |
@@ -92,4 +102,5 @@ var delete_news = { | @@ -92,4 +102,5 @@ var delete_news = { | ||
92 | 102 | ||
93 | </script> | 103 | </script> |
94 | 104 | ||
105 | +<script src="{% static 'js/crop_news.js' %}"></script> <!-- Js for cropper--> | ||
95 | {% endblock %} | 106 | {% endblock %} |
news/templates/news/search.html
@@ -57,7 +57,7 @@ | @@ -57,7 +57,7 @@ | ||
57 | <div class="col-md-6"> | 57 | <div class="col-md-6"> |
58 | <div align="right"> | 58 | <div align="right"> |
59 | <a href="{% url 'news:update' new.slug %}" class="btn btn-success btn-raised btn-sm"><i class="fa fa-edit"></i> {% trans 'Edit' %}</a> | 59 | <a href="{% url 'news:update' new.slug %}" class="btn btn-success btn-raised btn-sm"><i class="fa fa-edit"></i> {% trans 'Edit' %}</a> |
60 | - <a href="" class="btn btn-default btn-raised btn-sm"><i class="fa fa-trash"></i> {% trans 'Delete' %}</a> | 60 | + <a href="javascript:delete_news.get('{% url 'news:delete' new.slug %}','#news','#modal_remove')" class="btn btn-default btn-raised btn-sm"><i class="fa fa-trash"></i> {% trans 'Delete' %}</a> |
61 | </div> | 61 | </div> |
62 | </div> | 62 | </div> |
63 | </div> | 63 | </div> |
@@ -76,4 +76,20 @@ | @@ -76,4 +76,20 @@ | ||
76 | 76 | ||
77 | </div> | 77 | </div> |
78 | 78 | ||
79 | +<script type="text/javascript"> | ||
80 | +var delete_news = { | ||
81 | + get: function (url, id_modal, id_div_modal){ | ||
82 | + $.get(url, function(data){ | ||
83 | + if($(id_modal).length){ | ||
84 | + $(id_div_modal).empty(); | ||
85 | + $(id_div_modal).append(data); | ||
86 | + } else { | ||
87 | + $(id_div_modal).append(data); | ||
88 | + } | ||
89 | + $(id_modal).modal('show'); | ||
90 | + }); | ||
91 | + } | ||
92 | +}; | ||
93 | + | ||
94 | +</script> | ||
79 | {% endblock %} | 95 | {% endblock %} |
news/templates/news/update.html
news/views.py
@@ -78,6 +78,11 @@ class CreateNewsView(LoginRequiredMixin,LogMixin,generic.edit.CreateView): | @@ -78,6 +78,11 @@ class CreateNewsView(LoginRequiredMixin,LogMixin,generic.edit.CreateView): | ||
78 | template_name = 'news/create.html' | 78 | template_name = 'news/create.html' |
79 | form_class = NewsForm | 79 | form_class = NewsForm |
80 | 80 | ||
81 | + def dispatch(self, request, *args, **kwargs): | ||
82 | + if not request.user.is_staff: | ||
83 | + return redirect(reverse_lazy('subjects:home')) | ||
84 | + return super(CreateNewsView, self).dispatch(request, *args, **kwargs) | ||
85 | + | ||
81 | def form_valid(self, form): | 86 | def form_valid(self, form): |
82 | self.object = form.save(commit = False) | 87 | self.object = form.save(commit = False) |
83 | creator = self.request.user | 88 | creator = self.request.user |
@@ -117,6 +122,11 @@ class UpdateNewsView(LoginRequiredMixin,LogMixin,generic.UpdateView): | @@ -117,6 +122,11 @@ class UpdateNewsView(LoginRequiredMixin,LogMixin,generic.UpdateView): | ||
117 | form_class = NewsForm | 122 | form_class = NewsForm |
118 | model = News | 123 | model = News |
119 | 124 | ||
125 | + def dispatch(self, request, *args, **kwargs): | ||
126 | + if not request.user.is_staff: | ||
127 | + return redirect(reverse_lazy('subjects:home')) | ||
128 | + return super(UpdateNewsView, self).dispatch(request, *args, **kwargs) | ||
129 | + | ||
120 | def get_success_url(self): | 130 | def get_success_url(self): |
121 | messages.success(self.request, _('News successfully created!')) | 131 | messages.success(self.request, _('News successfully created!')) |
122 | 132 | ||
@@ -198,6 +208,11 @@ class DeleteNewsView(LoginRequiredMixin,LogMixin,generic.DeleteView): | @@ -198,6 +208,11 @@ class DeleteNewsView(LoginRequiredMixin,LogMixin,generic.DeleteView): | ||
198 | model = News | 208 | model = News |
199 | template_name = 'news/delete.html' | 209 | template_name = 'news/delete.html' |
200 | 210 | ||
211 | + def dispatch(self, request, *args, **kwargs): | ||
212 | + if not request.user.is_staff: | ||
213 | + return redirect(reverse_lazy('subjects:home')) | ||
214 | + return super(DeleteNewsView, self).dispatch(request, *args, **kwargs) | ||
215 | + | ||
201 | def delete(self, request, *args, **kwargs): | 216 | def delete(self, request, *args, **kwargs): |
202 | news = get_object_or_404(News, slug = self.kwargs.get('slug')) | 217 | news = get_object_or_404(News, slug = self.kwargs.get('slug')) |
203 | return super(DeleteNewsView, self).delete(self, request, *args, **kwargs) | 218 | return super(DeleteNewsView, self).delete(self, request, *args, **kwargs) |
@@ -0,0 +1,84 @@ | @@ -0,0 +1,84 @@ | ||
1 | +{% extends "categories/home.html" %} | ||
2 | + | ||
3 | +{% load static pagination i18n %} | ||
4 | + | ||
5 | +{% block content %} | ||
6 | + {% if messages %} | ||
7 | + {% for message in messages %} | ||
8 | + <div class="alert alert-{{ message.tags }} alert-dismissible" role="alert"> | ||
9 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
10 | + <span aria-hidden="true">×</span> | ||
11 | + </button> | ||
12 | + <p>{{ message }}</p> | ||
13 | + </div> | ||
14 | + {% endfor %} | ||
15 | + {% endif %} | ||
16 | + | ||
17 | + | ||
18 | + | ||
19 | + | ||
20 | + <!-- Wrapper for slides --> | ||
21 | + <div id="myCarousel" class="carousel slide " data-ride="carousel"> | ||
22 | + <!-- Indicators --> | ||
23 | + <ol class="carousel-indicators"> | ||
24 | + <li data-target="#myCarousel" data-slide-to="0" class="active"></li> | ||
25 | + <li data-target="#myCarousel" data-slide-to="1"></li> | ||
26 | + <li data-target="#myCarousel" data-slide-to="2"></li> | ||
27 | + <li data-target="#myCarousel" data-slide-to="3"></li> | ||
28 | + </ol> | ||
29 | + | ||
30 | +<div class="carousel-inner" role="listbox"> | ||
31 | + {% for new in news %} | ||
32 | + {% if forloop.first %} | ||
33 | + <div class="item active" style="text-align:center"> | ||
34 | + <span><a href="{% url 'news:view' new.slug %}"> <img src="{{ new.image.url }}" alt="Image"> </a></span> | ||
35 | + </div> | ||
36 | + {% else %} | ||
37 | + <div class="item" style="text-align:center"> | ||
38 | + <span><a href="{% url 'news:view' new.slug %}"> <img src="{{ new.image.url }}" alt="Image"> </a></span> | ||
39 | + </div> | ||
40 | + {% endif%} | ||
41 | + {% endfor %} | ||
42 | + | ||
43 | +</div> | ||
44 | + | ||
45 | + <!-- Left and right controls --> | ||
46 | + <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev"> | ||
47 | + <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> | ||
48 | + <span class="sr-only">Previous</span> | ||
49 | + </a> | ||
50 | + <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next"> | ||
51 | + <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> | ||
52 | + <span class="sr-only">Next</span> | ||
53 | + </a> | ||
54 | +</div> | ||
55 | + | ||
56 | + | ||
57 | + | ||
58 | + | ||
59 | + | ||
60 | + | ||
61 | + <div class="col-md-12 cards-content"> | ||
62 | + <h2 class=" my-subjects-title"><b><i>{% trans "My Subjects" %} ({{ total_subs }})</i></b></h2> | ||
63 | + | ||
64 | + {% if subjects|length > 0 %} | ||
65 | + <div class="panel-group" id="subject-accordion" role="tablist" aria-multiselectable="true"> | ||
66 | + {% for subject in subjects %} | ||
67 | + {% include "subjects/subject_card.html" with accordion_id="subject-accordion" %} | ||
68 | + {% endfor %} | ||
69 | + | ||
70 | + {% pagination request paginator page_obj %} | ||
71 | + </div> | ||
72 | + {% else %} | ||
73 | + <div class="text-center no-subjects"> | ||
74 | + <i class="fa fa-graduation-cap"></i> | ||
75 | + <h4>{% trans 'You still do not posses any subject in our platform' %}</h4> | ||
76 | + </div> | ||
77 | + {% endif %} | ||
78 | + </div> | ||
79 | + | ||
80 | + <div id="modal_subject"></div> | ||
81 | + | ||
82 | + <script type="text/javascript" src="{% static 'subjects/js/modal_subject.js' %}"></script> | ||
83 | + <script type="text/javascript" src="{% static 'js/category.js' %}"></script> | ||
84 | +{% endblock content %} |
subjects/templates/subjects/initial.html
@@ -18,7 +18,6 @@ | @@ -18,7 +18,6 @@ | ||
18 | 18 | ||
19 | 19 | ||
20 | <!-- Wrapper for slides --> | 20 | <!-- Wrapper for slides --> |
21 | - {% if user.is_staff %} | ||
22 | <div id="myCarousel" class="carousel slide " data-ride="carousel"> | 21 | <div id="myCarousel" class="carousel slide " data-ride="carousel"> |
23 | <!-- Indicators --> | 22 | <!-- Indicators --> |
24 | <ol class="carousel-indicators"> | 23 | <ol class="carousel-indicators"> |
@@ -28,7 +27,13 @@ | @@ -28,7 +27,13 @@ | ||
28 | <li data-target="#myCarousel" data-slide-to="3"></li> | 27 | <li data-target="#myCarousel" data-slide-to="3"></li> |
29 | </ol> | 28 | </ol> |
30 | 29 | ||
31 | - <div class="carousel-inner" role="listbox"> | 30 | +<div class="carousel-inner" role="listbox"> |
31 | + {% for new in news %} | ||
32 | + <div class="item" style="text-align:center"> | ||
33 | + <span><a href="{% url 'news:view' new.slug %}"> <img src="{{ new.image.url }}" alt="Image"> </a></span> | ||
34 | + </div> | ||
35 | + {% endfor %} | ||
36 | + | ||
32 | <div class="item active"> | 37 | <div class="item active"> |
33 | <h2 class=" my-subjects-title"><b><i>{% trans "Most popular keywords" %}</i></b></h2> | 38 | <h2 class=" my-subjects-title"><b><i>{% trans "Most popular keywords" %}</i></b></h2> |
34 | <div id="" class="col-md-12"> | 39 | <div id="" class="col-md-12"> |
@@ -50,7 +55,7 @@ | @@ -50,7 +55,7 @@ | ||
50 | </div> | 55 | </div> |
51 | </div> | 56 | </div> |
52 | 57 | ||
53 | - </div> | 58 | +</div> |
54 | 59 | ||
55 | <!-- Left and right controls --> | 60 | <!-- Left and right controls --> |
56 | <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev"> | 61 | <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev"> |
@@ -62,27 +67,6 @@ | @@ -62,27 +67,6 @@ | ||
62 | <span class="sr-only">Next</span> | 67 | <span class="sr-only">Next</span> |
63 | </a> | 68 | </a> |
64 | </div> | 69 | </div> |
65 | - {% else %} | ||
66 | - | ||
67 | - <h2 class=" my-subjects-title"><b><i>{% trans "Most popular keywords" %}</i></b></h2> | ||
68 | - <div id="" class="col-md-12"> | ||
69 | - <div class="users-cloud div-users-cloud"> | ||
70 | - <ul class=" users-cloud"> | ||
71 | - {% for tag in tags %} | ||
72 | - {% if tag.1 == 0 %} | ||
73 | - <li class="big"><a href="{% url 'subjects:search' %}?search={{tag.0}}">{{tag.0}}</a></li> | ||
74 | - {% elif tag.1 == 1 %} | ||
75 | - <li class="medium"><a href="{% url 'subjects:search' %}?search={{tag.0}}">{{tag.0}}</a></li> | ||
76 | - {% else %} | ||
77 | - <li class="small"><a href="{% url 'subjects:search' %}?search={{tag.0}}">{{tag.0}}</a></li> | ||
78 | - {% endif %} | ||
79 | - | ||
80 | - | ||
81 | - {% endfor %} | ||
82 | - </ul> | ||
83 | - </div> | ||
84 | - </div> | ||
85 | - {% endif %} | ||
86 | 70 | ||
87 | 71 | ||
88 | 72 |
subjects/views.py
@@ -32,13 +32,14 @@ from .forms import CreateSubjectForm, UpdateSubjectForm | @@ -32,13 +32,14 @@ from .forms import CreateSubjectForm, UpdateSubjectForm | ||
32 | from .utils import has_student_profile, has_professor_profile, count_subjects, get_category_page | 32 | from .utils import has_student_profile, has_professor_profile, count_subjects, get_category_page |
33 | from users.models import User | 33 | from users.models import User |
34 | from topics.models import Topic, Resource | 34 | from topics.models import Topic, Resource |
35 | +from news.models import News | ||
35 | 36 | ||
36 | from amadeus.permissions import has_category_permissions, has_subject_permissions, has_subject_view_permissions, has_resource_permissions | 37 | from amadeus.permissions import has_category_permissions, has_subject_permissions, has_subject_view_permissions, has_resource_permissions |
37 | 38 | ||
38 | class HomeView(LoginRequiredMixin, ListView): | 39 | class HomeView(LoginRequiredMixin, ListView): |
39 | login_url = reverse_lazy("users:login") | 40 | login_url = reverse_lazy("users:login") |
40 | redirect_field_name = 'next' | 41 | redirect_field_name = 'next' |
41 | - template_name = 'subjects/initial.html' | 42 | + template_name = 'subjects/home.html' |
42 | context_object_name = 'subjects' | 43 | context_object_name = 'subjects' |
43 | paginate_by = 10 | 44 | paginate_by = 10 |
44 | total = 0 | 45 | total = 0 |
@@ -59,6 +60,7 @@ class HomeView(LoginRequiredMixin, ListView): | @@ -59,6 +60,7 @@ class HomeView(LoginRequiredMixin, ListView): | ||
59 | context = super(HomeView, self).get_context_data(**kwargs) | 60 | context = super(HomeView, self).get_context_data(**kwargs) |
60 | context['title'] = _('Home') | 61 | context['title'] = _('Home') |
61 | context['show_buttons'] = True #So it shows subscribe and access buttons | 62 | context['show_buttons'] = True #So it shows subscribe and access buttons |
63 | + context['news'] = News.objects.all() | ||
62 | 64 | ||
63 | #bringing users | 65 | #bringing users |
64 | tag_amount = 50 | 66 | tag_amount = 50 |
@@ -521,8 +523,8 @@ class SubjectDetailView(LoginRequiredMixin, LogMixin, DetailView): | @@ -521,8 +523,8 @@ class SubjectDetailView(LoginRequiredMixin, LogMixin, DetailView): | ||
521 | expire_time = settings.SESSION_SECURITY_EXPIRE_AFTER | 523 | expire_time = settings.SESSION_SECURITY_EXPIRE_AFTER |
522 | 524 | ||
523 | context['participants'] = User.objects.filter( | 525 | context['participants'] = User.objects.filter( |
524 | - Q(is_staff = True) | Q(subject_student__slug = sub) | | ||
525 | - Q(professors__slug = sub) | | 526 | + Q(is_staff = True) | Q(subject_student__slug = sub) | |
527 | + Q(professors__slug = sub) | | ||
526 | Q(coordinators__subject_category__slug = sub) | 528 | Q(coordinators__subject_category__slug = sub) |
527 | ).extra(select = {'status': status_query}, select_params=(expire_time, expire_time,),).distinct().order_by('status', 'social_name','username').exclude(email = self.request.user.email) | 529 | ).extra(select = {'status': status_query}, select_params=(expire_time, expire_time,),).distinct().order_by('status', 'social_name','username').exclude(email = self.request.user.email) |
528 | 530 |
@@ -0,0 +1,66 @@ | @@ -0,0 +1,66 @@ | ||
1 | +$(function () { | ||
2 | + | ||
3 | + /* Script para abrir o modal com a imagem selecionada */ | ||
4 | + $("#id_image").change(function () { | ||
5 | + if (this.files && this.files[0]) { | ||
6 | + var reader = new FileReader(); | ||
7 | + reader.onload = function (e) { | ||
8 | + $("#image").attr("src", e.target.result); | ||
9 | + $("#modalCrop").modal("show"); | ||
10 | + } | ||
11 | + reader.readAsDataURL(this.files[0]); | ||
12 | + } | ||
13 | + }); | ||
14 | + | ||
15 | + /* Scripts da caixa de corte da imagem */ | ||
16 | + var $image = $("#image"); | ||
17 | + var cropBoxData; | ||
18 | + var canvasData; | ||
19 | + $("#modalCrop").on("shown.bs.modal", function () { | ||
20 | + $image.cropper({ | ||
21 | + viewMode: 1, | ||
22 | + aspectRatio: 1/1, | ||
23 | + minCropBoxWidth: 200, | ||
24 | + minCropBoxHeight: 200, | ||
25 | + ready: function () { | ||
26 | + $image.cropper("setCanvasData", canvasData); | ||
27 | + $image.cropper("setCropBoxData", cropBoxData); | ||
28 | + } | ||
29 | + }); | ||
30 | + }).on("hidden.bs.modal", function () { | ||
31 | + cropBoxData = $image.cropper("getCropBoxData"); | ||
32 | + canvasData = $image.cropper("getCanvasData"); | ||
33 | + $image.cropper("destroy"); | ||
34 | + }); | ||
35 | + | ||
36 | + $(".js-zoom-in").click(function () { | ||
37 | + $image.cropper("zoom", 0.1); | ||
38 | + }); | ||
39 | + | ||
40 | + $(".js-zoom-out").click(function () { | ||
41 | + $image.cropper("zoom", -0.1); | ||
42 | + }); | ||
43 | + | ||
44 | + /* Script para pegar os valores das dimensões e depois fechar o modal */ | ||
45 | + $(".js-crop-and-upload").click(function () { | ||
46 | + var cropData = $image.cropper("getData"); | ||
47 | + $("#id_x").val(cropData["x"]); | ||
48 | + $("#id_y").val(cropData["y"]); | ||
49 | + $("#id_height").val(cropData["height"]); | ||
50 | + $("#id_width").val(cropData["width"]); | ||
51 | + $("#modalCrop").modal('hide'); | ||
52 | + }); | ||
53 | + | ||
54 | + /* Script para remover o arquivo enviado caso o usuário clique em cancelar*/ | ||
55 | + $("#id_image").on('change', function(){ | ||
56 | + console.log(this.value); | ||
57 | + }); | ||
58 | + | ||
59 | + $('#crop_cancel').on('click', function(e){ | ||
60 | + var input = $("#id_image"); | ||
61 | + var holder = $("#pic_holder"); | ||
62 | + input.replaceWith(input.val('').clone(true)); | ||
63 | + holder.replaceWith(holder.val('').clone(true)); | ||
64 | + }); | ||
65 | + | ||
66 | +}); |
users/templates/users/_form.html
users/templates/users/list.html
users/templates/users/register.html