Пример #1
0
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([])

    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))
Пример #2
0
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))
Пример #3
0
def register(login, **kwargs):
    """Register a new user
    """
    if env.user.is_authorized():
        raise AlreadyAuthorized(env.user.login)

    try:
        if User('login', login):
            raise UserExists(login)
    except UserNotFound:
        pass

    env.user = env.user.__class__.from_data(None, login, **kwargs)
    env.user.save()

    add_post('User @%s is registered' % login,
             author=User('login', 'welcome'), auto_subscribe=False)
Пример #4
0
def register(login, **kwargs):
    """Register a new user
    """
    if env.user.is_authorized():
        raise AlreadyAuthorized(env.user.login)

    try:
        if User('login', login):
            raise UserExists(login)
    except UserNotFound:
        pass

    env.user = env.user.__class__.from_data(None, login, **kwargs)
    env.user.save()

    add_post('User @%s is registered' % login,
             author=User('login', 'welcome'), auto_subscribe=False)
Пример #5
0
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)
Пример #6
0
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)
Пример #7
0
    def update_feed(self, id):
        try:
            feed = Feed(id)
        except FeedNotFound:
            log.error('Feed #%s does not exist. Skipped.' % id)
            return

        redis = RedisPool(settings.storage_socket)

        try:
            feed.fetch()

            redis.delete('feed:retries:%s' % feed.id)

            for p in feed.posts():
                if not p.id:
                    if p.tags:
                        p.tags.insert(0, 'news')
                    else:
                        p.tags = ['news']
                    add_post(p)

            log.info('Feed #%s: %s new entries saved' % \
                     (feed.id, len(feed.posts())))

            feed.update_task()

        except FeedFetchError:
            retries = redis.incr('feed:retries:%s' % feed.id)
            log.error('Feed #%s: %s retries failed' % (feed.id, retries))
            if retries > settings.feed_retries:
                redis.delete('feed:retries:%s' % feed.id)
                return
            timeout = settings.feed_retry_timeout * retries
            feed.update_at(datetime.now() + timedelta(seconds=timeout))

        except InvalidFeedType:
            redis.delete('feed:retries:%s' % feed.id)
            feed.update_at(datetime.now() + \
                           timedelta(seconds=settings.feed_max_update_timeout))
Пример #8
0
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}
Пример #9
0
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}