~ubuntu-branches/ubuntu/karmic/imdbpy/karmic

« back to all changes in this revision

Viewing changes to docs/README.currentRole

  • Committer: Bazaar Package Importer
  • Author(s): Ana Beatriz Guerrero Lopez
  • Date: 2007-11-18 15:18:06 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20071118151806-s6s42pw750q3g59y
Tags: 3.3-1
* New upstream version.
* Move Homepage into control field.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
  THE currentRole ATTRIBUTE AND THE Character CLASS
 
3
  =================================================
 
4
 
 
5
Since version 3.3, IMDbPY supports the character pages of the IMDb
 
6
database; this required some substantial changes to how actors'
 
7
and acresses' roles were handled.
 
8
So far, only the "http", "httpThin" and "mobile" data access systems
 
9
can manage the character pages.
 
10
 
 
11
The currentRole instance attribute can be found in every instance
 
12
of Person, Movie and Character classes, even if actually the Character
 
13
never uses it.
 
14
 
 
15
The currentRole of a Person object is set to a Character instance,
 
16
inside a list of person who acted in a given movie.
 
17
The currentRole of a Movie object is set to a Character instance,
 
18
inside a list of movies played be given person.
 
19
The currentRole of a Movie object is set to a Person instance,
 
20
inside a list of movies in which a given character was portrayed.
 
21
 
 
22
Schema:
 
23
  movie['cast'][0].currentRole -> a Character object.
 
24
                  |
 
25
                  +-> a Person object.
 
26
 
 
27
  person['actor'][0].currentRole -> a Character object.
 
28
                    |
 
29
                    +-> a Movie object.
 
30
 
 
31
  character['filmography'][0].currentRole -> a Person object.
 
32
                             |
 
33
                             +-> a Movie object.
 
34
 
 
35
The roleID attribute can be used to access/set the characterID
 
36
or personID instance attribute of the current currentRole.
 
37
Building Movie or Person objects, you can pass the currentRole
 
38
parameter and the roleID parameter (to set the ID).
 
39
The currentRole parameter can be an object (Character or Person),
 
40
an unicode string (in which case a Character or Person object is
 
41
automatically instanced) or a list of objects or strings (to
 
42
handle multiple characters played by the same actor/actress in
 
43
a movie, or character played by more then a single actor/actress
 
44
in the same movie).
 
45
 
 
46
Anyway, currentRole objects (Character or Person instances) can
 
47
be pretty-printed easily: calling unicode(CharacterOrPersonObject)
 
48
will return a good-old-unicode string, like expected in the previous
 
49
version of IMDbPY.
 
50
 
 
51
 
 
52
  GOODIES
 
53
  =======
 
54
 
 
55
To help getting the required information from Movie, Person and
 
56
Character objects, in the "helpers" module there's a new factory
 
57
function, makeObject2Txt, which can be used to create your
 
58
pretty-printing function.
 
59
It takes some optional parameters: movieTxt, personTxt, characterTxt;
 
60
in these strings %(value)s items are replaced with object['value'] or
 
61
with obj.value (if the first is not present).
 
62
 
 
63
E.g.:
 
64
  import imdb
 
65
  myPrint = imdb.helpers.makeObject2Txt(personTxt=u'%(name)s ... %(currentRole)s')
 
66
  i = imdb.IMDb()
 
67
  m = i.get_movie('0057012')
 
68
  ps = m['cast'][0]
 
69
  print myPrint(ps)
 
70
  # The output will be something like:
 
71
  Peter Sellers ... Group Captain Lionel Mandrake / President Merkin Muffley / Dr. Strangelove
 
72
 
 
73
 
 
74
Portions of the formatting string can be stripped conditionally: if
 
75
the specified condition is false, they will be cancelled.
 
76
 
 
77
E.g.:
 
78
  myPrint = imdb.helpers.makeObject2Txt(personTxt='<if personID><a href=/person/%(personID)s></if personID>%(long imdb name)s<if personID></a></if personID><if currentRole> ... %(currentRole)s<if notes> %(notes)s</if notes></if currentRole>'
 
79
 
 
80
 
 
81
Another useful argumento is 'applyToValues': if set to a function,
 
82
it will be applied to every value before the substitution; it can
 
83
be useful to format strings for html output.
 
84