Commit e936b207380022a1127af33d2a1804a44d94aab9
1 parent
10fcdf39
Exists in
master
and in
5 other branches
ajustes no icone dos arquivos e mensagem de sucesso quando craido um file #381
Showing
5 changed files
with
110 additions
and
37 deletions
Show diff stats
@@ -0,0 +1,20 @@ | @@ -0,0 +1,20 @@ | ||
1 | +# -*- coding: utf-8 -*- | ||
2 | +# Generated by Django 1.10 on 2016-12-10 18:41 | ||
3 | +from __future__ import unicode_literals | ||
4 | + | ||
5 | +from django.db import migrations, models | ||
6 | + | ||
7 | + | ||
8 | +class Migration(migrations.Migration): | ||
9 | + | ||
10 | + dependencies = [ | ||
11 | + ('core', '0002_auto_20161124_1217'), | ||
12 | + ] | ||
13 | + | ||
14 | + operations = [ | ||
15 | + migrations.AlterField( | ||
16 | + model_name='mimetype', | ||
17 | + name='icon', | ||
18 | + field=models.CharField(max_length=50, verbose_name='Icon'), | ||
19 | + ), | ||
20 | + ] |
core/models.py
@@ -7,15 +7,12 @@ from django.contrib.postgres.fields import JSONField | @@ -7,15 +7,12 @@ from django.contrib.postgres.fields import JSONField | ||
7 | 7 | ||
8 | class MimeType(models.Model): | 8 | class MimeType(models.Model): |
9 | typ = models.CharField(_('Type'), max_length=100, unique=True) | 9 | typ = models.CharField(_('Type'), max_length=100, unique=True) |
10 | - icon = models.CharField(_('Icon'), max_length=50, unique=True) | 10 | + icon = models.CharField(_('Icon'), max_length=50) |
11 | 11 | ||
12 | class Meta: | 12 | class Meta: |
13 | verbose_name= _('Amadeus Mime Type') | 13 | verbose_name= _('Amadeus Mime Type') |
14 | verbose_name_plural = _('Amadeus Mime Types') | 14 | verbose_name_plural = _('Amadeus Mime Types') |
15 | 15 | ||
16 | - def get_icon(self, type): | ||
17 | - pass | ||
18 | - | ||
19 | def __str__(self): | 16 | def __str__(self): |
20 | return self.typ | 17 | return self.typ |
21 | 18 |
files/templates/files/create_file.html
@@ -99,6 +99,7 @@ | @@ -99,6 +99,7 @@ | ||
99 | contentType: false, | 99 | contentType: false, |
100 | success: function(data) { | 100 | success: function(data) { |
101 | $('#fileModal').modal('hide'); | 101 | $('#fileModal').modal('hide'); |
102 | + alertify.success('File successfully created!'); | ||
102 | $('#list-topic{{ topic.id }}-files').append(data); | 103 | $('#list-topic{{ topic.id }}-files').append(data); |
103 | $('#list-topic{{ topic.id }}-files-edit').append(data); | 104 | $('#list-topic{{ topic.id }}-files-edit').append(data); |
104 | }, | 105 | }, |
@@ -111,4 +112,4 @@ | @@ -111,4 +112,4 @@ | ||
111 | event.preventDefault(); | 112 | event.preventDefault(); |
112 | }); | 113 | }); |
113 | </script> | 114 | </script> |
114 | -{% endblock script_file %} | ||
115 | \ No newline at end of file | 115 | \ No newline at end of file |
116 | +{% endblock script_file %} |
files/utils.py
1 | mime_type_to_material_icons = { | 1 | mime_type_to_material_icons = { |
2 | - 'application/pdf': 'fa-file-pdf-o', | ||
3 | - 'text/plain': 'file-text-o', | ||
4 | - 'image/png': 'file-picture-o', | ||
5 | - 'image/jpeg': 'file-picture-o', | ||
6 | - 'application/msword': 'file-word-o', | ||
7 | - 'application/excel': 'file-powerpoint-o', | ||
8 | - 'application/vnd.ms-excel': 'file-powerpoint-o', | ||
9 | - 'application/x-excel': 'file-powerpoint-o', | ||
10 | - 'application/x-msexcel': 'file-powerpoint-o', | ||
11 | - 'application/mspowerpoint': 'file-powerpoint-o', | ||
12 | - 'application/powerpoint': 'file-powerpoint-o', | ||
13 | - 'application/vnd.ms-powerpoint': 'file-powerpoint-o', | ||
14 | - 'application/x-mspowerpoint': 'file-powerpoint-o', | ||
15 | - | ||
16 | -} | ||
17 | \ No newline at end of file | 2 | \ No newline at end of file |
3 | + | ||
4 | + # texto | ||
5 | + 'application/vnd.amazon.ebook':'fa-file-text-o', | ||
6 | + 'application/msword':'fa-file-word-o', | ||
7 | + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':'fa-file-word-o', | ||
8 | + 'application/epub+zip':'fa-file-text-o', | ||
9 | + 'application/vnd.oasis.opendocument.presentation':'fa-file-text-o', | ||
10 | + 'application/vnd.oasis.opendocument.spreadsheet':'fa-file-text-o', | ||
11 | + 'application/vnd.oasis.opendocument.text':'fa-file-text-o', | ||
12 | + 'application/pdf':'fa-file-pdf-o', | ||
13 | + 'application/vnd.ms-powerpoint':'fa-file-powerpoint-o', | ||
14 | + 'application/vnd.openxmlformats-officedocument.presentationml.presentation':'fa-file-powerpoint-o', | ||
15 | + 'application/vnd.ms-excel':'fa-file-excel-o', | ||
16 | + | ||
17 | + | ||
18 | + | ||
19 | + # codigos | ||
20 | + 'application/x-csh':'fa-file-code-o', | ||
21 | + 'text/css':'fa-file-code-o', | ||
22 | + 'text/csv':'fa-file-code-o', | ||
23 | + 'text/html':'fa-file-code-o', | ||
24 | + 'application/java-archive':'fa-file-code-o', | ||
25 | + 'application/js':'fa-file-code-o', | ||
26 | + 'application/json':'fa-file-code-o', | ||
27 | + 'application/rtf':'fa-file-code-o', | ||
28 | + 'application/x-sh':'fa-file-code-o', | ||
29 | + 'application/x-font-ttf':'fa-file-code-o', | ||
30 | + 'application/x-font-woff':'fa-file-code-o', | ||
31 | + 'application/xhtml+xml':'fa-file-code-o', | ||
32 | + 'application/xml':'fa-file-code-o', | ||
33 | + | ||
34 | + # compactados | ||
35 | + 'application/x-compressed':'fa-file-archive-o', | ||
36 | + 'application/x-zip-compressed':'fa-file-archive-o', | ||
37 | + 'application/zip':'fa-file-archive-o', | ||
38 | + 'application/gzip':'fa-file-archive-o', | ||
39 | + 'multipart/x-zip':'fa-file-archive-o', | ||
40 | + 'application/octet-stream':'fa-file-archive-o', | ||
41 | + 'application/x-bzip':'fa-file-archive-o', | ||
42 | + 'application/x-bzip2':'fa-file-archive-o', | ||
43 | + 'application/x-rar-compressed':'fa-file-archive-o', | ||
44 | + 'application/x-rar':'fa-file-archive-o', | ||
45 | + 'application/x-tar':'fa-file-archive-o', | ||
46 | + 'application/x-7z-compressed':'fa-file-archive-o', | ||
47 | + | ||
48 | + | ||
49 | + # tipos gerais | ||
50 | + 'text':'fa-file-text-o', | ||
51 | + 'multipart':'fa-file-o', | ||
52 | + 'image':'fa-file-image-o', | ||
53 | + 'audio':'fa-file-audio-o', | ||
54 | + 'video':'fa-file-video-o', | ||
55 | + 'application':'fa-file-o', | ||
56 | + 'x-world':'fa-file-o', | ||
57 | + 'drawing':'fa-file-image-o', | ||
58 | + 'model':'fa-file-image-o', | ||
59 | + 'x-conference':'fa-file-text-o', | ||
60 | + 'i-world':'fa-file-text-o', | ||
61 | + 'music':'fa-file-audio-o', | ||
62 | + 'message':'fa-file-text-o', | ||
63 | + 'x-music':'fa-file-audio-o', | ||
64 | + 'www':'fa-file-code-o', | ||
65 | + 'chemical':'fa-file-o', | ||
66 | + 'paleovu':'fa-file-o', | ||
67 | + 'xgl':'fa-file-movie-o', | ||
68 | + 'other':'fa-file-o', | ||
69 | +} |
files/views.py
@@ -50,33 +50,36 @@ class CreateFile(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin, | @@ -50,33 +50,36 @@ class CreateFile(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin, | ||
50 | self.object = form.save(commit = False) | 50 | self.object = form.save(commit = False) |
51 | topic = get_object_or_404(Topic, slug = self.kwargs.get('slug')) | 51 | topic = get_object_or_404(Topic, slug = self.kwargs.get('slug')) |
52 | self.object.topic = topic | 52 | self.object.topic = topic |
53 | - | 53 | + |
54 | self.object.name = str(self.object) | 54 | self.object.name = str(self.object) |
55 | - | 55 | + |
56 | 56 | ||
57 | # Set MimeType | 57 | # Set MimeType |
58 | file = self.request.FILES['file_url'] | 58 | file = self.request.FILES['file_url'] |
59 | try: | 59 | try: |
60 | if file: | 60 | if file: |
61 | file_type = file.content_type | 61 | file_type = file.content_type |
62 | - | ||
63 | - # Check if exist a mimetype in database | ||
64 | - try: | ||
65 | - self.object.file_type = MimeType.objects.get(typ = file_type) | ||
66 | - # Create if not | ||
67 | - except: | ||
68 | - mtype = MimeType.objects.create( | 62 | + # criar o mime type caso não tenha no banco ainda |
63 | + if (MimeType.objects.filter(typ = file_type).count()==0): | ||
64 | + mime = file_type | ||
65 | + if (not mime_type_to_material_icons.get(mime)): | ||
66 | + mime = mime.split("/")[0] | ||
67 | + if (not mime_type_to_material_icons.get(mime)): | ||
68 | + mime = "other" | ||
69 | + print (mime_type_to_material_icons.get(mime)) | ||
70 | + teste = mime_type_to_material_icons.get(mime) | ||
71 | + mtype = MimeType( | ||
69 | typ = file_type, | 72 | typ = file_type, |
70 | - icon = mime_type_to_material_icons[file_type] | 73 | + icon = teste |
71 | ) | 74 | ) |
72 | mtype.save() | 75 | mtype.save() |
73 | - self.object.file_type = mtype | 76 | + self.object.file_type = MimeType.objects.get(typ = file_type) |
77 | + | ||
74 | except: | 78 | except: |
75 | print('File not uploaded') | 79 | print('File not uploaded') |
76 | - # self.object.file_type = MimeType.objects.get(id = 1) | ||
77 | 80 | ||
78 | self.object.save() | 81 | self.object.save() |
79 | - #CREATE LOG | 82 | + #CREATE LOG |
80 | self.log_context['topic_id'] = topic.id | 83 | self.log_context['topic_id'] = topic.id |
81 | self.log_context['topic_name'] = topic.name | 84 | self.log_context['topic_name'] = topic.name |
82 | self.log_context['topic_slug'] = topic.slug | 85 | self.log_context['topic_slug'] = topic.slug |
@@ -90,7 +93,7 @@ class CreateFile(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin, | @@ -90,7 +93,7 @@ class CreateFile(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin, | ||
90 | 93 | ||
91 | #CREATE NOTIFICATION | 94 | #CREATE NOTIFICATION |
92 | super(CreateFile, self).createNotification(message="uploaded a File "+ self.object.name, actor=self.request.user, | 95 | super(CreateFile, self).createNotification(message="uploaded a File "+ self.object.name, actor=self.request.user, |
93 | - resource_name=self.object.name, resource_link= reverse('course:view_topic', args=[self.object.topic.slug]), | 96 | + resource_name=self.object.name, resource_link= reverse('course:view_topic', args=[self.object.topic.slug]), |
94 | users=self.object.topic.subject.students.all()) | 97 | users=self.object.topic.subject.students.all()) |
95 | 98 | ||
96 | self.log_context['file_id'] = self.object.id | 99 | self.log_context['file_id'] = self.object.id |
@@ -125,7 +128,7 @@ class CreateFile(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin, | @@ -125,7 +128,7 @@ class CreateFile(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin, | ||
125 | 128 | ||
126 | def get_success_url(self): | 129 | def get_success_url(self): |
127 | self.success_url = redirect('course:file:render_file', id = self.object.id) | 130 | self.success_url = redirect('course:file:render_file', id = self.object.id) |
128 | - | 131 | + |
129 | return self.success_url | 132 | return self.success_url |
130 | 133 | ||
131 | 134 | ||
@@ -211,7 +214,7 @@ class UpdateFile(LoginRequiredMixin, HasRoleMixin, LogMixin, generic.UpdateView) | @@ -211,7 +214,7 @@ class UpdateFile(LoginRequiredMixin, HasRoleMixin, LogMixin, generic.UpdateView) | ||
211 | 214 | ||
212 | def get_success_url(self): | 215 | def get_success_url(self): |
213 | self.success_url = reverse_lazy('course:file:render_file', args = (self.object.id, )) | 216 | self.success_url = reverse_lazy('course:file:render_file', args = (self.object.id, )) |
214 | - | 217 | + |
215 | return self.success_url | 218 | return self.success_url |
216 | 219 | ||
217 | 220 | ||
@@ -258,4 +261,4 @@ class DeleteFile(LoginRequiredMixin, HasRoleMixin, LogMixin, generic.DeleteView) | @@ -258,4 +261,4 @@ class DeleteFile(LoginRequiredMixin, HasRoleMixin, LogMixin, generic.DeleteView) | ||
258 | 261 | ||
259 | super(DeleteFile, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | 262 | super(DeleteFile, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) |
260 | 263 | ||
261 | - return reverse_lazy('course:view_topic', kwargs={'slug' : self.object.topic.slug}) | ||
262 | \ No newline at end of file | 264 | \ No newline at end of file |
265 | + return reverse_lazy('course:view_topic', kwargs={'slug' : self.object.topic.slug}) |