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.views.admin_clm.news
22 #
23 # @alldecoratedby{src.clm.utils.decorators.admin_clm_log}
24 #
25 
26 from clm.models.news import News
27 from clm.utils.exception import CLMException
28 from datetime import datetime
29 from clm.utils.decorators import admin_clm_log
30 
31 
32 @admin_clm_log(log=True)
33 ##
34 #
35 # @clmview_admin_clm
36 # @param_post{news_id}
37 # @response{dict} dict property of the requested News
38 #
39 def get_by_id(cm_id, caller_id, news_id):
40  return News.get(news_id).dict
41 
42 
43 @admin_clm_log(log=True)
44 ##
45 #
46 # Creates and saves new News. Such a News appears on the Web Interface's
47 # home screen.
48 #
49 # @clmview_admin_clm
50 # @param_post{topic,string}
51 # @param_post{content,string}
52 # @param_post{sticky,bool} whether the News should stay displayed long-term
53 #
54 def add(cm_id, caller_id, topic='', content='', sticky=False):
55 
56  news = News()
57  news.topic = topic
58  news.content = content
59  news.sticky = sticky
60  news.date = datetime.now()
61 
62  try:
63  news.save()
64  except:
65  raise CLMException('news_create')
66 
67 
68 @admin_clm_log(log=True)
69 ##
70 #
71 # Deletes permanently specified News. Deleted News can i no way be
72 # recovered.
73 #
74 # @clmview_admin_clm
75 # @param_post{news_id,int} id of the News to delete
76 #
77 def delete(cm_id, caller_id, news_id):
78  news = News.get(news_id)
79  try:
80  news.delete()
81  except CLMException, e:
82  raise e
83  except Exception, e:
84  raise CLMException('news_delete')
85 
86 
87 @admin_clm_log(log=True)
88 ##
89 #
90 # @clmview_admin_clm
91 # @param_post{news_id,int} id of the News to edit
92 # @param_post{topic,string} new topic of the News
93 # @param_post{content,string} new content of the News
94 # @param_post{sticky,bool} whether the News should stay displayed long-term
95 #
96 def edit(cm_id, caller_id, news_id, topic=None, content=None, sticky=None):
97  news = News.get(news_id)
98  if topic:
99  news.topic = topic
100  if content:
101  news.content = content
102  if sticky is not None:
103  news.sticky = sticky
104  try:
105  news.save()
106  except:
107  raise CLMException('news_edit')
108