Re: [Trac] Re: TracHours plugin - updating for Trac 1.6 - AttributeError: 'str' object has no attribute 'setdefault'
Jun Omae <[email protected]> Wed, 27 Aug 2025 17:24:49 +0900
| Newsgroups | gmane.comp.version-control.subversion.trac.general |
|---|---|
| Message-ID | <[email protected]> |
The post_process_request receives the returned values from process_request. For Jinja2 templates, the process_request should return a tuple of (template, data).
See https://trac.edgewall.org/wiki/TracDev/PortingFromGenshiToJinja#IRequestHandler
Therefore, before implementing IRequestFilter interface, the returned values of process_request should be modified and the template should be ported to Jinja2 from Genshi.
Index: trachours/hours.py
===================================================================
--- trachours/hours.py (revision 18705)
+++ trachours/hours.py (working copy)
@@ -384,8 +384,8 @@
data['queries'] = get_all_dict(self.env, """
SELECT id, title, description, query FROM ticket_time_query
""")
- return 'hours_listqueries.html', data, 'text/html'
- return 'hours_savequery.html', data, 'text/html'
+ return 'hours_listqueries.html', data
+ return 'hours_savequery.html', data
def process_query(self, req):
"""redict to save, edit or delete a query based on arguments"""
@@ -842,7 +842,7 @@
add_stylesheet(req, 'common/css/report.css')
add_script(req, 'common/js/query.js')
- return 'hours_timeline.html', data, 'text/html'
+ return 'hours_timeline.html', data
def process_ticket(self, req):
"""process a request to /hours/<ticket number>"""
@@ -901,7 +901,7 @@
add_ctxtnav(req, 'Back to Ticket #%s' % ticket_id,
req.href.ticket(ticket_id))
- return 'hours_ticket.html', data, 'text/html'
+ return 'hours_ticket.html', data
# Methods for transforming data to rss
Index: trachours/multiproject.py
===================================================================
--- trachours/multiproject.py (revision 18705)
+++ trachours/multiproject.py (working copy)
@@ -204,7 +204,7 @@
data['total'] = hours_format % total
- return 'hours_multiproject.html', data, 'text/html'
+ return 'hours_multiproject.html', data
if __name__ == '__main__':
Index: trachours/web_ui.py
===================================================================
--- trachours/web_ui.py (revision 18705)
+++ trachours/web_ui.py (working copy)
@@ -311,7 +311,7 @@
# _('Next Week'))
# prevnext_nav(req, _('Prev Week'), _('Next Week'))
- return 'hours_users.html', data, "text/html"
+ return 'hours_users.html', data
def user(self, req, user):
"""hours page for a single user"""
@@ -360,7 +360,7 @@
req.send(buffer.getvalue(), 'text/csv')
- return 'hours_user.html', data, 'text/html'
+ return 'hours_user.html', data
def export_csv(self, req, data, sep=',', mimetype='text/csv'):
content = StringIO()
On 2025/08/27 10:59, Rob Hills wrote:
> I'm using https://trac.edgewall.org/wiki/TracDev/PortingFromGenshiToJinja as a guide to help me update the TracHours plugin <https://trac-hacks.org/wiki/TracHoursPlugin> to work with Trac 1.6
>
> I have implemented the IRequestFilter interface and added a post_process_request() method which returns three results: template, data and content_type, as shown in the Porting from Genshi to Jinja howto <https://trac.edgewall.org/wiki/TracDev/PortingFromGenshiToJinja#ImplementIRequestFilter.post_process_requesttoconditionallyaddJavaScriptcode>. The content_type variable is passed in via the method call and not altered, and is the string "text/html"
>
> However, when this gets processed via trac.web.main here <https://github.com/edgewall/trac/blob/0dde63bb84da28ad87f1a3d3d7bea7b55d415620/trac/web/main.py#L250>, the content_type variable returned by the post_process_request() method gets transferred into the metadata variable and a few lines down here <https://github.com/edgewall/trac/blob/0dde63bb84da28ad87f1a3d3d7bea7b55d415620/trac/web/main.py#L264>, the code expects metadata to have a "setdefault" method. As it's a string, it doesn't have this method and hence throws the AttributeError "''str' object has no attribute 'setdefault'".
>
> I suspect I'm doing something wrong in my code, but I'm not sure what!
>
> Rob Hills
> Waikiki, Western Australia
>
>
> On Wednesday, 27 August 2025 at 01:16:21 UTC+8 RjOllos wrote:
>
> On Tuesday, August 26, 2025 at 5:45:49 AM UTC-7 [email protected] wrote:
>
> I posted this <https://groups.google.com/g/trac-hacks/c/_FJQMrNekZQ/m/FZ81e_N-AAAJ> on the Trac Hacks group but got no replies. Is that group still going?
>
>
> It's dead.
>
>
>
> Should I post the original query here instead?
>
>
> Yes, please do.
>
> --
> You received this message because you are subscribed to the Google Groups "Trac Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to trac-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
> To view this discussion visit https://groups.google.com/d/msgid/trac-users/3341c5e4-b7a9-4d44-b121-daba8f3a05ecn%40googlegroups.com <https://groups.google.com/d/msgid/trac-users/3341c5e4-b7a9-4d44-b121-daba8f3a05ecn%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
Jun Omae <[email protected]> (大前 潤)
--
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trac-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
To view this discussion visit https://groups.google.com/d/msgid/trac-users/97494b08-df1d-4edf-b669-ea33102ac3e3%40gmail.com.