def create_new_event(): c = Client(mock=False) id_network = request.args.get('id') user_id = current_user.id network = c.get_network(id_network) network_info = gather_network_info(id_network, user_id, c) if not network_info['user_is_member']: return render_template('network_create_event_post_not_member.html', curr_user_id=user_id, id_network=id_network, network_info=network_info, form=NetworkJoinForm()) network_title = network_info['network_title'] error_msg = None if request.method == 'GET': pass else: data = request.form form_submitted = CreateEventForm(request.form) if form_submitted.validate(): event_date = data['event_date'] title = data['title'] address_1 = data['address_1'] address_2 = data.get('address_2', None) country = data['country'] region = data.get('region', None) city = data.get('city', None) description = data['description'] event = { "id_network": id_network, "id_host": user_id, "event_date": event_date, "title": title, "address_1": address_1, "address_2": address_2, "country": country, "region": region, "city": city, "description": description } c.create_event(current_user, event) return redirect( url_for('networks.network_events') + "?id=%s" % str(id_network)) else: error_msg = "Oops. An error occurred. Did you enter all \ of the form fields correctly?" new_form = CreateEventForm() return render_template('network_create_event.html', curr_user_id=user_id, id_network=id_network, network_title=network_title, form=new_form, error_msg=error_msg)
def join_network(): id_network = request.args.get('id') id_user = current_user.id form = NetworkJoinForm(request.form) c = Client(mock=False) if form.validate(): c.join_network(current_user, id_network) network_info = gather_network_info(id_network, id_user, c, "join") return render_template( 'network.html', network_info=network_info, form=NetworkJoinForm() )
def create_new_post(): c = Client(mock=False) id_network = request.args.get('id') user_id = current_user.id network = c.get_network(id_network) network_info = gather_network_info(id_network, user_id, c) if not network_info['user_is_member']: return render_template( 'network_create_event_post_not_member.html', curr_user_id=user_id, id_network=id_network, network_info=network_info, form=NetworkJoinForm() ) network_title = network_info['network_title'] error_msg = None if request.method == 'GET': pass else: data = request.form form_submitted = CreatePostForm(request.form) if form_submitted.validate(): post_text = data['post_content'] post = { 'id_user': user_id, 'id_network': id_network, 'post_text': post_text, 'vid_link': "", 'img_link': "" } c.create_post(current_user, post) return redirect( url_for('networks.network_posts') + "?id=%s" % str(id_network) ) else: error_msg = "Oops. An error ocurred. Did you forget to add text to your \ post before submitting?" new_form = CreatePostForm() return render_template( 'network_create_post.html', curr_user_id=user_id, id_network=id_network, network_title=network_title, form=new_form, error_msg=error_msg )
def network(): id_network = request.args.get('id') c = Client(mock=False) id_user = current_user.id if is_logged_in(current_user) else None network_info = gather_network_info(id_network, id_user, c) upcoming_events = get_upcoming_events_by_network(c, id_network, 3) return render_template('network.html', network_info=network_info, form=NetworkJoinForm(), upcoming_events=upcoming_events)
def cancel_event_confirm(): current_event_id = request.args.get('id') c = Client(mock=False) event = c.get_event(current_event_id) network = c.get_network(event['id_network']) network_info = gather_network_info(network['id'], current_user.id, c) # The current user should only be able to cancel an event if they # are the host of that event. if not str(current_user.id) == str(event['id_host']): return redirect(url_for('user_home')) return render_template('event_cancel.html', network_info=network_info, event=event, form=EventCancelConfirmForm())
def leave(): c = Client(mock=False) id_network = request.args.get('id') user_id = current_user.id network = c.get_network(id_network) network_info = gather_network_info(id_network, user_id, c) if request.method == 'GET': if not network_info['user_is_member']: return redirect( url_for('networks.network') + "?id=%s" % str(id_network) ) return render_template( 'network_leave.html', id_network=id_network, network_title=network_info['network_title'], form=NetworkLeaveForm() ) elif request.method == 'POST': if network_info['user_is_member']: # NOTE: the two event deletion steps must happen in this order. # # Future TODO is to make this not a strict dependency. # # Delete all events this user is hosting in this network. events_hosting = c.get_user_events_hosting( user_id, 1000 ) for event in events_hosting: if str(event['id_network']) == str(network['id']): c.delete_event(current_user, str(event['id'])) # Unregister from all events this user is attending in this network. events_attending = c.get_events_attending_in_network( current_user, network['id'], 1000 ) for event in events_attending: c.leave_event(current_user, event['id']) # Leave the network. c.leave_network(current_user, network['id']) return redirect( url_for('user_home.render_user_home_networks') )