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.wi.models.user
22 #
23 # @author Piotr Wójcik
24 # @author Przemysław Syktus
25 # @date 21.09.2010
26 #
27 
28 from django.db import models
29 
30 
31 ##
32 #
33 # Helper function that returns \c User object based on the provided dictionary.
34 #
35 # @parameter{user}
36 # @returns{User}
37 #
38 def parse_user(user):
39  return User(user_id=user['user_id'], firstname=user['first'], lastname=user['last'], username=user['login'],
40  password='', email=user['email'], organization=user['organization'], is_active=user['is_active'],
41  is_admin_clm=user['is_superuser'], is_admin_cm=user['is_superuser_cm'], cm_id=user['default_cluster_id'],
42  default_cluster_id=user['default_cluster_id'])
43 
44 
45 ##
46 #
47 # Class for representation of the interface's users.
48 #
49 class User:
50  username = models.CharField('username', max_length=30, unique=True)
51  firstname = models.CharField('firstname', max_length=60)
52  lastname = models.CharField('lastname', max_length=60)
53  organization = models.CharField('organization', max_length=60)
54  email = models.EmailField('e-mail address', blank=True)
55  password = models.CharField('password', max_length=128)
56  cm_password = models.CharField('cm_password', max_length=128)
57  is_active = models.IntegerField('active', default=0)
58  is_admin_clm = models.BooleanField('admin clm', default=False)
59  is_admin_cm = models.BooleanField('admin cm', default=False)
60  is_logged_admin_cm = models.BooleanField('admin cm', default=False)
61  cm_id = models.IntegerField('cm_id', default=0)
62  default_cluster_id = models.IntegerField('default_cluster_id', default=0)
63 
64  def __init__(self, user_id, cm_id, firstname, lastname, username, organization, password, email, is_active=0,
65  is_admin_clm=False, is_admin_cm=False, is_logged_admin_cm=False, default_cluster_id=0):
66  self.user_id = user_id
67  self.cm_id = cm_id
68  self.firstname = firstname
69  self.lastname = lastname
70  self.organization = organization
71  self.username = username
72  self.email = email
73  self.password = password
74  self.cm_password = None
75  self.is_active = is_active
76  self.is_admin_clm = is_admin_clm
77  self.is_admin_cm = is_admin_cm
78  self.is_logged_admin_cm = is_logged_admin_cm
79  self.default_cluster_id = default_cluster_id
80 
81  def __unicode__(self):
82  return self.username
83 
84  def set_password(self, password):
85  self.password = password
86