From e936b207380022a1127af33d2a1804a44d94aab9 Mon Sep 17 00:00:00 2001 From: Jailson Dias Date: Sat, 10 Dec 2016 15:51:16 -0300 Subject: [PATCH] ajustes no icone dos arquivos e mensagem de sucesso quando craido um file #381 --- core/migrations/0003_auto_20161210_1541.py | 20 ++++++++++++++++++++ core/models.py | 5 +---- files/templates/files/create_file.html | 3 ++- files/utils.py | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------- files/views.py | 37 ++++++++++++++++++++----------------- 5 files changed, 110 insertions(+), 37 deletions(-) create mode 100644 core/migrations/0003_auto_20161210_1541.py diff --git a/core/migrations/0003_auto_20161210_1541.py b/core/migrations/0003_auto_20161210_1541.py new file mode 100644 index 0000000..ead48a8 --- /dev/null +++ b/core/migrations/0003_auto_20161210_1541.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2016-12-10 18:41 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0002_auto_20161124_1217'), + ] + + operations = [ + migrations.AlterField( + model_name='mimetype', + name='icon', + field=models.CharField(max_length=50, verbose_name='Icon'), + ), + ] diff --git a/core/models.py b/core/models.py index f8141e0..5fd9e9b 100644 --- a/core/models.py +++ b/core/models.py @@ -7,15 +7,12 @@ from django.contrib.postgres.fields import JSONField class MimeType(models.Model): typ = models.CharField(_('Type'), max_length=100, unique=True) - icon = models.CharField(_('Icon'), max_length=50, unique=True) + icon = models.CharField(_('Icon'), max_length=50) class Meta: verbose_name= _('Amadeus Mime Type') verbose_name_plural = _('Amadeus Mime Types') - def get_icon(self, type): - pass - def __str__(self): return self.typ diff --git a/files/templates/files/create_file.html b/files/templates/files/create_file.html index 17cd60a..2cb9466 100644 --- a/files/templates/files/create_file.html +++ b/files/templates/files/create_file.html @@ -99,6 +99,7 @@ contentType: false, success: function(data) { $('#fileModal').modal('hide'); + alertify.success('File successfully created!'); $('#list-topic{{ topic.id }}-files').append(data); $('#list-topic{{ topic.id }}-files-edit').append(data); }, @@ -111,4 +112,4 @@ event.preventDefault(); }); -{% endblock script_file %} \ No newline at end of file +{% endblock script_file %} diff --git a/files/utils.py b/files/utils.py index be1b4de..f49c3b6 100644 --- a/files/utils.py +++ b/files/utils.py @@ -1,16 +1,68 @@ mime_type_to_material_icons = { - 'application/pdf': 'fa-file-pdf-o', - 'text/plain': 'file-text-o', - 'image/png': 'file-picture-o', - 'image/jpeg': 'file-picture-o', - 'application/msword': 'file-word-o', - 'application/excel': 'file-powerpoint-o', - 'application/vnd.ms-excel': 'file-powerpoint-o', - 'application/x-excel': 'file-powerpoint-o', - 'application/x-msexcel': 'file-powerpoint-o', - 'application/mspowerpoint': 'file-powerpoint-o', - 'application/powerpoint': 'file-powerpoint-o', - 'application/vnd.ms-powerpoint': 'file-powerpoint-o', - 'application/x-mspowerpoint': 'file-powerpoint-o', - -} \ No newline at end of file + + # texto + 'application/vnd.amazon.ebook':'fa-file-text-o', + 'application/msword':'fa-file-word-o', + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':'fa-file-word-o', + 'application/epub+zip':'fa-file-text-o', + 'application/vnd.oasis.opendocument.presentation':'fa-file-text-o', + 'application/vnd.oasis.opendocument.spreadsheet':'fa-file-text-o', + 'application/vnd.oasis.opendocument.text':'fa-file-text-o', + 'application/pdf':'fa-file-pdf-o', + 'application/vnd.ms-powerpoint':'fa-file-powerpoint-o', + 'application/vnd.openxmlformats-officedocument.presentationml.presentation':'fa-file-powerpoint-o', + 'application/vnd.ms-excel':'fa-file-excel-o', + + + + # codigos + 'application/x-csh':'fa-file-code-o', + 'text/css':'fa-file-code-o', + 'text/csv':'fa-file-code-o', + 'text/html':'fa-file-code-o', + 'application/java-archive':'fa-file-code-o', + 'application/js':'fa-file-code-o', + 'application/json':'fa-file-code-o', + 'application/rtf':'fa-file-code-o', + 'application/x-sh':'fa-file-code-o', + 'application/x-font-ttf':'fa-file-code-o', + 'application/x-font-woff':'fa-file-code-o', + 'application/xhtml+xml':'fa-file-code-o', + 'application/xml':'fa-file-code-o', + + # compactados + 'application/x-compressed':'fa-file-archive-o', + 'application/x-zip-compressed':'fa-file-archive-o', + 'application/zip':'fa-file-archive-o', + 'application/gzip':'fa-file-archive-o', + 'multipart/x-zip':'fa-file-archive-o', + 'application/octet-stream':'fa-file-archive-o', + 'application/x-bzip':'fa-file-archive-o', + 'application/x-bzip2':'fa-file-archive-o', + 'application/x-rar-compressed':'fa-file-archive-o', + 'application/x-rar':'fa-file-archive-o', + 'application/x-tar':'fa-file-archive-o', + 'application/x-7z-compressed':'fa-file-archive-o', + + + # tipos gerais + 'text':'fa-file-text-o', + 'multipart':'fa-file-o', + 'image':'fa-file-image-o', + 'audio':'fa-file-audio-o', + 'video':'fa-file-video-o', + 'application':'fa-file-o', + 'x-world':'fa-file-o', + 'drawing':'fa-file-image-o', + 'model':'fa-file-image-o', + 'x-conference':'fa-file-text-o', + 'i-world':'fa-file-text-o', + 'music':'fa-file-audio-o', + 'message':'fa-file-text-o', + 'x-music':'fa-file-audio-o', + 'www':'fa-file-code-o', + 'chemical':'fa-file-o', + 'paleovu':'fa-file-o', + 'xgl':'fa-file-movie-o', + 'other':'fa-file-o', +} diff --git a/files/views.py b/files/views.py index 5a754f8..e04f7d5 100644 --- a/files/views.py +++ b/files/views.py @@ -50,33 +50,36 @@ class CreateFile(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin, self.object = form.save(commit = False) topic = get_object_or_404(Topic, slug = self.kwargs.get('slug')) self.object.topic = topic - + self.object.name = str(self.object) - + # Set MimeType file = self.request.FILES['file_url'] try: if file: file_type = file.content_type - - # Check if exist a mimetype in database - try: - self.object.file_type = MimeType.objects.get(typ = file_type) - # Create if not - except: - mtype = MimeType.objects.create( + # criar o mime type caso não tenha no banco ainda + if (MimeType.objects.filter(typ = file_type).count()==0): + mime = file_type + if (not mime_type_to_material_icons.get(mime)): + mime = mime.split("/")[0] + if (not mime_type_to_material_icons.get(mime)): + mime = "other" + print (mime_type_to_material_icons.get(mime)) + teste = mime_type_to_material_icons.get(mime) + mtype = MimeType( typ = file_type, - icon = mime_type_to_material_icons[file_type] + icon = teste ) mtype.save() - self.object.file_type = mtype + self.object.file_type = MimeType.objects.get(typ = file_type) + except: print('File not uploaded') - # self.object.file_type = MimeType.objects.get(id = 1) self.object.save() - #CREATE LOG + #CREATE LOG self.log_context['topic_id'] = topic.id self.log_context['topic_name'] = topic.name self.log_context['topic_slug'] = topic.slug @@ -90,7 +93,7 @@ class CreateFile(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin, #CREATE NOTIFICATION super(CreateFile, self).createNotification(message="uploaded a File "+ self.object.name, actor=self.request.user, - resource_name=self.object.name, resource_link= reverse('course:view_topic', args=[self.object.topic.slug]), + resource_name=self.object.name, resource_link= reverse('course:view_topic', args=[self.object.topic.slug]), users=self.object.topic.subject.students.all()) self.log_context['file_id'] = self.object.id @@ -125,7 +128,7 @@ class CreateFile(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin, def get_success_url(self): self.success_url = redirect('course:file:render_file', id = self.object.id) - + return self.success_url @@ -211,7 +214,7 @@ class UpdateFile(LoginRequiredMixin, HasRoleMixin, LogMixin, generic.UpdateView) def get_success_url(self): self.success_url = reverse_lazy('course:file:render_file', args = (self.object.id, )) - + return self.success_url @@ -258,4 +261,4 @@ class DeleteFile(LoginRequiredMixin, HasRoleMixin, LogMixin, generic.DeleteView) super(DeleteFile, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) - return reverse_lazy('course:view_topic', kwargs={'slug' : self.object.topic.slug}) \ No newline at end of file + return reverse_lazy('course:view_topic', kwargs={'slug' : self.object.topic.slug}) -- libgit2 0.21.2