diff options
Diffstat (limited to 'askbot/utils')
-rw-r--r-- | askbot/utils/console.py | 40 | ||||
-rw-r--r-- | askbot/utils/forms.py | 8 | ||||
-rw-r--r-- | askbot/utils/html.py | 4 | ||||
-rw-r--r-- | askbot/utils/url_utils.py | 14 |
4 files changed, 59 insertions, 7 deletions
diff --git a/askbot/utils/console.py b/askbot/utils/console.py index 496bbd65..fe6ad29e 100644 --- a/askbot/utils/console.py +++ b/askbot/utils/console.py @@ -74,3 +74,43 @@ def print_progress(elapsed, total, nowipe = False): in-place""" output = '%6.2f%%' % (100 * float(elapsed)/float(total)) print_action(output, nowipe) + +class ProgressBar(object): + """A wrapper for an iterator, that prints + a progress bar along the way of iteration + """ + def __init__(self, iterable, length, message = ''): + self.iterable = iterable + self.length = length + self.counter = float(0) + self.barlen = 60 + self.progress = '' + if message and length > 0: + print message + + + def __iter__(self): + return self + + def next(self): + + try: + result = self.iterable.next() + except StopIteration: + if self.length > 0: + sys.stdout.write('\n') + raise + + sys.stdout.write('\b'*len(self.progress)) + + if self.length < self.barlen: + sys.stdout.write('-'*(self.barlen/self.length)) + elif int(self.counter) % (self.length / self.barlen) == 0: + sys.stdout.write('-') + + self.progress = ' %.2f%%' % (100 * (self.counter/self.length)) + sys.stdout.write(self.progress) + sys.stdout.flush() + + self.counter += 1 + return result diff --git a/askbot/utils/forms.py b/askbot/utils/forms.py index 536d06b5..b8ed253b 100644 --- a/askbot/utils/forms.py +++ b/askbot/utils/forms.py @@ -57,7 +57,7 @@ class UserNameField(StrippedNonEmptyCharField): db_field='username', must_exist=False, skip_clean=False, - label=_('choose a username'), + label=_('Choose a screen name'), **kw ): self.must_exist = must_exist @@ -135,7 +135,7 @@ class UserEmailField(forms.EmailField): def __init__(self,skip_clean=False,**kw): self.skip_clean = skip_clean super(UserEmailField,self).__init__(widget=forms.TextInput(attrs=dict(login_form_widget_attrs, - maxlength=200)), label=mark_safe(_('your email address')), + maxlength=200)), label=mark_safe(_('Your email <i>(never shared)</i>')), error_messages={'required':_('email address is required'), 'invalid':_('please enter a valid email address'), 'taken':_('this email is already used by someone else, please choose another'), @@ -166,11 +166,11 @@ class UserEmailField(forms.EmailField): class SetPasswordForm(forms.Form): password1 = forms.CharField(widget=forms.PasswordInput(attrs=login_form_widget_attrs), - label=_('choose password'), + label=_('Password'), error_messages={'required':_('password is required')}, ) password2 = forms.CharField(widget=forms.PasswordInput(attrs=login_form_widget_attrs), - label=mark_safe(_('retype password')), + label=mark_safe(_('Password <i>(please retype)</i>')), error_messages={'required':_('please, retype your password'), 'nomatch':_('sorry, entered passwords did not match, please try again')}, ) diff --git a/askbot/utils/html.py b/askbot/utils/html.py index f6c168fb..f91fa980 100644 --- a/askbot/utils/html.py +++ b/askbot/utils/html.py @@ -28,10 +28,10 @@ class HTMLSanitizerMixin(sanitizer.HTMLSanitizerMixin): class HTMLSanitizer(tokenizer.HTMLTokenizer, HTMLSanitizerMixin): def __init__(self, stream, encoding=None, parseMeta=True, useChardet=True, - lowercaseElementName=True, lowercaseAttrName=True): + lowercaseElementName=True, lowercaseAttrName=True, **kwargs): tokenizer.HTMLTokenizer.__init__(self, stream, encoding, parseMeta, useChardet, lowercaseElementName, - lowercaseAttrName) + lowercaseAttrName, **kwargs) def __iter__(self): for token in tokenizer.HTMLTokenizer.__iter__(self): diff --git a/askbot/utils/url_utils.py b/askbot/utils/url_utils.py index 0ebce394..6027d096 100644 --- a/askbot/utils/url_utils.py +++ b/askbot/utils/url_utils.py @@ -1,6 +1,18 @@ +import urlparse from django.core.urlresolvers import reverse from django.conf import settings +def strip_path(url): + """srips path, params and hash fragments of the url""" + purl = urlparse.urlparse(url) + return urlparse.urlunparse( + urlparse.ParseResult( + purl.scheme, + purl.netloc, + '', '', '', '' + ) + ) + def get_login_url(): """returns internal login url if django_authopenid is used, or @@ -27,6 +39,6 @@ def get_logout_redirect_url(): if 'askbot.deps.django_authopenid' in settings.INSTALLED_APPS: return reverse('logout') elif hasattr(settings, 'LOGOUT_REDIRECT_URL'): - return settigs.LOGOUT_REDIRECT_URL + return settings.LOGOUT_REDIRECT_URL else: return reverse('index') |