This has kept me up quite a few hours last night, this morning I woke
up and I still have no clue how to approach this. I am still pretty
new to Python & web2py but I can't believe a simple string function
gives me so much grief.
My goal:
I am making a simple shoutbox for practice purposes, it uses a
database with the colloms: Shout,created_on,created_by
I have a database result set in the controller of the shoutbox
( shouts = db(db.shouts).select(orderby=~db.shouts.created_on) ).
Now the problem I run into is when I want to implement a simple emote
system. Basicly I want to perform a simple string replace on
shouts.Shout.
Because I have no idea how to manipulate the database result set
(which I also would like to know) I figured I would deal with it in
the view, not really ideal I would guess.
So I have a function in a module:
def ParseEmote(text):
text = text.replace("test","bla")
return text
in the view I have:
{{for shout in shouts:}}
{{result = functions.timesince(shout.created_on)}}
<div style="font-size:12px;">
<span
style="color:#0F0">{{=db.auth_user[shout.created_by].first_name}}</
span>
<span style="color:#999;">says ({{=result}} ago): </
span>
</div>
{{=functions.ParseEmote(shout.Shout)}}
{{pass}}
The error I get is:
Traceback (most recent call last):
File "gluon/restricted.py", line 192, in restricted
File "G:\web2py\applications\the_old_republic\views\default/
shoutbox.html", line 15, in <module>
File "applications/The_Old_Republic/controllers/functions.py", line
7, in ParseEmote
AttributeError: 'NoneType' object has no attribute 'replace'
Now my question is:
1. How can I modify my ParseEmote function to deal with the
shout.Shout variable which seems to be a NoneType which I dont really
get. Its not really the best solution but I might come in handy later.
2. Is there a way I can get a similar result by just using just the
controller? something like (but then working):
shouts = db(db.shouts).select(orderby=~db.shouts.created_on)
for s in shouts:
s.Shout.replace(":emote1:","somehtml")
pass
Regards,
Yuushi