comparison rhodecode/model/users_group.py @ 959:fff21c9b075c beta

#56 fixed found bugs, implemented adding of new group + forms+validators fixed db schema naming
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 26 Jan 2011 17:34:37 +0100
parents rhodecode/model/user_group.py@83d35d716a02
children 2c8fd84935a4
comparison
equal deleted inserted replaced
958:7d1483f3170b 959:fff21c9b075c
1 # -*- coding: utf-8 -*-
2 """
3 rhodecode.model.user_group
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~
5
6 users groups model for RhodeCode
7
8 :created_on: Jan 25, 2011
9 :author: marcink
10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
12 """
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License
15 # as published by the Free Software Foundation; version 2
16 # of the License or (at your opinion) any later version of the license.
17 #
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26 # MA 02110-1301, USA.
27
28 import logging
29 import traceback
30
31 from pylons.i18n.translation import _
32
33 from rhodecode.model import BaseModel
34 from rhodecode.model.caching_query import FromCache
35 from rhodecode.model.db import UsersGroup
36
37 from rhodecode.lib.exceptions import DefaultUserException, UserOwnsReposException
38
39 from sqlalchemy.exc import DatabaseError
40
41 log = logging.getLogger(__name__)
42
43
44 class UsersGroupModel(BaseModel):
45
46 def get(self, users_group_id, cache=False):
47 users_group = self.sa.query(UsersGroup)
48 if cache:
49 users_group = users_group.options(FromCache("sql_cache_short",
50 "get_users_group_%s" % users_group_id))
51 return users_group.get(users_group_id)
52
53
54 def get_by_groupname(self, users_group_name, cache=False, case_insensitive=False):
55
56 if case_insensitive:
57 user = self.sa.query(UsersGroup)\
58 .filter(UsersGroup.users_group_name.ilike(users_group_name))
59 else:
60 user = self.sa.query(UsersGroup)\
61 .filter(UsersGroup.users_group_name == users_group_name)
62 if cache:
63 user = user.options(FromCache("sql_cache_short",
64 "get_user_%s" % users_group_name))
65 return user.scalar()
66
67 def create(self, form_data):
68 try:
69 new_users_group = UsersGroup()
70 for k, v in form_data.items():
71 setattr(new_users_group, k, v)
72
73 self.sa.add(new_users_group)
74 self.sa.commit()
75 except:
76 log.error(traceback.format_exc())
77 self.sa.rollback()
78 raise
79