/[glsr]/trunk/site/table_listing.py
Gentoo

Diff of /trunk/site/table_listing.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 133 Revision 134
25 """ 25 """
26 26
27 def __init__(self, harm): 27 def __init__(self, harm):
28 28
29 BaseDomain.__init__(self, harm) 29 BaseDomain.__init__(self, harm)
30 self._domain = ""
30 self._page = "" 31 self._page = ""
31 self._list_title = "" 32 self._list_title = ""
32 self._fields = [] 33 self._fields = []
34 self._hidden_fields = []
33 self._loop_data = [] 35 self._loop_data = []
34 36
35 def init(self, page = "", list_title = "Default Title", fields = None): 37 def init(self, page = "", list_title = "Default Title", fields = None):
36 """Initialize the extra variables used in this class.""" 38 """Initialize the extra variables used in this class."""
37 39
39 self._list_title = list_title 41 self._list_title = list_title
40 self._fields = fields 42 self._fields = fields
41 if self._fields is None: 43 if self._fields is None:
42 self._fields = [] 44 self._fields = []
43 45
46 def _generate_link(self, link_info, data):
47 if type(link_info) not in (list, tuple):
48 return link_info
49
50 link = link_info[0]
51 for value in link_info[1:]:
52 link = link % (data[value])
53
54 return link
55
44 def _make_table(self): 56 def _make_table(self):
45 """The core member function. 57 """The core member function.
46 58
47 Sets all variables necessary to display a nice neat sorted table. 59 Sets all variables necessary to display a nice neat sorted table.
48 """ 60 """
61 # values to output in a single loop. 73 # values to output in a single loop.
62 for record in loop_data: 74 for record in loop_data:
63 fields = deepcopy(self._fields) 75 fields = deepcopy(self._fields)
64 for field in fields: 76 for field in fields:
65 field["value"] = record[field["name"]] 77 field["value"] = record[field["name"]]
78 if field.has_key("link"):
79 field["link"] = self._generate_link(field["link"], record)
66 80
67 record.update({"fields": fields}) 81 record.update({"fields": fields})
68 82
69 self._set_template(os.path.join(config.template_loc, 83 self._set_template(os.path.join(config.template_loc,
70 'table_listing.tpl')) 84 'table_listing.tpl'))
85
86 extra_fields = "".join(["&%s=%s" % (field["name"], field["value"])
87 for field in self._hidden_fields])
71 88
72 self._template.param("GLSR_URL", config.url) 89 self._template.param("GLSR_URL", config.url)
73 self._template.param("LIST_TITLE", self._list_title) 90 self._template.param("LIST_TITLE", self._list_title)
74 self._template.param("PAGE_NUM", current_page) 91 self._template.param("PAGE_NUM", current_page)
92 self._template.param("DOMAIN", self._domain)
75 self._template.param("PAGE", self._page) 93 self._template.param("PAGE", self._page)
76 self._template.param("START", start) 94 self._template.param("START", start)
77 self._template.param("NEXT_START", start + items_per_page) 95 self._template.param("NEXT_START", start + items_per_page)
78 self._template.param("PAGE_LOOP", page_loop) 96 self._template.param("PAGE_LOOP", page_loop)
97 self._template.param("EXTRA_FIELDS", extra_fields)
79 self._template.param("FIELDS", self._fields) 98 self._template.param("FIELDS", self._fields)
80 self._template.param("LOOP_DATA", loop_data) 99 self._template.param("LOOP_DATA", loop_data)
81 100
82 101
83 def _pages(self, list_in, start): 102 def _pages(self, list_in, start):
109 return 1 * ascending 128 return 1 * ascending
110 elif val1[sortby] < val2[sortby]: 129 elif val1[sortby] < val2[sortby]:
111 return -1 * ascending 130 return -1 * ascending
112 return 0 131 return 0
113 132
114 sortby = self._harm.request.queries.get("sortby", "user_id") 133 sortby = self._harm.request.queries.get("sortby",
134 self._fields[0]["name"])
115 order = self._harm.request.queries.get("order", "a") 135 order = self._harm.request.queries.get("order", "a")
116 136
117 if order == 'd': 137 if order == 'd':
118 ascending = -1 138 ascending = -1
119 139

Legend:
Removed from v.133  
changed lines
  Added in v.134

  ViewVC Help
Powered by ViewVC 1.1.20