models.py
2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""
Copyright 2016, 2017 UFPE - Universidade Federal de Pernambuco
Este arquivo é parte do programa Amadeus Sistema de Gestão de Aprendizagem, ou simplesmente Amadeus LMS
O Amadeus LMS é um software livre; você pode redistribui-lo e/ou modifica-lo dentro dos termos da Licença Pública Geral GNU como publicada pela Fundação do Software Livre (FSF); na versão 2 da Licença.
Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU para maiores detalhes.
Você deve ter recebido uma cópia da Licença Pública Geral GNU, sob o título "LICENSE", junto com este programa, se não, escreva para a Fundação do Software Livre (FSF) Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
"""
import os
from django.db import models
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse_lazy
from topics.models import Resource
valid_formats = [
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.ms-excel','application/vnd.oasis.opendocument.spreadsheet','text/csv'
]
def validate_file_extension(value):
if hasattr(value.file, 'content_type'):
if not value.file.content_type in valid_formats:
raise ValidationError(_('Please select a valid file. The uploaded file must have one of the following extensions: .csv, .xlx, .xls and .xlsx'))
class Bulletin(Resource):
content = models.TextField(_('Bulletin Content'), blank = True)
file_content = models.FileField(_('Goals'), blank = True, upload_to = 'bulletin/goals', validators = [validate_file_extension])
indicators = models.FileField(_('Relevant Indicators'), blank = True,null = True, upload_to = 'bulletin/indicators', validators = [validate_file_extension])
class Meta:
verbose_name = _('Bulletin')
verbose_name_plural = _('Bulletins')
def __str__(self):
return self.name
def access_link(self):
if self.show_window:
return reverse_lazy('bulletin:window_view', args = (), kwargs = {'slug': self.slug})
return reverse_lazy('bulletin:view', args = (), kwargs = {'slug': self.slug})
def update_link(self):
return 'bulletin:update'
def delete_link(self):
return 'bulletin:delete'
def delete_message(self):
return _('Are you sure you want delete the bulletin')