| Trees | Indices | Help |
|
|---|
|
|
1 '''
2 Created on Apr 29, 2010
3
4 @author: jnaous
5 '''
6
7 from django import forms
8 from models import PasswordXMLRPCServerProxy
9
10 import logging
11 logger = logging.getLogger("PasswordXMLRPCServerProxyForm")
12
15 '''Check url'''
16 import urlparse
17 url = self.cleaned_data['url']
18 logger.debug("Checking URL %s" % url)
19 parsed = urlparse.urlparse(url, "https", False)
20 if parsed.port == None:
21 raise forms.ValidationError("Did not specify a port. Please \
22 explicitly specify the port. e.g. https://hostname:portnum/xmlrpc/xmlrpc/")
23 if parsed.port == 0:
24 raise forms.ValidationError("Invalid port number 0.")
25 u = parsed.geturl()
26 logger.debug("parsed url: %s" % u)
27 if not u.endswith("/"): u += "/"
28 return u
29
31 logger.debug("Cleaning data")
32 if self._errors:
33 return self.cleaned_data
34 d = dict(self.cleaned_data)
35 if "password2" in d: del d["password2"]
36 p = self._meta.model(**d)
37 avail, msg = p.is_available(get_info=True)
38 if not avail:
39 url = self.cleaned_data.get("url", "None")
40 logger.debug("URL not available.")
41 raise forms.ValidationError(
42 "The url %s could not be reached. Check the url, username, "
43 "and password. The error message was: %s." % (
44 url, msg))
45 logger.debug("Done cleaning data")
46 return self.cleaned_data
47
48 -class PasswordXMLRPCServerProxyForm(forms.ModelForm,
49 PasswordXMLRPCServerProxyFormHelperAddin):
50 '''
51 A form that can be used to create/edit info on a PasswordXMLRPCClient
52 If C{check_available} is True, the form will check that a saved client
53 can access the location.
54 '''
55
57 super(PasswordXMLRPCServerProxyForm, self).__init__(*args, **kwargs)
58 self.check_available = check_available
59
61 model = PasswordXMLRPCServerProxy
62
65
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Fri Feb 18 13:10:11 2011 | http://epydoc.sourceforge.net |