Martin Thorsen Ranang avatar Martin Thorsen Ranang committed 9a4851e

Upgraded package to become compatible with Turbogears 2.2.0 and repoze.who 2.1b1.

Comments (0)

Files changed (4)

 from setuptools import setup, find_packages
 import os
 
-version = '0.5.1'
+version = '0.6.0'
 
 setup(name='tgext.registration2',
       version=version,

tgext.registration2.egg-info/PKG-INFO

 Metadata-Version: 1.0
 Name: tgext.registration2
-Version: 0.5.1dev-20110401
+Version: 0.5.1dev-20130129
 Summary: set of controller entries to handle users' (self)registration in turbogears 2
 Home-page: http://resheteva.org.il/packages
 Author: alex bodnaru

tgext/registration2/controllers.py

 
 from pylons import request
 from tg import expose, redirect, config, validate, require, flash, TGController, url
-import repoze.what.predicates as identity
+try:
+    import tg.predicates as identity
+except:
+    # Pre Turbogears 2.2.0 + repoze.who 2.x:
+    import repoze.what.predicates as identity
 from repoze.who.plugins.auth_tkt import AuthTktCookiePlugin
 from pkg_resources import resource_string
 import logging
 DBSession = config.DBSession
 user_class = config.sa_auth['user_class']
 group_class = config.sa_auth['group_class']
-from repoze.what.plugins.sql import SqlGroupsAdapter
-groups = SqlGroupsAdapter(group_class, user_class, DBSession)
+#from repoze.what.plugins.sql import SqlGroupsAdapter
+#groups = SqlGroupsAdapter(group_class, user_class, DBSession)
 
 
 try:
         
     def add_groups(self, user, group_list):
         "Adds the user to each of the groups in the group_list sequence."
-        for group_name in group_list:
-            groups.include_item(group_name, user.user_name)
-            
+        for group in DBSession.query(group_class) \
+            .filter(group_class.name.in_(group_list)):
+            if group not in user.groups:
+                user.groups.add(group)
+        DBSession.flush()
+
     def remove_all_groups(self, user):
         "Removes the user from all groups that a User belongs to."
-        group_list = dict(request.identity)['groups']
-        for group_name in group_list:
-            groups.exclude_item(group_name, user.user_name)
-        
+        user.groups = []
+        DBSession.flush()
+
     def validation_hash(self, unique_input=""):
         "Returns a hash that can be used for validation."
         hash_str =  u" ".join((unique_input, request.remote_addr, 

tgext/registration2/widgets.py

 
 from pylons import request
-import repoze.what.predicates as identity
+try:
+    import tg.predicates as identity
+except:
+    # Pre Turbogears 2.2.0 + repoze.who 2.x:
+    import repoze.what.predicates as identity
 
 from tw.forms.validators import UnicodeString, Email, FancyValidator, Invalid, \
         All, Schema, FieldsMatch
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.