~lazr-developers/lazr.restful/trunk

« back to all changes in this revision

Viewing changes to src/lazr/restful/docs/webservice.txt

  • Committer: Leonard Richardson
  • Date: 2011-02-02 13:04:00 UTC
  • mfrom: (134.5.30 rockstar-web-link)
  • Revision ID: leonard.richardson@canonical.com-20110202130400-6gq4uspdw2u3wk1d
[r=thumper] Publish a web_link for entries that correspond to pages on some website.

Show diffs side-by-side

added added

removed removed

Lines of Context:
555
555
    >>> from lazr.restful.interfaces import IEntry, LAZR_WEBSERVICE_NAME
556
556
    >>> class IAuthorEntry(IAuthor, IEntry):
557
557
    ...     """The part of an author we expose through the web service."""
558
 
    ...     taggedValue(LAZR_WEBSERVICE_NAME, dict(singular="author",
559
 
    ...                                            plural="authors"))
 
558
    ...     taggedValue(
 
559
    ...         LAZR_WEBSERVICE_NAME,
 
560
    ...         dict(
 
561
    ...             singular="author", plural="authors",
 
562
    ...             publish_web_link=True))
560
563
 
561
564
    >>> class ICommentEntry(IComment, IEntry):
562
565
    ...     """The part of a comment we expose through the web service."""
563
 
    ...     taggedValue(LAZR_WEBSERVICE_NAME,
564
 
    ...         dict(singular="comment", plural="comments"))
 
566
    ...     taggedValue(
 
567
    ...         LAZR_WEBSERVICE_NAME,
 
568
    ...         dict(
 
569
    ...             singular="comment", plural="comments",
 
570
    ...             publish_web_link=True))
565
571
 
566
572
Most of the time, it doesn't work to expose to the web service the same data
567
573
model we expose internally. Usually there are fields we don't want to expose,
581
587
    >>> class IDishEntry(IEntry):
582
588
    ...     "The part of a dish that we expose through the web service."
583
589
    ...     recipes = CollectionField(value_type=Reference(schema=IRecipe))
584
 
    ...     taggedValue(LAZR_WEBSERVICE_NAME,
585
 
    ...         dict(singular="dish", plural="dishes"))
 
590
    ...     taggedValue(
 
591
    ...         LAZR_WEBSERVICE_NAME,
 
592
    ...         dict(
 
593
    ...             singular="dish", plural="dishes",
 
594
    ...             publish_web_link=True))
586
595
 
587
596
In the following code block we define an interface that exposes the underlying
588
597
``Recipe``'s name but not its ID. References to associated objects (like the
595
604
    ...     dish = Reference(schema=IDish)
596
605
    ...     instructions = Text(title=u"Name", required=True)
597
606
    ...     comments = CollectionField(value_type=Reference(schema=IComment))
598
 
    ...     taggedValue(LAZR_WEBSERVICE_NAME,
599
 
    ...         dict(singular="recipe", plural="recipes"))
 
607
    ...     taggedValue(
 
608
    ...         LAZR_WEBSERVICE_NAME,
 
609
    ...         dict(
 
610
    ...             singular="recipe", plural="recipes",
 
611
    ...             publish_web_link=True))
600
612
 
601
613
    >>> from lazr.restful.fields import ReferenceChoice
602
614
    >>> class ICookbookEntry(IEntry):
607
619
    ...     recipes = CollectionField(value_type=Reference(schema=IRecipe))
608
620
    ...     comments = CollectionField(value_type=Reference(schema=IComment))
609
621
    ...     cover = Bytes(0, 5000, title=u"An image of the cookbook's cover.")
610
 
    ...     taggedValue(LAZR_WEBSERVICE_NAME,
611
 
    ...         dict(singular="cookbook", plural="cookbooks"))
 
622
    ...     taggedValue(
 
623
    ...         LAZR_WEBSERVICE_NAME,
 
624
    ...         dict(
 
625
    ...             singular="cookbook", plural="cookbooks",
 
626
    ...             publish_web_link=True))
612
627
 
613
628
The ``author`` field is a choice between ``Author`` objects. To make sure
614
629
that the ``Author`` objects are properly marshalled to JSON, we need to