[Checkins]
SVN: Sandbox/darrylcousins/tfws.website/src/tfws/website/
Playing around
Darryl Cousins
darryl at darrylcousins.net.nz
Tue Aug 14 07:48:07 EDT 2007
Log message for revision 78808:
Playing around
Changed:
U Sandbox/darrylcousins/tfws.website/src/tfws/website/BROWSER.txt
U Sandbox/darrylcousins/tfws.website/src/tfws/website/browser/browser.py
U Sandbox/darrylcousins/tfws.website/src/tfws/website/members.py
U Sandbox/darrylcousins/tfws.website/src/tfws/website/site.txt
U Sandbox/darrylcousins/tfws.website/src/tfws/website/templates/index.pt
-=-
Modified: Sandbox/darrylcousins/tfws.website/src/tfws/website/BROWSER.txt
===================================================================
--- Sandbox/darrylcousins/tfws.website/src/tfws/website/BROWSER.txt 2007-08-14 02:39:07 UTC (rev 78807)
+++ Sandbox/darrylcousins/tfws.website/src/tfws/website/BROWSER.txt 2007-08-14 11:48:06 UTC (rev 78808)
@@ -9,7 +9,7 @@
>>> browser.handleErrors = False
>>> browser.open("http://localhost/")
-Unauthorized users can access the site.
+Unauthorized users cannot access the server root.
>>> user = ExtendedTestBrowser()
>>> user.open("http://localhost/")
@@ -17,6 +17,9 @@
...
HTTPError: HTTP Error 401: Unauthorized
+Adding a site
+-------------
+
Using our authenticated browser instance we can add a website.
>>> browser.open("http://localhost/++skin++tfwswebsite/add")
@@ -37,8 +40,38 @@
treefern
Tree Fern
-We can edit the new site ... to be continued
+Deleting a site
+---------------
+Sites can be deleted, first we add another
+
+ >>> browser.open("http://localhost/++skin++tfwswebsite/add")
+ >>> browser.getControl('name').value = u'treefern2'
+ >>> browser.getControl('Title').value = u'Tree Fern'
+ >>> browser.getControl('Login').value = u'darrylcousins'
+ >>> browser.getControl('Password').value = u'tfws'
+ >>> browser.getControl('First Name').value = u'Darryl'
+ >>> browser.getControl('Last Name').value = u'Cousins'
+ >>> browser.getControl('Email').value = u'darry.cousins at tfws.org.nz'
+ >>> browser.getControl('Add').click()
+ >>> 'treefern2' in browser.contents
+ True
+
+Yep, it's there.
+
+ >>> browser.getControl(name='selected:list').value = ['treefern2']
+ >>> browser.getControl(name='confirm_delete').value = u'yes'
+ >>> browser.getControl('Delete').click()
+ >>> 'treefern2' in browser.contents
+ False
+
+Yes, it's gone.
+
+Accessing the site
+------------------
+
+We can access the new site.
+
>>> browser.getLink('treefern').click()
>>> testing.printElement(browser, "//h1")
<h1>Tree Fern</h1>
@@ -49,6 +82,9 @@
>>> print user.url
http://localhost/treefern/index
+Login
+-----
+
We have a login form.
>>> user.handleErrors = False
@@ -92,6 +128,18 @@
>>> user.getControl('Change Password').value = u'secret'
>>> user.getControl('Verify Password').value = u'osecret'
>>> user.getControl('Apply').click()
- >>> print user.contents
+Invariant validation on password fields.
+ >>> 'Passwords do not match' in user.contents
+ True
+
+ >>> user.getControl('First Name').value = u'Darryl Jon'
+ >>> user.getControl('Change Password').value = u'secret'
+ >>> user.getControl('Verify Password').value = u'secret'
+ >>> user.getControl('Apply').click()
+ >>> 'Data successfully updated' in user.contents
+ True
+
+
+
Modified: Sandbox/darrylcousins/tfws.website/src/tfws/website/browser/browser.py
===================================================================
--- Sandbox/darrylcousins/tfws.website/src/tfws/website/browser/browser.py 2007-08-14 02:39:07 UTC (rev 78807)
+++ Sandbox/darrylcousins/tfws.website/src/tfws/website/browser/browser.py 2007-08-14 11:48:06 UTC (rev 78808)
@@ -67,6 +67,7 @@
return
if 'selected' in self.request:
for id in self.request['selected']:
+ self.items.remove(self.context[id])
del self.context[id]
self.status = _('Sites were successfully deleted.')
else:
Modified: Sandbox/darrylcousins/tfws.website/src/tfws/website/members.py
===================================================================
--- Sandbox/darrylcousins/tfws.website/src/tfws/website/members.py 2007-08-14 02:39:07 UTC (rev 78807)
+++ Sandbox/darrylcousins/tfws.website/src/tfws/website/members.py 2007-08-14 11:48:06 UTC (rev 78808)
@@ -174,7 +174,26 @@
grok.context(MemberIndex)
grok.template('templates/member.pt')
+from z3c.form.interfaces import IDataManager
+def applyChanges(form, content, data):
+ changes = {}
+ for name, field in form.fields.items():
+ # If the field is not in the data, then go on to the next one
+ if name not in data:
+ continue
+ # Get the datamanager and get the original value
+ dm = zope.component.getMultiAdapter(
+ (content, field.field), IDataManager)
+ oldValue = dm.get()
+ # Only update the data, if it is different
+ if dm.get() != data[name]:
+ dm.set(data[name])
+ interface = dm.field.interface
+ changes.setdefault(interface, []).append(name)
+ return changes
+
+
class MemberEdit(mars.form.FormView, layout.FormLayoutSupport, form.EditForm):
grok.name('edit')
grok.context(Member)
@@ -188,15 +207,20 @@
def applyChanges(self, data):
content = self.getContent().context
- change_password = data['change_password']
+ change_password = data.get('change_password', None)
del data['change_password']
del data['verify_password']
- changed = form.applyChanges(self, content, data)
- if content.password != change_password:
+
+ changes = applyChanges(self, content, data)
+ if content.password != change_password and change_password != None:
content.password = change_password
- changed = True
- if changed:
+ changes.setdefault(interfaces.IWebSiteMember, []).append('password')
+ if changes:
+ descriptions = []
+ for interface, names in changes.items():
+ descriptions.append(zope.lifecycleevent.Attributes(interface,
+ *names))
zope.event.notify(
- zope.lifecycleevent.ObjectModifiedEvent(content))
- return changed
+ zope.lifecycleevent.ObjectModifiedEvent(content, descriptions))
+ return changes
Modified: Sandbox/darrylcousins/tfws.website/src/tfws/website/site.txt
===================================================================
--- Sandbox/darrylcousins/tfws.website/src/tfws/website/site.txt 2007-08-14 02:39:07 UTC (rev 78807)
+++ Sandbox/darrylcousins/tfws.website/src/tfws/website/site.txt 2007-08-14 11:48:06 UTC (rev 78808)
@@ -145,7 +145,14 @@
We can traverse Members to a website member.
>>> tmember = members.traverse(member.__name__)
- >>> print (tmember.login, tmember.title, tmember.email, tmember.password)
- (u'darryl', u'Darryl Cousins', u'darryl at tfws.org.nz', 'tfws')
+ >>> print (tmember.login, tmember.title, tmember.email)
+ (u'darryl', u'Darryl Cousins', u'darryl at tfws.org.nz')
+We can't access the password for the member however
+ >>> tmember.password
+ Traceback (most recent call last):
+ ...
+ AttributeError: 'Member' object has no attribute 'password'
+
+
Modified: Sandbox/darrylcousins/tfws.website/src/tfws/website/templates/index.pt
===================================================================
--- Sandbox/darrylcousins/tfws.website/src/tfws/website/templates/index.pt 2007-08-14 02:39:07 UTC (rev 78807)
+++ Sandbox/darrylcousins/tfws.website/src/tfws/website/templates/index.pt 2007-08-14 11:48:06 UTC (rev 78808)
@@ -1,2 +1 @@
<h1 tal:content="context/title">Tree Fern</h1>
-
More information about the Checkins
mailing list