durusmail: quixote-users: Is there an example of how to do this.
Is there an example of how to do this.
2005-08-02
2005-08-02
2005-08-02
2005-08-06
Is there an example of how to do this.
mso@oz.net
2005-08-02
David Driver wrote:
> Suppose that I have a URL that looks like http://mysite/ar/customer/
> /customer/ is to resolve to a screen for looking up customers.
> /customer/10 shows a summary of the customer and links to other
> reports for the customer and an edit link so that
> /customer/10/edit shows a ui for editing the customer
>
> If I am using dynamic exporting directory and I don't want the user to
> see the other links (for reports and editing) untill they have looked
> up a customer or entered the url directly. Also how do the subsiquent
> directories get called?
>
> I would eventually see doing something like
> /customer/10/aging/detailed
> How does aging know that wer are talking about customer 10 if detailed
> is also q lookup in aging?

import quixote
from quixote.directory import Directory
class AR_Customer(Directory):
    _q_exports = ['', 'add']
    def _q_index(self): ...   # List of customers.
    def add(self): ...        # Add a customer

    def _q_lookup(self, cust_id):
        """URL was not otherwise matched, assume it's a customer ID."""
        if not cust_id.isdigit():
            return None
        return Customer(cust_id)

class Customer(Directory):
    _q_exports = ['', 'edit', 'report1', 'aging']
    def __init__(self, cust_id):
        self.cust_id = cust_id

    def edit(self): ...            # Modify data
    def report1(self): ...         # Generate a report

    aging = Aging()
    # Or maybe "def aging(self):  return Aging(self.cust_id)"
    # but I haven't tried it that way.

class Aging(Directory):
    _q_exports = ['', 'detailed']
    def __init__(self, cust_id):
        # Could also pass other data too.
        self.cust_id = cust_id

    def _q_index(self): ...          # Short aging report
    def detailed(self): ...          # Detailed aging report.

There's no way to get to the subdirectories without entering a customer
ID.    You can verify the customer exists in _q_lookup or __init__, or
wait till the leaf method and raise QueryError if the customer is not
found.

Typically you'd pass one additional piece of information for each
subdirectory level, but in the case there didn't seem to be any additional
information besides the cust_id.  In a case where an Incident has multiple
Entries and the URL is like /incidents/INCIDENT#/ENTRY#/ or
/incidents/123/456:

class Main(Directory):
    def _q_lookup(self, incident_id):
        if not incident_id.isdigit():
            return None
        return Incident(incident_id)

class Incident(Directory):
    def __main__(self, incident_id):
        self.incident_id = incident_id
    def _q_lookup(self, entry_id):
        if not entry_id.isdigit():
            return None
        return Entry(entry_id, incident_id)

class Entry(Directory):
    def __init__(self, entry_id, incident_id):
        self.entry_id = entry_id
        self.incident_id = incident_id

--
-- Mike Orr 

reply