Esempio n. 1
0
def user_update(identifier):
    current_user = UserController().current_user
    current_user_id = UserController().current_user_id

    action = request.form.get('action')
    active = request.form.get('active') == 'true'

    if action == 'block':
        u = UserController().block_user(identifier, active)
    elif action == 'follow':
        u = UserController().follow_user(identifier, active)

    if u:
        events = []
        if not Block.blocks(u.user_id, current_user_id):
            events = EventController().get_events_for_user_by_interested(
                user=u, interested=UserEvent.INTERESTED)

    return redirect(request.referrer or '/')
Esempio n. 2
0
def user(identifier,
         interested=None,
         query=None,
         category=None,
         tag=None,
         cities=None,
         flags=None,
         lat=None,
         lon=None,
         page=1,
         next_page_url=None,
         prev_page_url=None,
         scroll=False,
         selected=None):
    selected_categories = category

    current_user = UserController().current_user
    current_user_id = UserController().current_user_id

    user = UserController().get_user(identifier)

    if user:
        events = []
        categories = []
        tags = []
        event_cities = []
        if not Block.blocks(user.user_id, current_user_id):
            events, categories, tags, event_cities = EventController(
            ).get_events_for_user_by_interested(user=user,
                                                query=query,
                                                categories=category,
                                                tags=tag,
                                                cities=cities,
                                                flags=flags,
                                                interested=interested,
                                                page=page)

        chips = _parse_chips(categories=categories,
                             selected_categories=selected_categories,
                             tags=tags,
                             cities=event_cities,
                             interested=interested,
                             flags=flags,
                             show_interested=True)

        vargs = {
            'current_user': current_user,
            'is_me': user == current_user,
            'events': events,
            'selected': selected,
            'chips': chips,
            'page': page,
            'next_page_url': next_page_url,
            'prev_page_url': prev_page_url
        }

        if user.user_id == current_user_id:
            return _render_events_list(request, events, vargs, scroll=scroll)
        else:
            vargs['user'] = user
            user.card_follower_count = user.follower_users_count()
            user.card_event_count = user.active_user_events_count()
            user.card_is_followed = user.is_follows_user(
                current_user) if current_user else False
            user.card_is_following = current_user.is_follows_user(
                user) if current_user else False
            user.card_is_blocked = current_user.is_blocks_user(
                user) if current_user else False

            return _render_events_list(request,
                                       events,
                                       vargs,
                                       template=TEMPLATE_USER_PAGE,
                                       scroll=scroll)
    return redirect(request.referrer or '/')