cc1  v2.1
CC1 source code docs
 All Classes Namespaces Files Functions Variables Pages
news.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 # @COPYRIGHT_begin
3 #
4 # Copyright [2010-2014] Institute of Nuclear Physics PAN, Krakow, Poland
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18 # @COPYRIGHT_end
19 
20 ##
21 # @package src.clm.models.news
22 #
23 # @author Tomek Sośnicki <tom.sosnicki@gmail.com>
24 # @author Maciej Nabożny <di.dijo@gmail.com>
25 #
26 
27 from django.db import models
28 from clm.utils.exception import CLMException
29 
30 
31 ##
32 #
33 # @model{NEWS}
34 #
35 # News is an entity for providing latest common News, targeted to all users,
36 # available on the main page of the CC1 webinterface.
37 #
38 class News(models.Model):
39  ## News topic @field
40  topic = models.CharField(max_length=255)
41  ## News content @field
42  content = models.TextField()
43  ## whether this News is sticky and should be displayed for a longer time @field
44  sticky = models.IntegerField()
45  ## this News' publication date @field
46  date = models.DateTimeField()
47 
48  class Meta:
49  app_label = 'clm'
50 
51  ##
52  #
53  # @returns{string} this News topic
54  #
55  def __unicode__(self):
56  return self.topic
57 
58  @property
59  ##
60  #
61  # @returns{dict} this New's data
62  # \n fields:
63  # @dictkey{news_id,int} id of this News
64  # @dictkey{topic,string} topic of this News
65  # @dictkey{content,string} content of this News
66  # @dictkey{sticky,bool} whether this News is sticky and should be keept
67  # displayed for longer period
68  # @dictkey{date,datetime.datetime} creation date of this News
69  #
70  def dict(self):
71  d = {}
72  d['news_id'] = self.id
73  d['topic'] = self.topic
74  d['content'] = self.content
75  d['sticky'] = self.sticky
76  d['date'] = self.date
77  return d
78 
79  @staticmethod
80  ##
81  #
82  # @parameter{news_id,int} id of the requested News
83  #
84  # @returns{News} instance of the requested News
85  #
86  # @raises{news_get,CLMException} no such News found
87  #
88  def get(news_id):
89  try:
90  news = News.objects.get(pk=news_id)
91  except:
92  raise CLMException('news_get')
93 
94  return news
95