Advertisement
phiron

Projetos, notícias e hotsites

Apr 15th, 2015
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.40 KB | None | 0 0
  1. class Noticia(models.Model):
  2.     '''
  3.    classe abstrata que serve de base para todo o tipo de publicação
  4.    '''
  5.     nome=models.CharField("título",max_length=300)
  6.     chamada=models.TextField("chamada",max_length=1000,blank=True)
  7.     publicado_em=models.DateTimeField("data publicação",auto_now_add=True)
  8.     atualizado_em=models.DateTimeField("data atualização",auto_now=True)
  9.     visivel=models.BooleanField("visível",default=True)
  10.     projeto=models.ManyToManyField(
  11.                             Projeto,
  12.                             blank=True,
  13.                             limit_choices_to={'visivel': True},
  14.                             related_name='%(app_label)s_%(class)s',
  15.                             help_text="Selecione os projetos a qual a publicação se relaciona"
  16.                             )
  17.     texto=RichTextField("notícia",
  18.                         help_text='Espaço para inserir notícias, aceita fotos e formatações de texto avançadas,\
  19.                            bem como iframes para vídeos do youtube')
  20.     imagem=models.ImageField('banner',
  21.                              upload_to='noticias/',
  22.                              help_text="imagem principal da notícia",
  23.                              blank=True,
  24.                              null=True)
  25.     legenda_imagem = models.CharField('legenda banner notícia',
  26.                                       max_length=200,blank = True, null = True)
  27.     destaque=models.BooleanField('destaque',default=False)
  28.     def __str__(self):
  29.         '''
  30.        retorna o nome da notícia
  31.        '''
  32.         return self.nome
  33.     def get_absolute_url(self):
  34.         '''
  35.        retorna a url da notícia a ser apresentada
  36.        '''
  37.         #ainda a ser implementado...
  38.         return reverse('postagem:noticia', kwargs = {'slug':self.slug})
  39.    
  40.     class Meta:
  41.         verbose_name="notícia"
  42.         verbose_name_plural="notícias"
  43.  
  44. class Projetos(models.Model, RetornoDados):
  45.     '''
  46.    classe que armazena o projeto instituicional
  47.    '''
  48.     Codigo=models.CharField('código',max_length=20,help_text="código definido pelo financiador")
  49.     NomeCurto=models.CharField('Nome curto',max_length=50,blank=True)
  50.     Titulo=models.CharField('título',max_length=255,blank=True)
  51.     slug = models.SlugField(max_length=500,blank=True,null=True)
  52.     visivel = models.BooleanField(default=True)
  53.     visivel_site = models.BooleanField('hotsite',default = False,help_text="defina se existe um hotsite para esse objeto")
  54.     exibir_logo=models.CharField("Exibição da Logo",max_length=200,blank=True,null=True,
  55.                                  help_text="Escolha o local onde irá ficar o link do site",
  56.                                  choices=(('indice_geral','indice_geral'),
  57.                                            ('hotsite','hotsite'),
  58.                                            ),
  59.                                  default='indice_geral')
  60.     def __str__(self):
  61.         if self.titulo_site != None:
  62.             if self.titulo_site != "":
  63.                 return self.titulo_site
  64.             else:
  65.                 return self.NomeCurto
  66.         return self.NomeCurto
  67.     def get_absolute_url(self):
  68.         return reverse('institucional:projeto', kwargs = {'slug':self.slug})
  69.    
  70.     def finalizado(self):
  71.         '''
  72.        verifica se o projeto está ou não finalizado
  73.        '''
  74.         from datetime import datetime
  75.         agora=datetime.now()
  76.         if self.dataFinal > agora:
  77.             return False
  78.         elif self.dataInicial <= agora:
  79.             return True
  80.     class Meta:
  81.         verbose_name='projeto'
  82.         verbose_name_plural='projetos'
  83.         #order_with_respect_to = 'idEixo'
  84.         ordering=['NomeCurto',]
  85.  
  86.  
  87. class HotsiteBase(models.Model):
  88.     '''
  89.    classe base, abstrata para os hotsites
  90.    
  91.    '''
  92.     nome=models.CharField('título', max_length=500,help_text="Título do Hotsite",unique=True)
  93.     descricao=RichTextField('descrição',help_text="Descrição/Explicação do Hotsite ou tema desejado")
  94.     agrupamento=models.ManyToManyField(Projetos,
  95.                                     help_text="Selecione os projetos que deseja agregar a esse hotsite")
  96.     def get_absolute_url(self):
  97.         return reverse('hotsite:projeto', kwargs = {'slug':self.slug})
  98.     class Meta:
  99.         verbose_name="hotsite de projeto"
  100.         verbose_name_plural="hotsites de projetos"
  101.         ordering=['nome',]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement