Ejemplo n.º 1
0
    def probe(self, location=None):
        """Test the repository. On success, stores extra information
           about that repository including the root URL and the latest
           revision.
       
           This must be called any time the repository location is
           modified.  Since it resets our latest revision counter, all
           changes prior to this call will be ignored.

           On success, updates the repository model but does not save it.
           On failure, raises a form validation error.
           This function may block for an arbitrary amount of time!
           """
        location = location or self.model.location

        if not self.client.is_url(location):
            raise forms.ValidationError("Must be a valid URL")

        # XXX: svn+ssh might be useful too, but by default ssh will try to
        #      prompt interactively!

        scheme = location.split(':/', 1)[0]
        valid_schemes = ('http', 'https', 'svn')
        if not scheme in valid_schemes:
            raise forms.ValidationError(
                "Only the %s, and '%s' URL schemes are allowed" %
                (', '.join(["'%s'" % s
                            for s in valid_schemes[:-1]]), valid_schemes[-1]))

        try:
            info = self._info(location)
        except pysvn.ClientError, e:
            raise forms.ValidationError(str(e))
Ejemplo n.º 2
0
 def clean(self, value):
     try:
         return datetime.timedelta(seconds=float(value))
     except (ValueError, TypeError):
         raise forms.ValidationError(
             'This value must be a real number.')
     except OverflowError:
         raise forms.ValidationError('The maximum allowed value is %s' %
                                     datetime.timedelta.max)
Ejemplo n.º 3
0
    def clean_text(self):
	text = self.clean_data.get('text')
	file = self.data.get('file')

	if not text and not file:
	    raise forms.ValidationError('One of "text" or "file" must be filled out')

	if text and not is_valid_cert(text):
	    raise forms.ValidationError('A valid certificate is required')

	return text
Ejemplo n.º 4
0
    def clean_file(self):
	text = self.data.get('text')
	file = self.data.get('file')

	if text and file:
	    raise forms.ValidationError('Only one of "text" or "file" must be filled out')

	if file and not is_valid_cert(file['content']):
	    raise forms.ValidationError('A valid certificate is required')

	return file
Ejemplo n.º 5
0
 def clean_username(self):
     username = self.clean_data['username']
     if not re.search(r'^\w+$', username):
         raise forms.ValidationError(
             'Username can only containalphanumeric characters and the underscore.'
         )
     try:
         User.objects.get(username=username)
     except ObjectDoesNotExist:
         return username
     raise forms.ValidationError('Username is already taken.')
Ejemplo n.º 6
0
 def clean_discount(self):
     """ Check if discount exists and if it applies to these products """
     data = self.cleaned_data['discount']
     if data:
         discount = Discount.objects.filter(code=data).filter(active=True)
         if discount.count() == 0:
             raise forms.ValidationError(_('Invalid discount.'))
         valid, msg = discount[0].isValid(self.tempCart)
         if not valid:
             raise forms.ValidationError(msg)
     return data
Ejemplo n.º 7
0
 def clean_username(self):
     if not alnum_re.search(self.cleaned_data["username"]):
         raise forms.ValidationError(
             u"Usernames can only contain letters, numbers and underscores."
         )
     try:
         user = User.objects.get(
             username__exact=self.cleaned_data["username"])
     except User.DoesNotExist:
         return self.cleaned_data["username"]
     raise forms.ValidationError(
         u"This username is already taken. Please choose another.")
Ejemplo n.º 8
0
 def to_python(self, value):
     if value == NOTSET:
         value = 0
     if isinstance(value, datetime.timedelta):
         return value
     try:
         return datetime.timedelta(seconds=float(value))
     except (ValueError, TypeError):
         raise forms.ValidationError('This value must be a real number.')
     except OverflowError:
         raise forms.ValidationError('The maximum allowed value is %s' %
                                     datetime.timedelta.max)
Ejemplo n.º 9
0
    def clean_card_expiration(self):
        if not self.requires_payment:
            return None
        from datetime import date
        try:
            if self.cleaned_data['card_expiration'] < date.today():
                raise forms.ValidationError(
                    "Your card expiration can't be before todays date.")
        except TypeError:
            raise forms.ValidationError(
                "Your card expiration was not a valid date.")

        return self.cleaned_data['card_expiration']
Ejemplo n.º 10
0
 def clean_discount(self):
     """ Check if discount exists and is valid. """
     data = self.cleaned_data['discount']
     if data:
         try:
             discount = Discount.objects.get(code=data, active=True)
         except Discount.DoesNotExist:
             raise forms.ValidationError(_('Invalid discount.'))
         valid, msg = discount.isValid(self.tempCart)
         if not valid:
             raise forms.ValidationError(msg)
         # TODO: validate that it can work with these products
     return data
Ejemplo n.º 11
0
    def clean(self, value):
        email_re = re.compile(r'[\w\d\.\-\+]+@[\w\d\.\-\+]+\.[\w\d\.\-\+]+')
        if not email_re.match(value):
            raise forms.ValidationError('You must enter a valid email address')
        query = db.Query(User)
        count = query.filter('email = ', value).count()

        if count > 0:
            raise forms.ValidationError(
                '%s is already registered.  Please try a different email address.'
                % value)

        return value
Ejemplo n.º 12
0
    def clean(self, value):
        if not Phone.is_valid_number(value):
            raise forms.ValidationError(
                'Please enter a valid 10-digit US phone number')

        user = users.get_current_user()

        clean_number = Phone.normalize_number(value)
        if Phone.all().filter('verified =', True).filter(
                'number =', clean_number).filter('user !=', user).count() > 0:
            raise forms.ValidationError(
                'Phone number taken, please enter a different one.')

        return clean_number
Ejemplo n.º 13
0
 def clean_new_password_confirm(self):
     if self._errors:
         return None
     if self.cleaned_data['new_password_confirm'] != self.cleaned_data[
             'new_password']:
         raise forms.ValidationError("Passwords must match")
     return self.cleaned_data['new_password_confirm']
Ejemplo n.º 14
0
    def clean_subdomain(self):
        if not self.cleaned_data['subdomain'].isalnum():
            raise forms.ValidationError(
                "Your subdomain can only include letters and numbers.")

        try:
            Account.objects.get(
                subdomain=self.cleaned_data['subdomain'],
                domain=self.data['domain'],
            )
            raise forms.ValidationError(
                "The domain %s.%s has already been taken" %
                (self.cleaned_data['subdomain'], self.cleaned_data['domain']))
        except Account.DoesNotExist:
            pass
        return self.cleaned_data['subdomain']
Ejemplo n.º 15
0
 def clean_password2(self):
     if 'password1' in self.clean_data:
         password1 = self.clean_data['password1']
         password2 = self.clean_data['password2']
         if password1 == password2:
             return password2
     raise forms.ValidationError('Passwords do not match.')
Ejemplo n.º 16
0
 def clean_number(self):
     value = self.cleaned_data['number']
     try:
         Account.objects.get(number=value)
         raise forms.ValidationError("This account number alredy exist.") 
     except Account.DoesNotExist:
         return value
Ejemplo n.º 17
0
    def clean_email(self):
        """Prevent account hijacking by disallowing duplicate emails."""
        email = self.cleaned_data.get('email', None)
        if email and User.objects.filter(email=email).count() > 0:
            raise forms.ValidationError(
                ugettext("That email address is already in use."))

        return email
Ejemplo n.º 18
0
 def clean_password_cur(self):
     """
     Validates that username is not in use
     """
     password_cur = self.cleaned_data.get('password_cur', None)
     if password_cur:
         if not self.request.user.check_password(password_cur):
             raise forms.ValidationError(u'password is incorrect')
Ejemplo n.º 19
0
 def clean_credit_number(self):
     """ Check if credit card is valid. """
     credit_number = self.cleaned_data['credit_number']
     card = CreditCard(credit_number, self.cleaned_data['credit_type'])
     results, msg = card.verifyCardTypeandNumber()
     if not results:
         raise forms.ValidationError(msg)
     return credit_number
Ejemplo n.º 20
0
 def clean_email(self):
     try:
         EmailAddress.objects.get(user=self.user,
                                  email=self.cleaned_data["email"])
     except EmailAddress.DoesNotExist:
         return self.cleaned_data["email"]
     raise forms.ValidationError(
         u"This email address already associated with this account.")
Ejemplo n.º 21
0
    def clean_Longitude(self):
        x = self.data['Longitude']

        if not x: return x

        try:
            return str(parse_longitude(x))
        except ValueError:
            raise forms.ValidationError('Invalid longitude')
Ejemplo n.º 22
0
 def clean_year_expires(self):
     """ Check if credit card has expired. """
     month = self.cleaned_data['month_expires']
     year = int(self.cleaned_data['year_expires'])
     max_day = calendar.monthrange(year, month)[1]
     if datetime.date.today() > datetime.date(
             year=year, month=month, day=max_day):
         raise forms.ValidationError(_('Your card has expired.'))
     return year
Ejemplo n.º 23
0
 def clean_balance(self):
     value = self.cleaned_data['balance']
     try:
         money_val = Money()
         money_val.from_string(value)
         if money_val.currency.code == 'XXX' and get_def_currency():
             money_val.currency = CURRENCY[get_def_currency()]
     except:
         raise forms.ValidationError("Invalid money value")
     return money_val
Ejemplo n.º 24
0
    def clean(self, value):

        result = forms.CharField.clean(self, value)

        try:
            league = League.get(result)
        except datastore_errors.BadKeyError:
            raise forms.ValidationError('Unknown League')

        return result
Ejemplo n.º 25
0
 def clean(self, value):
     value = super(TagField, self).clean(value)
     if value == u'':
         return value
     for tag_name in parse_tag_input(value):
         if len(tag_name) > settings.MAX_TAG_LENGTH:
             raise forms.ValidationError(
                 _('Each tag may be no more than %s characters long.') %
                 settings.MAX_TAG_LENGTH)
     return value
Ejemplo n.º 26
0
    def clean_password(self):
        """Enforce that password and password2 are the same."""
        p1 = self.cleaned_data.get('password')
        p2 = self.cleaned_data.get('password2')
        if not (p1 and p2 and p1 == p2):
            raise forms.ValidationError(
                ugettext("The two passwords do not match."))

        # note, here is where we'd put some kind of custom validator to enforce "hard" passwords.
        return p1
Ejemplo n.º 27
0
 def clean(self, value):
     """
     Validates that the input is a valid list of tag names,
     separated by a single comma, a single space or a comma
     followed by a space.
     """
     value = super(TagField, self).clean(value)
     if value == u'':
         return value
     if not tag_list_re.search(value):
         raise forms.ValidationError(
             u'Tag names must contain only unicode alphanumeric characters, numbers, underscores or hyphens, with a comma, space or comma followed by space used to separate each tag name.'
         )
     tag_names = get_tag_name_list(value)
     for tag_name in tag_names:
         if len(tag_name) > 50:
             raise forms.ValidationError(
                 u'Tag names must be no longer than 50 characters.')
     return value
Ejemplo n.º 28
0
    def clean_password2(self):
        """
        Validates that the two password inputs match.
        """

        if self.cleaned_data.get('password', None) and self.cleaned_data.get('password2', None) and \
           self.cleaned_data['password'] == self.cleaned_data['password2']:
            return self.cleaned_data['password2']
        else:
            raise forms.ValidationError(u'The passwords did not match')
Ejemplo n.º 29
0
 def clean(self):
     if self._errors:
         return
     try:
         self.person = Person.objects.get(
             username=self.data['username'],
             account=self.account,
         )
     except Person.DoesNotExist:
         raise forms.ValidationError(
             "Your user name wasn't on file. Did you spell it correctly?", )
Ejemplo n.º 30
0
 def clean_username(self):
     """
     Validates that username is not in use
     """
     username = self.cleaned_data.get('username', None)
     if username:
         try:
             User.objects.get(username=username)
             raise forms.ValidationError(
                 u'username already exists, please choose another')
         except User.DoesNotExist:
             return username