Created
September 25, 2013 17:29
-
-
Save daeken/6703071 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Profile(db.Model): | |
| user = db.UserProperty() | |
| nickname = db.TextProperty() | |
| desc = db.TextProperty() | |
| pic = db.TextProperty() | |
| def html_desc(self): | |
| def rep(match): | |
| sub = match.group(1) | |
| if '|' not in sub: | |
| return '[' + sub + ']' | |
| else: | |
| color, text = sub.split('|', 1) | |
| color = color.replace('<', '\0') | |
| color = color.replace('>', '\x02') | |
| color = color.replace('"', '\x01') | |
| return '\0span style=\x01color: %s\x01\x02%s\x00/span\x02' % (color.strip(), text.strip()) | |
| desc = re.sub(r'\[(.*?)\]', rep, self.desc) | |
| desc = desc.replace('<', '<') | |
| desc = desc.replace('>', '>') | |
| desc = desc.replace('"', '"') | |
| desc = desc.replace('\0', '<') | |
| desc = desc.replace('\x02', '>') | |
| desc = desc.replace('\x01', '"') | |
| desc = desc.replace('\n', '<br>') | |
| return desc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment