Beispiel #1
0
def enhance_event_info(client, events):
    for event in events:
        enhance_event_date_info(event)
        event['network_title'] = get_network_title(
            client.get_network(event['id_network']))
        event['num_registered'] = client.get_event_reg_count(
            event['id'])['reg_count']
    return events
Beispiel #2
0
def gather_network_info(id_network, id_user, client, scenario="normal"):

    network = client.get_network(id_network)
    recent_posts = client.get_network_posts(id_network, 3)
    recent_events = client.get_network_events(id_network, 3)
    for event in recent_events:
        utils.enhance_event_date_info(event)

    for post in recent_posts:
        post['username'] = client.get_user(post['id_user'])['username']
        post['reply_count'] = client.get_post_reply_count(
            post['id'])['reply_count']
        post['time_ago'] = get_time_ago(post['post_date'])

    user_is_member = False
    if not id_user == None:
        user_networks = client.get_user_networks(id_user, count=100)
        for network_ in user_networks:
            if int(id_network) == int(network_['id']):
                user_is_member = True
                break

    network_info = {}
    network_info['id'] = id_network
    network_info['posts'] = recent_posts
    network_info['events'] = recent_events
    network_info['network_title'] = get_network_title(network)
    network_info['user_is_member'] = user_is_member

    if user_is_member and scenario == 'normal':
        network_info[
            'greeting'] = 'You are a member of this network.  Welcome!'
    elif not user_is_member and scenario == 'normal':
        network_info[
            'greeting'] = 'You are not a member of this network. Join now to create posts and events.'
    elif user_is_member and scenario == 'join':
        network_info['greeting'] = 'You just joined this network. Welcome!'
    elif not user_is_member and scenario == 'join':
        network_info[
            'greeting'] = 'Looks like something went wrong. Try joining later.'
    elif user_is_member and scenario == 'leave':
        network_info[
            'greeting'] = 'Looks like something went wrong. Try leaving later.'
    elif not user_is_member and scenario == 'leave':
        network_info['greeting'] = 'You just left this network. Bye bye!'

    num_users = client.get_network_user_count(id_network)['user_count']
    num_posts = client.get_network_post_count(id_network)['post_count']

    network_info['num_users'] = num_users
    network_info['num_posts'] = num_posts
    return network_info
Beispiel #3
0
def render_event():
    current_event_id = request.args.get('id')
    c = Client(mock=False)
    event = c.get_event(current_event_id)
    date_info = {}
    enhance_event_date_info(event)
    event['num_registered'] = c.get_event_reg_count(event['id'])['reg_count']

    network = c.get_network(event['id_network'])
    event['network_title'] = get_network_title(network)
    event['location'] = get_event_location(event)
    host = c.get_user(event['id_host'])

    role = None

    if is_logged_in(current_user):
        user_id = current_user.id
        if event['id_host'] == int(user_id):

          # The current user is hosting this event.
          role = 'hosting'
          host['username'] = '******'

        elif user_is_attending_event(c, user_id, event):

          # The current user is already signed up for this event.
          role = 'attending'
        else:

          # The current user is not signed up for this event.
          pass
    else:
        user_id = None

    return render_template(
      'event.html',
      event=event,
      host=host,
      role=role,
      curr_user_id=user_id,
      join_form=EventJoinForm(),
      leave_form=EventLeaveForm(),
      cancel_form=EventCancelForm()
    )
Beispiel #4
0
def network_events() :
  # TODO: A lot of this code is repeated from network(), with just minor variations.
  # This should be factored out.
  id_network = request.args.get('id')
  if not id_network :
    return render_template('404.html')
  c = Client(mock=False)
  try:
    id_network = int(id_network)
  except ValueError:
    return render_template('404.html')
  network = c.get_network(id_network)
  if not network:
    return render_template('404.html')

  events = None

  old_index = request.args.get('index')
  if not old_index:
    events = c.get_network_events(id_network, 10)
  else:
    try:
      old_index = int(old_index)
    except ValueError:
      return render_template('404.html')
    events = c.get_network_events(id_network, 10, old_index - 1)

  # TODO: Add better handling for when there's no posts left.

  if not events :
    event_index = old_index
  else :
    event_index = events[-1]['id']

  for event in events:
    utils.enhance_event_date_info(event)
    event['num_registered'] = c.get_event_reg_count(event['id'])['reg_count']

  id_user = current_user.id
  user_networks = c.get_user_networks(id_user, count=100)
  user_is_member = False
  for network_ in user_networks:
    if int(id_network) == int(network_['id']):
      user_is_member = True
      break

  network_info = {}
  network_info['id'] = id_network
  network_info['events'] = events
  network_info['network_title'] = get_network_title(network)
  network_info['user_is_member'] = user_is_member

  num_users = c.get_network_user_count(id_network)['user_count']
  num_posts = c.get_network_post_count(id_network)['post_count']

  network_info['num_users'] = num_users
  network_info['num_posts'] = num_posts

  referrer = request.headers.get("Referer")

  return render_template(
    'network_events.html', network_info=network_info,
    event_index=event_index, referer_url=referrer
  )