cc1  v2.1
CC1 source code docs
 All Classes Namespaces Files Functions Variables Pages
user.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.cm.views.user.user
22 # @alldecoratedby{src.cm.utils.decorators.user_log}
23 #
24 # @author Tomek Sośnicki <tom.sosnicki@gmail.com>
25 #
26 
27 from cm.utils.exception import CMException
28 from cm.models.user import User
29 from cm.utils.decorators import user_log
30 
31 
32 @user_log(log=True)
33 ##
34 #
35 # Gets caller's quota.
36 #
37 # @cmview_user
38 # @response{dict} caller's quota
39 #
40 def get_quota(caller_id):
41  return User.get(caller_id).long_dict
42 
43 
44 # TODO: point_history returns a dict? It must be JSONED and like this does not work
45 @user_log(log=True)
46 ##
47 #
48 # @cmview_user
49 # @response caller's point history
50 #
51 def points_history(caller_id):
52  return User.get(caller_id).points_history()
53 
54 
55 @user_log(log=True)
56 ##
57 #
58 # Adds Users whose ids are listed in @prm{remote} and who are locally
59 # missing.
60 #
61 # @cmview_user
62 # @param_post{remote,list(int)} ids of the remote Users
63 #
64 def add_missing(caller_id, remote):
65 
66  # remote must be passed through POST as a list
67  # it is a list of users id
68  try:
69  # put all the user ids in a list
70  local = User.objects.all().values_list('id', flat=True)
71  # create user for all the ids which are in remote but not in the local cm
72  for user_id in [uid for uid in remote if uid not in local]:
73  User.create(user_id)
74  except:
75  raise CMException('user_create')
76