##// END OF EJS Templates
fixed typo
marcink -
r1692:b76bb93d beta
parent child Browse files
Show More
@@ -1,90 +1,90 b''
1 1 # -*- coding: utf-8 -*-
2 2 """
3 3 rhodecode.model.users_group
4 4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 5
6 6 users group model for RhodeCode
7 7
8 8 :created_on: Oct 1, 2011
9 9 :author: nvinot
10 10 :copyright: (C) 2011-2011 Nicolas Vinot <aeris@imirhil.fr>
11 11 :license: GPLv3, see COPYING for more details.
12 12 """
13 13 # This program is free software: you can redistribute it and/or modify
14 14 # it under the terms of the GNU General Public License as published by
15 15 # the Free Software Foundation, either version 3 of the License, or
16 16 # (at your option) any later version.
17 17 #
18 18 # This program is distributed in the hope that it will be useful,
19 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 21 # GNU General Public License for more details.
22 22 #
23 23 # You should have received a copy of the GNU General Public License
24 24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 25
26 26 import logging
27 27 import traceback
28 28
29 29 from rhodecode.lib.caching_query import FromCache
30 30
31 from rhodecode.model import BaseMode
31 from rhodecode.model import BaseModel
32 32 from rhodecode.model.db import UsersGroupMember, UsersGroup
33 33
34 34 log = logging.getLogger(__name__)
35 35
36 36 class UsersGroupModel(BaseModel):
37 37
38 38 def get(self, users_group_id, cache = False):
39 39 users_group = UsersGroup.query()
40 40 if cache:
41 41 users_group = users_group.options(FromCache("sql_cache_short",
42 42 "get_users_group_%s" % users_group_id))
43 43 return users_group.get(users_group_id)
44 44
45 45 def get_by_name(self, name, cache = False, case_insensitive = False):
46 46 users_group = UsersGroup.query()
47 47 if case_insensitive:
48 48 users_group = users_group.filter(UsersGroup.users_group_name.ilike(name))
49 49 else:
50 50 users_group = users_group.filter(UsersGroup.users_group_name == name)
51 51 if cache:
52 52 users_group = users_group.options(FromCache("sql_cache_short",
53 53 "get_users_group_%s" % name))
54 54 return users_group.scalar()
55 55
56 56 def create(self, form_data):
57 57 try:
58 58 new_users_group = UsersGroup()
59 59 for k, v in form_data.items():
60 60 setattr(new_users_group, k, v)
61 61
62 62 self.sa.add(new_users_group)
63 63 self.sa.commit()
64 64 return new_users_group
65 65 except:
66 66 log.error(traceback.format_exc())
67 67 self.sa.rollback()
68 68 raise
69 69
70 70 def add_user_to_group(self, users_group, user):
71 71 for m in users_group.members:
72 72 u = m.user
73 73 if u.user_id == user.user_id:
74 74 return m
75 75
76 76 try:
77 77 users_group_member = UsersGroupMember()
78 78 users_group_member.user = user
79 79 users_group_member.users_group = users_group
80 80
81 81 users_group.members.append(users_group_member)
82 82 user.group_member.append(users_group_member)
83 83
84 84 self.sa.add(users_group_member)
85 85 self.sa.commit()
86 86 return users_group_member
87 87 except:
88 88 log.error(traceback.format_exc())
89 89 self.sa.rollback()
90 90 raise
General Comments 0
You need to be logged in to leave comments. Login now