def add_post(): text = env.request.args('text', '').strip() tags = env.request.args('tags', '').strip(' \t*,;') if isinstance(tags, str): tags = tags.decode('utf-8') tags = [t.replace(u"\xa0", " ") for t in re.split(r'\s*[,;*]\s*', tags)] private = bool(env.request.args('private')) m = re.search(r'^\s*(?P<to>(?:@[a-z0-9_-]+[,\s]*)+)', text) to = parse_logins(m.group('to')) if m else [] files = _files([]) sess = Session() sess['clear_post_input'] = True sess.save() try: id = posts.add_post(text, tags=tags, to=to, private=private, files=files) except PostTextError: return render('/post-error.html') return Response(redirect='%s://%s.%s/%s' % \ (env.request.protocol, env.user.login, settings.domain, id))
def del_recipients(post_id, to): to = parse_logins(to) try: posts.del_recipients(post_id, to) except PostNotFound: return xmpp_template('post_not_found', post_id=post_id) except PostAuthorError: return xmpp_template('post_denied', post_id=post_id) except UserNotFound, e: return xmpp_template('user_not_found', login=e.message)
def add_post(text, taglist=None, to=None, private=False): taglist = parse_tags(taglist) if to: text = '%s %s' % (to.strip(), text.strip()) to = parse_logins(to) try: post_id = posts.add_post(text, tags=taglist, to=to, private=private) except PostTextError: return xmpp_template('post_inadmissible') except UserNotFound, e: return xmpp_template('user_not_found', login=e.message)
def add_post(): text = env.request.args('text', '').strip() tags = env.request.args('tag', '') or env.request.args('tag[]', '') if not tags: tags = [] elif not isinstance(tags, (list, tuple)): tags = [tags] def _t(tag): if isinstance(tag, str): tag = tag.decode('utf-8') return tag.replace(u"\xa0", " ") tags = map(_t, tags) private = bool(env.request.args('private')) m = re.search(r'^\s*(?P<to>(?:@[a-z0-9_-]+[,\s]*)+)', text) to = parse_logins(m.group('to')) if m else [] id = posts.add_post(text, tags=tags, to=to, private=private) return {"id": id}