paulb@210 | 1 | #!/usr/bin/env python |
paulb@210 | 2 | |
paulb@210 | 3 | "A simple Zope product." |
paulb@210 | 4 | |
paulb@210 | 5 | from Simple import SimpleResource |
paulb@210 | 6 | from WebStack.Resources.LoginRedirect import LoginRedirectResource, LoginRedirectAuthenticator |
paulb@669 | 7 | from WebStack.Resources.Login import LoginResource, LoginAuthenticator |
paulb@669 | 8 | from WebStack.Resources.ResourceMap import MapResource |
paulb@210 | 9 | from WebStack.Adapters.Zope import WebStackAdapterProduct |
paulb@210 | 10 | from Globals import InitializeClass |
paulb@210 | 11 | |
paul@765 | 12 | # Change this to be the URL base for your server. |
paul@765 | 13 | # eg. http://localhost:8000 |
paulb@683 | 14 | |
paul@765 | 15 | app_url = "http://localhost" # No trailing "/"! |
paul@765 | 16 | |
paul@765 | 17 | # Must match the key used elsewhere. |
paul@765 | 18 | |
paul@765 | 19 | secret_key = "horses" |
paulb@683 | 20 | |
paulb@210 | 21 | class SimpleWithLoginProduct(WebStackAdapterProduct): |
paulb@683 | 22 | |
paulb@210 | 23 | meta_type = "Simple with login product" |
paulb@683 | 24 | |
paulb@683 | 25 | def __init__(self, id, parent_url): |
paul@765 | 26 | login_url = parent_url + "/" + id + "/login" |
paul@765 | 27 | resource = get_site_map(app_url, login_url, secret_key) |
paul@765 | 28 | WebStackAdapterProduct.__init__(self, id, resource) |
paulb@210 | 29 | |
paulb@210 | 30 | InitializeClass(SimpleWithLoginProduct) |
paulb@210 | 31 | |
paulb@210 | 32 | def addSimpleWithLoginProduct(self): |
paulb@210 | 33 | """ |
paulb@210 | 34 | The HTML form used to add the product. |
paulb@210 | 35 | """ |
paulb@210 | 36 | |
paulb@210 | 37 | return """ |
paulb@210 | 38 | <html> |
paulb@210 | 39 | <head> |
paulb@210 | 40 | <title>Add Simple with Login Product</title> |
paulb@210 | 41 | </head> |
paulb@210 | 42 | <body> |
paulb@210 | 43 | <form action="addProduct"> |
paulb@210 | 44 | id <input name="id" type="text"><br> |
paulb@210 | 45 | <input name="add" type="submit" value="Add!"> |
paulb@210 | 46 | </form> |
paulb@210 | 47 | </body> |
paulb@210 | 48 | </html> |
paulb@210 | 49 | """ |
paulb@210 | 50 | |
paulb@210 | 51 | def addProduct(self, id, REQUEST=None): |
paulb@210 | 52 | """ |
paulb@210 | 53 | The function used to add the product. |
paulb@210 | 54 | """ |
paulb@210 | 55 | |
paulb@683 | 56 | product = SimpleWithLoginProduct(id, self.DestinationURL()) |
paulb@210 | 57 | self.Destination()._setObject(id, product) |
paulb@210 | 58 | if REQUEST: |
paulb@210 | 59 | return self.manage_main(self, REQUEST) |
paulb@210 | 60 | |
paulb@210 | 61 | def initialize(context): |
paulb@210 | 62 | context.registerClass( |
paulb@210 | 63 | SimpleWithLoginProduct, |
paulb@210 | 64 | constructors = (addSimpleWithLoginProduct, addProduct) |
paulb@210 | 65 | ) |
paulb@210 | 66 | |
paulb@210 | 67 | # vim: tabstop=4 expandtab shiftwidth=4 |