Changeset 12721
- Timestamp:
- Mar 14, 2013, 8:55:12 PM (11 years ago)
- Location:
- accountmanagerplugin/trunk
- Files:
-
- 2 added
- 10 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
accountmanagerplugin/trunk/acct_mgr/admin.py
r12706 r12721 30 30 from acct_mgr.api import IUserIdChanger 31 31 from acct_mgr.api import _, N_, dgettext, gettext, ngettext, tag_ 32 from acct_mgr.compat import as_int, is_enabled, exception_to_unicode 33 from acct_mgr.compat import get_pretty_dateinfo 32 34 from acct_mgr.guard import AccountGuard 33 35 from acct_mgr.model import change_uid, del_user_attribute, email_verified … … 36 38 from acct_mgr.register import RegistrationModule 37 39 from acct_mgr.web_ui import AccountModule, LoginModule 38 from acct_mgr.util import as_int, is_enabled, exception_to_unicode 39 from acct_mgr.util import get_pretty_dateinfo, pretty_precise_timedelta 40 from acct_mgr.util import pretty_precise_timedelta 40 41 41 42 … … 696 697 # acct_mgr.register.GenericRegistrationInspector. 697 698 try: 698 doc = gettext(check.doc) 699 if check._description: 700 doc = gettext(check._description) 699 701 except AttributeError: 700 702 doc = check.__class__.__doc__ … … 819 821 data.update(dict(roundup=roundup, roundup_defaults=roundup_defaults)) 820 822 821 add_script(req, 'acct_mgr/ acctmgr_admin.js')823 add_script(req, 'acct_mgr/js/acctmgr_admin.js') 822 824 add_stylesheet(req, 'acct_mgr/acctmgr.css') 823 825 add_stylesheet(req, 'common/css/report.css') -
accountmanagerplugin/trunk/acct_mgr/api.py
r12706 r12721 48 48 pass 49 49 return string 50 51 from acct_mgr.compat import cleandoc 52 cleandoc_ = cleandoc 50 53 51 54 -
accountmanagerplugin/trunk/acct_mgr/macros.py
r11930 r12721 20 20 from acct_mgr.admin import fetch_user_data 21 21 from acct_mgr.api import AccountManager, CommonTemplateProvider, _ 22 from acct_mgr.compat import get_pretty_dateinfo 22 23 from acct_mgr.guard import AccountGuard 23 from acct_mgr.util import get_pretty_dateinfo24 24 25 25 -
accountmanagerplugin/trunk/acct_mgr/model.py
r12706 r12721 16 16 17 17 from acct_mgr.api import GenericUserIdChanger 18 from acct_mgr.compat import as_int, exception_to_unicode 18 19 from acct_mgr.hashlib_compat import md5 19 from acct_mgr.util import as_int, exception_to_unicode20 20 21 21 -
accountmanagerplugin/trunk/acct_mgr/register.py
r12689 r12721 27 27 from acct_mgr.api import AccountManager, CommonTemplateProvider 28 28 from acct_mgr.api import IAccountRegistrationInspector 29 from acct_mgr.api import _, N_, dgettext, gettext, tag_ 29 from acct_mgr.api import _, N_, cleandoc_, dgettext, gettext, tag_ 30 from acct_mgr.compat import is_enabled 30 31 from acct_mgr.model import email_associated, get_user_attribute 31 32 from acct_mgr.model import set_user_attribute 32 from acct_mgr.util import containsAny , is_enabled33 from acct_mgr.util import containsAny 33 34 34 35 … … 52 53 class GenericRegistrationInspector(Component): 53 54 """Generic check class, great for creating simple checks quickly.""" 55 _description = '' 54 56 55 57 implements(IAccountRegistrationInspector) 56 58 57 59 abstract = True 58 59 @property60 def doc(self):61 return N_(self.__class__.__doc__)62 60 63 61 def render_registration_fields(self, req, data): … … 85 83 86 84 class BasicCheck(GenericRegistrationInspector): 85 _description = cleandoc_( 87 86 """A collection of basic checks. 88 87 89 This includes checking for90 * emptiness (no user input for username and/or password)91 * some blacklisted username characters92 * upper-cased usernames (reserved for Trac permission actions)93 * some reserved usernames94 * a username duplicate in configured password stores95 96 ''This check is bypassed for requests regarding user's own preferences.''97 """ 88 This includes checking for 89 * emptiness (no user input for username and/or password) 90 * some blacklisted username characters 91 * upper-cased usernames (reserved for Trac permission actions) 92 * some reserved usernames 93 * a username duplicate in configured password stores 94 95 ''This check is bypassed for requests regarding user's own preferences.'' 96 """) 98 97 99 98 def validate_registration(self, req): … … 162 161 163 162 class BotTrapCheck(GenericRegistrationInspector): 163 _description = cleandoc_( 164 164 """A collection of simple bot checks. 165 165 166 ''This check is bypassed for requests by an authenticated user.''167 """ 166 ''This check is bypassed for requests by an authenticated user.'' 167 """) 168 168 169 169 reg_basic_token = Option('account-manager', 'register_basic_token', '', … … 212 212 213 213 class EmailCheck(GenericRegistrationInspector): 214 _description = cleandoc_( 214 215 """A collection of checks for email addresses. 215 216 216 ''This check is bypassed, if account verification is disabled.''217 """ 217 ''This check is bypassed, if account verification is disabled.'' 218 """) 218 219 219 220 def render_registration_fields(self, req, data): … … 273 274 274 275 class RegExpCheck(GenericRegistrationInspector): 276 _description = cleandoc_( 275 277 """A collection of checks based on regular expressions. 276 278 277 ''It depends on !EmailCheck being enabled too for using it's input field.278 Likewise email checking is bypassed, if account verification is disabled.''279 """ 279 ''It depends on !EmailCheck being enabled too for using it's input field. 280 Likewise email checking is bypassed, if account verification is disabled.'' 281 """) 280 282 281 283 username_regexp = Option('account-manager', 'username_regexp', … … 312 314 313 315 class UsernamePermCheck(GenericRegistrationInspector): 316 _description = cleandoc_( 314 317 """Check for usernames referenced in the permission system. 315 318 316 ''This check is bypassed for requests by an authenticated user.''317 """ 319 ''This check is bypassed for requests by an authenticated user.'' 320 """) 318 321 319 322 def validate_registration(self, req): -
accountmanagerplugin/trunk/acct_mgr/tests/admin.py
r12663 r12721 39 39 40 40 class DummyCheck(GenericRegistrationInspector): 41 @property 42 def doc(self): 43 return "A dummy check for unit-testing the interface." 41 _description = \ 42 """A dummy check for unit-testing the interface.""" 44 43 45 44 def validate_registration(self, req): -
accountmanagerplugin/trunk/acct_mgr/util.py
r12615 r12721 14 14 import sys 15 15 16 from genshi.builder import tag17 18 16 from trac.config import Option 19 17 from trac.util.datefmt import format_datetime, pretty_timedelta 20 18 from trac.util.datefmt import to_datetime, utc 21 from trac.util.text import to_unicode22 from trac.web.chrome import Chrome23 19 24 20 from acct_mgr.api import _, ngettext 21 22 23 class EnvRelativePathOption(Option): 24 25 def __get__(self, instance, owner): 26 if instance is None: 27 return self 28 path = super(EnvRelativePathOption, self).__get__(instance, owner) 29 if not path: 30 return path 31 return os.path.normpath(os.path.join(instance.env.path, path)) 25 32 26 33 … … 60 67 61 68 62 class EnvRelativePathOption(Option):63 64 def __get__(self, instance, owner):65 if instance is None:66 return self67 path = super(EnvRelativePathOption, self).__get__(instance, owner)68 if not path:69 return path70 return os.path.normpath(os.path.join(instance.env.path, path))71 72 73 try:74 from trac.util import as_int75 # Provide the function for compatibility (available since Trac 0.12).76 except ImportError:77 def as_int(s, default, min=None, max=None):78 """Convert s to an int and limit it to the given range, or79 return default if unsuccessful (copied verbatim from Trac0.12dev).80 """81 try:82 value = int(s)83 except (TypeError, ValueError):84 return default85 if min is not None and value < min:86 value = min87 if max is not None and value > max:88 value = max89 return value90 91 69 # taken from a comment of Horst Hansen 92 70 # at http://code.activestate.com/recipes/65441 … … 103 81 return func(self, *args, **kwds) 104 82 return wrap 105 106 try:107 from trac.util.text import exception_to_unicode108 # Provide the function for compatibility (available since Trac 0.11.3).109 except:110 def exception_to_unicode(e, traceback=False):111 """Convert an `Exception` to an `unicode` object.112 113 In addition to `to_unicode`, this representation of the exception114 also contains the class name and optionally the traceback.115 This replicates the Trac core function for backwards-compatibility.116 """117 message = '%s: %s' % (e.__class__.__name__, to_unicode(e))118 if traceback:119 from trac.util import get_last_traceback120 traceback_only = get_last_traceback().split('\n')[:-2]121 message = '\n%s\n%s' % (to_unicode('\n'.join(traceback_only)),122 message)123 return message124 125 # Compatibility code for `pretty_dateinfo` from template data dict126 # (available since Trac 1.0)127 def get_pretty_dateinfo(env, req):128 """Return the function defined in trac.web.chrome.Chrome.populate_data .129 130 For Trac 0.11 and 0.12 it still provides a slightly simplified version.131 """132 # Function is not a class attribute, must be extracted from data dict.133 fn = Chrome(env).populate_data(req, {}).get('pretty_dateinfo')134 if not fn:135 def _pretty_dateinfo(date, format=None, dateonly=False):136 absolute = format_datetime(date, tzinfo=req.tz)137 relative = pretty_timedelta(date)138 if format == 'absolute':139 label = absolute140 # TRANSLATOR: Sync with same msgid in Trac 0.13, please.141 title = _("%(relativetime)s ago", relativetime=relative)142 else:143 if dateonly:144 label = relative145 else:146 label = _("%(relativetime)s ago", relativetime=relative)147 title = absolute148 return tag.span(label, title=title)149 return fn and fn or _pretty_dateinfo150 151 # Compatibility code for `ComponentManager.is_enabled`152 # (available since Trac 0.12)153 def is_enabled(env, cls):154 """Return whether the given component class is enabled.155 156 For Trac 0.11 the missing algorithm is included as fallback.157 """158 try:159 return env.is_enabled(cls)160 except AttributeError:161 if cls not in env.enabled:162 env.enabled[cls] = env.is_component_enabled(cls)163 return env.enabled[cls]164 83 165 84 def pretty_precise_timedelta(time1, time2=None, resolution=None, diff=0): -
accountmanagerplugin/trunk/acct_mgr/web_ui.py
r12672 r12721 33 33 from acct_mgr.api import AccountManager, CommonTemplateProvider 34 34 from acct_mgr.api import _, dgettext, ngettext, tag_ 35 from acct_mgr.compat import is_enabled 35 36 from acct_mgr.db import SessionStore 36 37 from acct_mgr.guard import AccountGuard 37 38 from acct_mgr.model import set_user_attribute, user_known 38 39 from acct_mgr.register import EmailVerificationModule, RegistrationModule 39 from acct_mgr.util import if_enabled , is_enabled40 from acct_mgr.util import if_enabled 40 41 41 42 -
accountmanagerplugin/trunk/setup.cfg
r9403 r12721 7 7 msgid_bugs_address = hoff.st@shaas.net 8 8 output_file = acct_mgr/locale/messages.pot 9 keywords = _ ngettext:1,2 N_ tag_ 9 keywords = _ ngettext:1,2 N_ tag_ cleandoc_ 10 10 width = 72 11 11 … … 23 23 output_dir = acct_mgr/locale 24 24 domain = acct_mgr 25 26 [compile_catalog_js] 27 directory = acct_mgr/locale 28 domain = acct_mgr 29 30 [generate_messages_js] 31 domain = acct_mgr 32 input_dir = acct_mgr/locale 33 output_dir = acct_mgr/htdocs 34 35 [compile_catalog_tracini] 36 directory = acct_mgr/locale 37 domain = acct_mgr -
accountmanagerplugin/trunk/setup.py
r12658 r12721 10 10 extra = {} 11 11 12 has_trac_extract_python = False 12 13 try: 13 from trac.util.dist import get_l10n_cmdclass 14 cmdclass = get_l10n_cmdclass() 14 from trac.util.dist import get_l10n_cmdclass 15 try: 16 from trac.dist import get_l10n_trac_cmdclass 17 cmdclass = get_l10n_trac_cmdclass() 18 has_trac_extract_python = True 19 except ImportError: 20 # Trac < 1.0, using other compatibility code here. 21 cmdclass = get_l10n_cmdclass() 15 22 if cmdclass: 16 23 extra['cmdclass'] = cmdclass 17 24 extractors = [ 18 ('**.py', 'python', None),19 25 ('**/templates/**.html', 'genshi', None), 20 26 ] 27 if has_trac_extract_python: 28 extractors.append( 29 ('**.py', 'trac.dist:extract_python', None)) 30 else: 31 extractors.append( 32 ('**.py', 'acct_mgr.compat:extract_python', None)) 21 33 extra['message_extractors'] = { 22 34 'acct_mgr': extractors, 23 35 } 24 # i18n is implemented to be optional here36 # Trac < 0.12, i18n is implemented to be optional here. 25 37 except ImportError: 26 38 pass … … 42 54 package_data={ 43 55 'acct_mgr': [ 44 'htdocs/*', 'locale/*/LC_MESSAGES/*.mo', 'locale/.placeholder', 56 'htdocs/*.css', 'htdocs/js/*', 'htdocs/*.png', 57 'locale/*/LC_MESSAGES/*.mo', 'locale/.placeholder', 45 58 'templates/*.html', 'templates/*.txt' 46 59 ]
Note: See TracChangeset
for help on using the changeset viewer.