def process_session_view(session_id):
    if request.method == 'GET':
        session = DataGetter.get_sessions_of_user_by_id(session_id)
        if not session:
            abort(404)
        form_elems = DataGetter.get_custom_form_elements(session.event_id)
        if not form_elems:
            flash("Speaker and Session forms have been incorrectly configured for this event."
                  " Session creation has been disabled", "danger")
            return redirect(url_for('.display_my_sessions_view', event_id=session.event_id))
        speaker_form = json.loads(form_elems.speaker_form)
        session_form = json.loads(form_elems.session_form)
        event = DataGetter.get_event(session.event_id)
        speaker = DataGetter.get_speakers(session.event_id).filter_by(user_id=login.current_user.id).first()
        return render_template(
            'gentelella/users/mysessions/mysession_detail_edit.html', session=session,
            photo_delete_url=url_for('.avatar_delete', event_id=event.id, speaker_id=speaker.id),
            speaker_form=speaker_form, session_form=session_form, event=event, speaker=speaker)

    if request.method == 'POST':
        session = DataGetter.get_sessions_of_user_by_id(session_id)
        speaker = DataGetter.get_speakers(session.event_id).filter_by(user_id=login.current_user.id).first()
        DataManager.edit_session(request, session, speaker)
        flash("The session has been updated successfully", "success")
        return redirect(url_for('.display_session_view', session_id=session_id))
def trash_view(event_id):
    if request.method == "GET":
        DataManager.trash_event(event_id)
    flash("Your event has been deleted.", "danger")
    if current_user.is_super_admin:
        return redirect(url_for('sadmin_events.index_view'))
    return redirect(url_for('.index_view'))
示例#3
0
def change_password_view(hash):
    """Change password view"""
    if request.method == 'GET':
        return render_template('gentelella/users/login/change_password.html')
    if request.method == 'POST':
        DataManager.reset_password(request.form, hash)
        return redirect(url_for('.index'))
def user_role_invite(event_id, hash):
    """Accept User-Role invite for the event.
    """
    event = DataGetter.get_event(event_id)
    user = current_user
    role_invite = DataGetter.get_event_role_invite(event.id, hash,
                                                   email=user.email)

    if role_invite:
        if role_invite.has_expired():
            delete_from_db(role_invite, 'Deleted RoleInvite')

            flash('Sorry, the invitation link has expired.', 'error')
            return redirect(url_for('.details_view', event_id=event.id))

        if user.has_role(event.id):
            flash('You have already been assigned a Role in the Event.', 'warning')
            return redirect(url_for('events.details_view', event_id=event_id))

        role = role_invite.role
        data = dict()
        data['user_email'] = role_invite.email
        data['user_role'] = role.name
        DataManager.add_role_to_event(data, event.id)

        # Delete Role Invite after it has been accepted
        delete_from_db(role_invite, 'Deleted RoleInvite')

        flash('You have been added as a %s' % role.title_name)
        return redirect(url_for('.details_view', event_id=event.id))
    else:
        abort(404)
def process_session_view(session_id):
    if request.method == 'GET':
        session = DataGetter.get_sessions_of_user_by_id(session_id)
        speaker = DataGetter.get_speakers(
            session.event_id).filter_by(user_id=login.current_user.id).first()
        if not session:
            abort(404)
        form_elems = DataGetter.get_custom_form_elements(session.event_id)
        if not form_elems:
            flash(
                "Speaker and Session forms have been incorrectly configured for this event."
                " Session creation has been disabled", "danger")
            return redirect(
                url_for('.display_my_sessions_view',
                        event_id=session.event_id))
        session_form = json.loads(form_elems.session_form)
        event = DataGetter.get_event(session.event_id)
        return render_template(
            'gentelella/users/mysessions/mysession_session_edit.html',
            session=session,
            speaker=speaker,
            session_form=session_form,
            event=event)

    if request.method == 'POST':
        session = DataGetter.get_sessions_of_user_by_id(session_id)
        speaker = DataGetter.get_speakers(
            session.event_id).filter_by(user_id=login.current_user.id).first()
        DataManager.edit_session(request, session, speaker)
        flash("The session has been updated successfully", "success")
        return redirect(url_for('.display_session_view',
                                session_id=session_id))
示例#6
0
def empty_trash():
    from app import current_app as app

    with app.app_context():
        events = Event.query.filter(Event.deleted_at.isnot(None)).all()
        users = User.query.filter(User.deleted_at.isnot(None)).all()
        sessions = Session.query.filter(Session.deleted_at.isnot(None)).all()
        pending_orders = Order.query.filter_by(status="pending")

        for event in events:
            if datetime.now() - event.deleted_at >= timedelta(days=30):
                DataManager.delete_event(event.id)

        for user in users:
            if datetime.now() - user.deleted_at >= timedelta(days=30):
                transaction = transaction_class(Event)
                transaction.query.filter_by(user_id=user.id).delete()
                delete_from_db(user, "User deleted permanently")

        for session_ in sessions:
            if datetime.now() - session_.deleted_at >= timedelta(days=30):
                delete_from_db(session_, "Session deleted permanently")

        for pending_order in pending_orders:
            if datetime.now() - pending_order.created_at >= timedelta(days=3):
                pending_order.status = "expired"
                save_to_db(pending_order, "Pending order expired.")
    def index_view(self):
        if request.method == 'POST':
            DataManager.update_permissions(request.form)

        perms = dict()
        roles = DataGetter.get_roles()
        services = DataGetter.get_services()
        get_permission = DataGetter.get_permission_by_role_service

        for role in roles:
            perms[role] = dict()
            for service in services:
                perms[role][service.name] = dict()
                p = get_permission(role=role, service=service)
                if not p:
                    perms[role][service.name]['c'] = False
                    perms[role][service.name]['r'] = False
                    perms[role][service.name]['u'] = False
                    perms[role][service.name]['d'] = False
                else:
                    perms[role][service.name]['c'] = p.can_create
                    perms[role][service.name]['r'] = p.can_read
                    perms[role][service.name]['u'] = p.can_update
                    perms[role][service.name]['d'] = p.can_delete

        return self.render(
            '/gentelella/admin/super_admin/permissions/permissions.html',
            perms=sorted(perms.iteritems(),
                         key=lambda (k, v): k.name))
def empty_trash():
    from app import current_app as app

    with app.app_context():
        events = Event.query.filter(Event.deleted_at.isnot(None)).all()
        users = User.query.filter(User.deleted_at.isnot(None)).all()
        sessions = Session.query.filter(Session.deleted_at.isnot(None)).all()
        pending_orders = Order.query.filter_by(status="pending")

        for event in events:
            if datetime.now() - event.deleted_at >= timedelta(days=30):
                DataManager.delete_event(event.id)

        for user in users:
            if datetime.now() - user.deleted_at >= timedelta(days=30):
                transaction = transaction_class(Event)
                transaction.query.filter_by(user_id=user.id).delete()
                delete_from_db(user, "User deleted permanently")

        for session_ in sessions:
            if datetime.now() - session_.deleted_at >= timedelta(days=30):
                delete_from_db(session_, "Session deleted permanently")

        for pending_order in pending_orders:
            if datetime.now() - pending_order.created_at >= timedelta(days=3):
                pending_order.status = "expired"
                save_to_db(pending_order, "Pending order expired.")
def process_event_cfs_speaker(identifier, via_hash=False):
    if request.method == 'GET':
        event = get_published_event_or_abort(identifier)
        placeholder_images = DataGetter.get_event_default_images()
        if event.sub_topic:
            custom_placeholder = DataGetter.get_custom_placeholder_by_name(event.sub_topic)
        elif event.topic:
            custom_placeholder = DataGetter.get_custom_placeholder_by_name(event.topic)
        else:
            custom_placeholder = DataGetter.get_custom_placeholder_by_name('Other')
        if not event.has_session_speakers:
            abort(404)

        call_for_speakers = DataGetter.get_call_for_papers(event.id).first()

        if not call_for_speakers or (not via_hash and call_for_speakers.privacy == 'private'):
            abort(404)

        form_elems = DataGetter.get_custom_form_elements(event.id)
        speaker_form = json.loads(form_elems.speaker_form)
        session_form = json.loads(form_elems.session_form)

        now = datetime.now(pytz.timezone(event.timezone
                                                  if (event.timezone and event.timezone != '') else 'UTC'))
        start_date = pytz.timezone(event.timezone).localize(call_for_speakers.start_date)
        end_date = pytz.timezone(event.timezone).localize(call_for_speakers.end_date)
        state = "now"
        if end_date < now:
            state = "past"
        elif start_date > now:
            state = "future"
        speakers = DataGetter.get_speakers(event.id).all()
        accepted_sessions_count = get_count(DataGetter.get_sessions(event.id))
        return render_template('gentelella/guest/event/cfs_new_speaker.html',
                               event=event,
                               speaker_form=speaker_form,
                               accepted_sessions_count=accepted_sessions_count,
                               session_form=session_form,
                               call_for_speakers=call_for_speakers,
                               placeholder_images=placeholder_images,
                               state=state,
                               speakers=speakers,
                               via_hash=via_hash,
                               custom_placeholder=custom_placeholder,
                               from_path="cfs")

    if request.method == 'POST':
        email = request.form['email']
        event = DataGetter.get_event_by_identifier(identifier)
        if not event.has_session_speakers:
            abort(404)
        DataManager.add_speaker_to_event(request, event.id)
        if login.current_user.is_authenticated:
            flash("You have been registered as Speaker", "success")
            return redirect(url_for('event_detail.display_event_cfs', identifier=identifier))
        else:
            flash(Markup(
                "You have been registered as Speaker. Please login/register with <strong><u>" + email + "</u></strong> to manage it."),
                "success")
            return redirect(url_for('admin.login_view', next=url_for('my_sessions.display_my_sessions_view')))
    def process_session_view(self, session_id):
        if request.method == 'GET':
            session = DataGetter.get_sessions_of_user_by_id(session_id)
            if not session:
                abort(404)
            form_elems = DataGetter.get_custom_form_elements(session.event_id)
            if not form_elems:
                flash(
                    "Speaker and Session forms have been incorrectly configured for this event."
                    " Session creation has been disabled", "danger")
                return redirect(
                    url_for('.display_my_sessions_view',
                            event_id=session.event_id))
            speaker_form = json.loads(form_elems.speaker_form)
            session_form = json.loads(form_elems.session_form)
            event = DataGetter.get_event(session.event_id)
            speakers = DataGetter.get_speakers(session.event_id).all()
            return self.render(
                '/gentelella/admin/mysessions/mysession_detail_edit.html',
                session=session,
                speaker_form=speaker_form,
                session_form=session_form,
                event=event,
                speakers=speakers)

        if request.method == 'POST':
            session = DataGetter.get_sessions_of_user_by_id(session_id)
            DataManager.edit_session(request, session)
            flash("The session has been updated successfully", "success")
            return redirect(
                url_for('.display_session_view', session_id=session_id))
def process_event_cfs_speaker(identifier, via_hash=False):
    if request.method == 'GET':
        event = get_published_event_or_abort(identifier)
        placeholder_images = DataGetter.get_event_default_images()
        if event.sub_topic:
            custom_placeholder = DataGetter.get_custom_placeholder_by_name(event.sub_topic)
        elif event.topic:
            custom_placeholder = DataGetter.get_custom_placeholder_by_name(event.topic)
        else:
            custom_placeholder = DataGetter.get_custom_placeholder_by_name('Other')
        if not event.has_session_speakers:
            abort(404)

        call_for_speakers = DataGetter.get_call_for_papers(event.id).first()

        if not call_for_speakers or (not via_hash and call_for_speakers.privacy == 'private'):
            abort(404)

        form_elems = DataGetter.get_custom_form_elements(event.id)
        speaker_form = json.loads(form_elems.speaker_form)
        session_form = json.loads(form_elems.session_form)

        now = datetime.now(pytz.timezone(event.timezone
                                                  if (event.timezone and event.timezone != '') else 'UTC'))
        start_date = pytz.timezone(event.timezone).localize(call_for_speakers.start_date)
        end_date = pytz.timezone(event.timezone).localize(call_for_speakers.end_date)
        state = "now"
        if end_date < now:
            state = "past"
        elif start_date > now:
            state = "future"
        speakers = DataGetter.get_speakers(event.id).all()
        accepted_sessions_count = get_count(DataGetter.get_sessions(event.id))
        return render_template('gentelella/guest/event/cfs_new_speaker.html',
                               event=event,
                               speaker_form=speaker_form,
                               accepted_sessions_count=accepted_sessions_count,
                               session_form=session_form,
                               call_for_speakers=call_for_speakers,
                               placeholder_images=placeholder_images,
                               state=state,
                               speakers=speakers,
                               via_hash=via_hash,
                               custom_placeholder=custom_placeholder,
                               from_path="cfs")

    if request.method == 'POST':
        email = request.form['email']
        event = DataGetter.get_event_by_identifier(identifier)
        if not event.has_session_speakers:
            abort(404)
        DataManager.add_speaker_to_event(request, event.id)
        if login.current_user.is_authenticated:
            flash("You have been registered as Speaker", "success")
            return redirect(url_for('event_detail.display_event_cfs', identifier=identifier))
        else:
            flash(Markup(
                "You have been registered as Speaker. Please login/register with <strong><u>" + email + "</u></strong> to manage it."),
                "success")
            return redirect(url_for('admin.login_view', next=url_for('my_sessions.display_my_sessions_view')))
示例#12
0
def trash_view(event_id):
    if request.method == "GET":
        DataManager.trash_event(event_id)
    flash("Your event has been deleted.", "danger")
    if current_user.is_super_admin:
        return redirect(url_for('sadmin_events.index_view'))
    return redirect(url_for('.index_view'))
示例#13
0
def change_password_view(hash):
    """Change password view"""
    if request.method == 'GET':
        return render_template('gentelella/admin/login/change_password.html')
    if request.method == 'POST':
        DataManager.reset_password(request.form, hash)
        return redirect(url_for('.index'))
def create_view(event_id):
    event = DataGetter.get_event(event_id)
    if not event.has_session_speakers:
        return render_template(
            'gentelella/admin/event/info/enable_module.html',
            active_page='sessions',
            title='Sessions',
            event=event)
    if request.method == 'POST':
        DataManager.add_session_to_event(request, event_id)
        flash("The session and speaker have been saved")
        get_from = request.args.get("from")
        if get_from and get_from == 'speaker':
            return redirect(
                url_for('event_speakers.index_view', event_id=event_id))
        return redirect(url_for('.index_view', event_id=event_id))

    form_elems = DataGetter.get_custom_form_elements(event_id)
    if not form_elems:
        flash(
            "Speaker and Session forms have been incorrectly configured for this event."
            " Session creation has been disabled", "danger")
        return redirect(url_for('.index_view', event_id=event_id))
    speaker_form = json.loads(form_elems.speaker_form)
    session_form = json.loads(form_elems.session_form)
    speakers = DataGetter.get_speakers(event_id).all()

    return render_template('gentelella/admin/event/sessions/new.html',
                           speaker_form=speaker_form,
                           session_form=session_form,
                           event=event,
                           speakers=speakers)
def session_display_view(event_id, session_id):
    session = get_session_or_throw(session_id)
    if request.method == 'POST':
        DataManager.edit_session(request, session)
        return redirect(url_for('.index_view', event_id=event_id))
    event = DataGetter.get_event(event_id)
    if not event.has_session_speakers:
        return render_template(
            'gentelella/admin/event/info/enable_module.html',
            active_page='sessions',
            title='Sessions',
            event=event)
    form_elems = DataGetter.get_custom_form_elements(event_id)
    if not form_elems:
        flash(
            "Speaker and Session forms have been incorrectly configured for this event."
            " Session creation has been disabled", "danger")
        return redirect(url_for('.index_view', event_id=event_id))
    session_form = json.loads(form_elems.session_form)
    speakers = DataGetter.get_speakers(event_id).all()

    return render_template('gentelella/admin/event/sessions/edit.html',
                           session=session,
                           session_form=session_form,
                           event_id=event_id,
                           event=event,
                           speakers=speakers)
def process_speaker_view(speaker_id):
    if request.method == 'GET':
        speaker = DataGetter.get_speaker(speaker_id)
        if not speaker or speaker.name == '':
            abort(404)
        form_elems = DataGetter.get_custom_form_elements(speaker.event_id)
        if not form_elems:
            flash(
                "Speaker and Session forms have been incorrectly configured for this event."
                " Session creation has been disabled", "danger")
            return redirect(
                url_for('.display_my_sessions_view',
                        event_id=speaker.event_id))
        speaker_form = json.loads(form_elems.speaker_form)
        event = DataGetter.get_event(speaker.event_id)
        return render_template(
            'gentelella/users/mysessions/mysession_speaker_edit.html',
            photo_delete_url=url_for('.avatar_delete',
                                     event_id=event.id,
                                     speaker_id=speaker.id),
            speaker_form=speaker_form,
            event=event,
            speaker=speaker)

    if request.method == 'POST':
        speaker = DataGetter.get_speaker(speaker_id)
        DataManager.edit_speaker(request, speaker)
        flash("The speaker has been updated successfully", "success")
        return redirect(
            url_for('.display_my_sessions_view', event_id=speaker.event_id))
示例#17
0
def add_session_media():
    if 'slides' in request.files and request.files['slides'].filename != '':
        url = DataManager.add_session_media(request, 'slides')
        return jsonify({
            'status': 'ok',
            'url': url
        }), 200

    if 'video' in request.files and request.files['video'].filename != '':
        url = DataManager.add_session_media(request, 'video')
        return jsonify({
            'status': 'ok',
            'url': url
        }), 200

    if 'audio' in request.files and request.files['audio'].filename != '':
        url = DataManager.add_session_media(request, 'audio')
        return jsonify({
            'status': 'ok',
            'url': url
        }), 200

    return jsonify({
            'status': 'ok'
        }), 200
示例#18
0
def create_event(name='TestEvent', creator_email=None):
    """Creates Event and returns its `id`.
    :param creator_email:
    :param name Name of Event
    """
    event = Event(name=name,
                  start_time=datetime(2016, 4, 8, 12, 30, 45),
                  end_time=datetime(2016, 4, 9, 12, 30, 45))
    if creator_email:
        event.creator = User.query.filter_by(email=creator_email).first()

    save_to_db(event, 'Event saved')

    copyright = Copyright(holder='copyright holder', event=event)
    save_to_db(copyright, "Copyright saved")

    if creator_email:
        # Add creator as Organizer
        data = {
            'user_email': creator_email,
            'user_role': ORGANIZER,
        }
        DataManager.add_role_to_event(data, event.id, record=False)

    return event.id
def create_default_user():
    print "Your login is 'super_admin'."
    email = raw_input("Enter email for super_admin    : ")
    _validate_email(email)
    password = getpass("Enter password for super_admin : ")
    _validate_password(password)
    DataManager.create_super_admin(email, password)
def user_role_invite(event_id, hash):
    """Accept User-Role invite for the event.
    """
    event = DataGetter.get_event(event_id)
    user = current_user
    role_invite = DataGetter.get_event_role_invite(event.id,
                                                   hash,
                                                   email=user.email)

    if role_invite:
        if role_invite.has_expired():
            delete_from_db(role_invite, 'Deleted RoleInvite')

            flash('Sorry, the invitation link has expired.', 'error')
            return redirect(url_for('.details_view', event_id=event.id))

        if user.has_role(event.id):
            flash('You have already been assigned a Role in the Event.',
                  'warning')
            return redirect(url_for('events.details_view', event_id=event_id))

        role = role_invite.role
        data = dict()
        data['user_email'] = role_invite.email
        data['user_role'] = role.name
        DataManager.add_role_to_event(data, event.id)

        # Delete Role Invite after it has been accepted
        delete_from_db(role_invite, 'Deleted RoleInvite')

        flash('You have been added as a %s' % role.title_name)
        return redirect(url_for('.details_view', event_id=event.id))
    else:
        abort(404)
    def initiate_order_payment(form):
        identifier = form['identifier']
        email = form['email']

        order = TicketingManager.get_and_set_expiry(identifier)

        if order:

            user = TicketingManager.get_or_create_user_by_email(email, form)
            order.user_id = user.id

            if order.amount > 0 \
                and (not order.paid_via
                     or (order.paid_via
                         and (order.paid_via == 'stripe'
                              or order.paid_via == 'paypal'))):

                country = form['country']
                address = form['address']
                city = form['city']
                state = form['state']
                zipcode = form['zipcode']
                order.address = address
                order.city = city
                order.state = state
                order.country = country
                order.zipcode = zipcode
                order.status = 'initialized'
            else:
                order.status = 'completed'
                order.completed_at = datetime.utcnow()
                if not order.paid_via:
                    order.paid_via = 'free'

            holders_firstnames = form.getlist('holders[firstname]')
            holders_lastnames = form.getlist('holders[lastname]')
            holders_ticket_ids = form.getlist('holders[ticket_id]')
            holders_emails = form.getlist('holders[email]')

            for i, firstname in enumerate(holders_firstnames):
                data = {
                    'firstname': firstname,
                    'lastname': holders_lastnames[i]
                }
                holder_user = TicketingManager.get_or_create_user_by_email(holders_emails[i], data)
                ticket_holder = TicketHolder(firstname=data['firstname'],
                                             lastname=data['lastname'],
                                             ticket_id=int(holders_ticket_ids[i]),
                                             email=holder_user.email, order_id=order.id)
                DataManager.add_attendee_role_to_event(holder_user, order.event_id)
                db.session.add(ticket_holder)

            # add attendee role to user
            DataManager.add_attendee_role_to_event(user, order.event_id)
            # save items
            save_to_db(order)
            return order
        else:
            return False
    def process_event_cfs(self, identifier, via_hash=False):
        if request.method == 'GET':
            event = get_published_event_or_abort(identifier)
            placeholder_images = DataGetter.get_event_default_images()
            custom_placeholder = DataGetter.get_custom_placeholders()
            if not event.has_session_speakers:
                abort(404)

            call_for_speakers = DataGetter.get_call_for_papers(
                event.id).first()
            accepted_sessions = DataGetter.get_sessions(event.id)

            if not call_for_speakers or (
                    not via_hash and call_for_speakers.privacy == 'private'):
                abort(404)

            form_elems = DataGetter.get_custom_form_elements(event.id)
            speaker_form = json.loads(form_elems.speaker_form)
            session_form = json.loads(form_elems.session_form)

            now = datetime.now()
            state = "now"
            if call_for_speakers.end_date < now:
                state = "past"
            elif call_for_speakers.start_date > now:
                state = "future"
            speakers = DataGetter.get_speakers(event.id).all()
            return self.render('/gentelella/guest/event/cfs_new.html',
                               event=event,
                               accepted_sessions=accepted_sessions,
                               speaker_form=speaker_form,
                               session_form=session_form,
                               call_for_speakers=call_for_speakers,
                               placeholder_images=placeholder_images,
                               state=state,
                               speakers=speakers,
                               via_hash=via_hash,
                               custom_placeholder=custom_placeholder)

        if request.method == 'POST':
            email = request.form['email']
            event = DataGetter.get_event_by_identifier(identifier)
            if not event.has_session_speakers:
                abort(404)
            DataManager.add_session_to_event(request, event.id)
            if login.current_user.is_authenticated:
                flash("Your session proposal has been submitted", "success")
                return redirect(
                    url_for('my_sessions.display_my_sessions_view',
                            event_id=event.id))
            else:
                flash(
                    Markup(
                        "Your session proposal has been submitted. Please login/register with <strong><u>"
                        + email + "</u></strong> to manage it."), "success")
                return redirect(
                    url_for(
                        'admin.login_view',
                        next=url_for('my_sessions.display_my_sessions_view')))
def create_default_user():
    print "Your login is 'super_admin'."
    email = raw_input("Enter email for super_admin    : ")
    _validate_email(email)
    getpass.os = eventlet.patcher.original('os')
    password = getpass.getpass("Enter password for super_admin : ")
    _validate_password(password)
    DataManager.create_super_admin(email, password)
def process_event_cfs(identifier, via_hash=False):
    if request.method == 'GET':
        event = get_published_event_or_abort(identifier)
        placeholder_images = DataGetter.get_event_default_images()
        if event.sub_topic:
            custom_placeholder = DataGetter.get_custom_placeholder_by_name(event.sub_topic)
        elif event.topic:
            custom_placeholder = DataGetter.get_custom_placeholder_by_name(event.topic)
        else:
            custom_placeholder = DataGetter.get_custom_placeholder_by_name('Other')
        if not event.has_session_speakers:
            abort(404)

        call_for_speakers = DataGetter.get_call_for_papers(event.id).first()

        if not call_for_speakers or (not via_hash and call_for_speakers.privacy == 'private'):
            abort(404)

        form_elems = DataGetter.get_custom_form_elements(event.id)
        speaker_form = json.loads(form_elems.speaker_form)
        session_form = json.loads(form_elems.session_form)

        now = datetime.now(pytz.timezone(event.timezone
                                                  if (event.timezone and event.timezone != '') else 'UTC'))
        start_date = pytz.timezone(event.timezone).localize(call_for_speakers.start_date)
        end_date = pytz.timezone(event.timezone).localize(call_for_speakers.end_date)
        state = "now"
        if end_date < now:
            state = "past"
        elif start_date > now:
            state = "future"
        speakers = DataGetter.get_speakers(event.id).all()
        user_speaker = DataGetter.get_speaker_by_email_event(login.current_user.email, event.id)
        accepted_sessions_count = get_count(DataGetter.get_sessions(event.id))
        return render_template('gentelella/guest/event/cfs_new_session.html',
                               event=event,
                               speaker_form=speaker_form,
                               user_speaker=user_speaker,
                               accepted_sessions_count=accepted_sessions_count,
                               session_form=session_form,
                               call_for_speakers=call_for_speakers,
                               placeholder_images=placeholder_images,
                               state=state,
                               speakers=speakers,
                               via_hash=via_hash,
                               custom_placeholder=custom_placeholder,
                               from_path="cfs")

    if request.method == 'POST':
        event = DataGetter.get_event_by_identifier(identifier)
        if not event.has_session_speakers:
            abort(404)
        if login.current_user.is_authenticated:
            DataManager.add_session_to_event(request, event.id, no_name=True)
            flash("Your session proposal has been submitted", "success")
            return redirect(url_for('my_sessions.display_my_sessions_view', event_id=event.id))

        return redirect(url_for('admin.login_view', next=url_for('my_sessions.display_my_sessions_view')))
def process_event_cfs(identifier, via_hash=False):
    if request.method == 'GET':
        event = get_published_event_or_abort(identifier)
        placeholder_images = DataGetter.get_event_default_images()
        if event.sub_topic:
            custom_placeholder = DataGetter.get_custom_placeholder_by_name(event.sub_topic)
        elif event.topic:
            custom_placeholder = DataGetter.get_custom_placeholder_by_name(event.topic)
        else:
            custom_placeholder = DataGetter.get_custom_placeholder_by_name('Other')
        if not event.has_session_speakers:
            abort(404)

        call_for_speakers = DataGetter.get_call_for_papers(event.id).first()

        if not call_for_speakers or (not via_hash and call_for_speakers.privacy == 'private'):
            abort(404)

        form_elems = DataGetter.get_custom_form_elements(event.id)
        speaker_form = json.loads(form_elems.speaker_form)
        session_form = json.loads(form_elems.session_form)

        now = datetime.now(pytz.timezone(event.timezone
                                                  if (event.timezone and event.timezone != '') else 'UTC'))
        start_date = pytz.timezone(event.timezone).localize(call_for_speakers.start_date)
        end_date = pytz.timezone(event.timezone).localize(call_for_speakers.end_date)
        state = "now"
        if end_date < now:
            state = "past"
        elif start_date > now:
            state = "future"
        speakers = DataGetter.get_speakers(event.id).all()
        user_speaker = DataGetter.get_speaker_by_email_event(login.current_user.email, event.id)
        accepted_sessions_count = get_count(DataGetter.get_sessions(event.id))
        return render_template('gentelella/guest/event/cfs_new_session.html',
                               event=event,
                               speaker_form=speaker_form,
                               user_speaker=user_speaker,
                               accepted_sessions_count=accepted_sessions_count,
                               session_form=session_form,
                               call_for_speakers=call_for_speakers,
                               placeholder_images=placeholder_images,
                               state=state,
                               speakers=speakers,
                               via_hash=via_hash,
                               custom_placeholder=custom_placeholder,
                               from_path="cfs")

    if request.method == 'POST':
        event = DataGetter.get_event_by_identifier(identifier)
        if not event.has_session_speakers:
            abort(404)
        if login.current_user.is_authenticated:
            DataManager.add_session_to_event(request, event.id, no_name=True)
            flash("Your session proposal has been submitted", "success")
            return redirect(url_for('my_sessions.display_my_sessions_view', event_id=event.id))

        return redirect(url_for('admin.login_view', next=url_for('my_sessions.display_my_sessions_view')))
def reject_session(event_id, session_id):
    session = get_session_or_throw(session_id)
    skip = request.args.get('skip')
    send_email = True
    if skip and skip == 'email':
        send_email = False
    DataManager.session_accept_reject(session, event_id, 'rejected',
                                      send_email)
    return redirect(url_for('.index_view', event_id=event_id))
def mark_as_read(notification_id):
    user = login.current_user
    notification = DataGetter.get_user_notification(notification_id)

    if notification and notification.user == user:
        DataManager.mark_user_notification_as_read(notification)
        return jsonify({'status': 'ok'})
    else:
        abort(404)
def create_custom_sys_role():
    if request.method == 'POST':
        role_name = request.form.get('role_name')
        sys_role = CustomSysRole.query.filter_by(name=role_name).first()
        if sys_role:
            flash('A System Role with similar name already exists. Please choose a different name.')
            return redirect(url_for('.index_view'))
        DataManager.create_custom_sys_role(request.form)
    return redirect(url_for('.index_view'))
def update_custom_sys_role():
    if request.method == 'POST':
        role_name = request.form.get('role_name')
        sys_role = CustomSysRole.query.filter_by(name=role_name).first()
        if not sys_role:
            flash('No such role exists.')
            return redirect(url_for('.index_view'))
        DataManager.update_custom_sys_role(request.form)
    return redirect(url_for('.index_view'))
示例#30
0
def contact_info_view(user_id):
    if request.method == 'POST':
        DataManager.update_user(request.form, int(user_id), contacts_only_update=True)
        flash("Your contact info has been updated.", "success")
        return redirect(url_for('.contact_info_view', user_id=user_id))
    user = DataGetter.get_user(int(user_id))
    user.admin_access = 1

    return render_template('gentelella/users/settings/pages/contact_info.html', user=user)
示例#31
0
def mark_as_read(notification_id):
    user = login.current_user
    notification = DataGetter.get_user_notification(notification_id)

    if notification and notification.user == user:
        DataManager.mark_user_notification_as_read(notification)
        return jsonify({'status': 'ok'})
    else:
        abort(404)
示例#32
0
 def update_custom_sys_role(self):
     if request.method == 'POST':
         role_name = request.form.get('role_name')
         sys_role = CustomSysRole.query.filter_by(name=role_name).first()
         if not sys_role:
             flash('No such role exists.')
             return redirect(url_for('.index_view'))
         DataManager.update_custom_sys_role(request.form)
     return redirect(url_for('.index_view'))
示例#33
0
def contact_info_view():
    user_id = login.current_user.id
    if request.method == 'POST':
        DataManager.update_user(request.form, int(user_id), contacts_only_update=True)
        flash("Your contact info has been updated.", "success")
        return redirect(url_for('.contact_info_view'))
    profile = DataGetter.get_user(int(user_id))

    return render_template('gentelella/users/settings/pages/contact_info.html', user=login.current_user)
def new_view(event_id, user_id, hash):
    invite = DataGetter.get_invite_by_user_id(user_id)
    event = DataGetter.get_event(event_id)
    if invite and invite.hash == hash:
        if request.method == 'POST':
            DataManager.add_session_to_event(request, event_id)
            return redirect(url_for('.index_view', event_id=event_id))
        return render_template('gentelella/admin/sessions/new.html',
                               event=event)
def reject_session(event_id, session_id):
    session = get_session_or_throw(session_id)
    skip = request.args.get('skip')
    send_email = True
    if skip and skip == 'email':
        send_email = False
    message = request.form.get('message', None) if request.form else None
    subject = request.form.get('subject', None) if request.form else None
    DataManager.session_accept_reject(session, event_id, 'rejected', send_email, message=message, subject=subject)
    return redirect(url_for('.index_view', event_id=event_id))
示例#36
0
    def contact_info_view(self):
        user_id = login.current_user.id
        if request.method == 'POST':
            url = ""
            DataManager.update_user(request.form, int(user_id), url, contacts_only_update=True)
            flash("Your contact info has been updated.", "success")
            return redirect(url_for('.contact_info_view'))
        profile = DataGetter.get_user(int(user_id))

        return self.render('/gentelella/admin/settings/pages/contact_info.html', user=login.current_user)
示例#37
0
def confirm_session(event_id, session_id):
    session = get_session_or_throw(session_id)
    skip = request.args.get('skip')
    send_email = True
    if skip and skip == 'email':
        send_email = False
    message = request.form.get('message', None) if request.form else None
    subject = request.form.get('subject', None) if request.form else None
    DataManager.session_accept_reject(session, event_id, 'confirmed', send_email, message=message, subject=subject)
    return redirect(url_for('.index_view', event_id=event_id))
示例#38
0
 def create_custom_sys_role(self):
     if request.method == 'POST':
         role_name = request.form.get('role_name')
         sys_role = CustomSysRole.query.filter_by(name=role_name).first()
         if sys_role:
             flash(
                 'A System Role with similar name already exists. Please choose a different name.'
             )
             return redirect(url_for('.index_view'))
         DataManager.create_custom_sys_role(request.form)
     return redirect(url_for('.index_view'))
 def test_add_event_to_trash(self):
     event = Event(name="event1",
                   start_time=datetime(2003, 8, 4, 12, 30, 45),
                   end_time=datetime(2003, 9, 4, 12, 30, 45),
                   in_trash=False)
     with app.test_request_context():
         save_to_db(event, "Event saved")
         DataManager.trash_event(1)
         url= url_for('events.index_view')
         rv = self.app.get(url)
         self.assertFalse('event1' in rv.data)
         self.assertEqual(event.in_trash, True)
示例#40
0
def edit_view(user_id=None):
    admin = None
    if not user_id:
        user_id = login.current_user.id
    else:
        admin = True
    if request.method == 'POST':
        DataManager.update_user(request.form, int(user_id))
        if admin:
            return redirect(url_for('sadmin_users.details_view', user_id=user_id))
        return redirect(url_for('.index_view'))
    return redirect(url_for('.index_view'))
示例#41
0
 def process_event_cfs(self, identifier):
     email = request.form['email']
     event = DataGetter.get_event_by_identifier(identifier)
     if not event.has_session_speakers:
         abort(404)
     DataManager.add_session_to_event(request, event.id)
     if login.current_user.is_authenticated:
         flash("Your session proposal has been submitted", "success")
         return redirect(url_for('my_sessions.display_my_sessions_view', event_id=event.id))
     else:
         flash(Markup("Your session proposal has been submitted. Please login/register with <strong><u>" + email + "</u></strong> to manage it."), "success")
         return redirect(url_for('admin.login_view', next=url_for('my_sessions.display_my_sessions_view')))
def edit_view(user_id=None):
    admin = None
    if not user_id:
        user_id = login.current_user.id
    else:
        admin = True
    if request.method == 'POST':
        DataManager.update_user(request.form, int(user_id))
        if admin:
            return redirect(url_for('sadmin_users.details_view', user_id=user_id))
        return redirect(url_for('.index_view'))
    return redirect(url_for('.index_view'))
    def test_notifications(self):
        with app.test_request_context():
            user = get_or_create_super_admin()
            notif = {
                'title': 'Test Notif Title',
                'message': 'Test Notif Message',
                'action': 'Testing Notifications'
            }
            DataManager.create_user_notification(user=user, **notif)

            rv = self.app.get(url_for('profile.notifications_view'))
            self.assertIn(notif['title'], rv.data, msg=rv.data)
            self.assertIn(notif['message'], rv.data, msg=rv.data)
    def test_add_event_to_trash(self):
        with app.test_request_context():
            event = Event(name="event1",
                          start_time=datetime(2003, 8, 4, 12, 30, 45),
                          end_time=datetime(2003, 9, 4, 12, 30, 45),
                          in_trash=False)

            save_to_db(event, "Event saved")
            DataManager.trash_event(1)
            url = url_for('events.index_view')
            rv = self.app.get(url)
            self.assertFalse('event1' in rv.data)
            self.assertEqual(event.in_trash, True)
    def test_add_event_to_trash(self):
        with app.test_request_context():
            event = Event(name="event1",
                          start_time=datetime(2003, 8, 4, 12, 30, 45),
                          end_time=datetime(2003, 9, 4, 12, 30, 45),
                          deleted_at=None)

            save_to_db(event, "Event saved")
            DataManager.trash_event(1)
            url = url_for('events.index_view')
            rv = self.app.get(url)
            self.assertFalse('event1' in rv.data)
            self.assertTrue(event.deleted_at is not None)
示例#46
0
    def test_notifications(self):
        with app.test_request_context():
            user = get_or_create_super_admin()
            notif = {
                'title': 'Test Notif Title',
                'message': 'Test Notif Message',
                'action': 'Testing Notifications'
            }
            DataManager.create_user_notification(user=user, **notif)

            rv = self.app.get(url_for('notifications.index_view'))
            self.assertIn(notif['title'], rv.data, msg=rv.data)
            self.assertIn(notif['message'], rv.data, msg=rv.data)
示例#47
0
def create_view(event_id):
    if request.method == 'POST':
        email = request.form['email']
        user = DataGetter.get_user_by_email(email)
        event = DataGetter.get_event(event_id)
        if user:
            DataManager.add_invite_to_event(user.id, event_id)
            hash = DataGetter.get_invite_by_user_id(user.id).hash
            link = url_for('event_sessions.new_view', event_id=event_id, user_id=user.id, hash=hash, _external=True)
            Helper.send_email_invitation(email, event.name, link)
            cfs_link = url_for('event_detail.display_event_cfs', identifier=event.identifier)
            Helper.send_notif_invite_papers(user, event.name, cfs_link, link)

    return redirect(url_for('events.details_view', event_id=event_id))
示例#48
0
def update_roles_view(user_id):
    user = DataGetter.get_user(user_id)
    user.is_admin = request.form.get('admin') == 'yes'
    save_to_db(user)

    custom_sys_roles = DataGetter.get_custom_sys_roles()
    for role in custom_sys_roles:
        field = request.form.get('custom_role-{}'.format(role.id))
        if field:
            DataManager.get_or_create_user_sys_role(user, role)
        else:
            DataManager.delete_user_sys_role(user, role)

    return redirect(url_for('.index_view'))
    def test_notification_read(self):
        with app.test_request_context():
            user = get_or_create_super_admin()
            notif = {
                'title': 'Test Notif Title',
                'message': 'Test Notif Message',
                'action': 'Testing Notifications'
            }
            DataManager.create_user_notification(user=user, **notif)

            notification = Notification.query.filter_by(user=user, **notif).first()

            rv = self.app.get(url_for('profile.mark_notification_as_read',
                                      notification_id=notification.id))

            self.assertEqual(notification.has_read, True, msg=rv.data)
示例#50
0
def initialize_db(credentials):
    with app.app_context():
        populate_data = True
        inspector = reflection.Inspector.from_engine(db.engine)
        table_name = 'events'
        table_names = inspector.get_table_names()
        if table_name not in table_names:
            try:
                db.create_all()
                stamp()
            except:
                populate_data = False
                print "Could not create tables. Either database does not exist or tables already created"
            if populate_data:
                credentials = credentials.split(":")
                DataManager.create_super_admin(credentials[0], credentials[1])
                populate()
示例#51
0
def update_roles_view(user_id):
    if current_user.is_super_admin:
        user = DataGetter.get_user(user_id)
        user.is_admin = request.form.get('admin') == 'yes'
        save_to_db(user)

        custom_sys_roles = DataGetter.get_custom_sys_roles()
        for role in custom_sys_roles:
            field = request.form.get('custom_role-{}'.format(role.id))
            if field:
                DataManager.get_or_create_user_sys_role(user, role)
            else:
                DataManager.delete_user_sys_role(user, role)

        return redirect(url_for('.index_view'))
    else:
        abort(403)
def add_speaker_view(event_id, session_id):
    event = DataGetter.get_event(event_id)
    if not event.has_session_speakers:
        return render_template('gentelella/users/events/info/enable_module.html', active_page='sessions',
                               title='Sessions', event=event)
    form_elems = DataGetter.get_custom_form_elements(event_id)
    if not form_elems:
        flash("Speaker form has been incorrectly configured for this event. Editing has been disabled", "danger")
        return redirect(url_for('.index_view', event_id=event_id))
    speaker_form = json.loads(form_elems.speaker_form)
    if request.method == 'GET':
        return render_template('gentelella/users/events/speakers/edit.html', event_id=event_id,
                               event=event, speaker_form=speaker_form)
    if request.method == 'POST':
        DataManager.add_speaker_to_session(request, event_id, session_id)
        flash("The speaker has been added to session")
        return redirect(url_for('.index_view', event_id=event_id))
def empty_trash():
    with app.app_context():
        events = Event.query.filter_by(in_trash=True)
        users = User.query.filter_by(in_trash=True)
        sessions = Session.query.filter_by(in_trash=True)
        for event in events:
            if datetime.now() - event.trash_date >= timedelta(days=30):
                DataManager.delete_event(event.id)

        for user in users:
            if datetime.now() - user.trash_date >= timedelta(days=30):
                transaction = transaction_class(Event)
                transaction.query.filter_by(user_id=user.id).delete()
                delete_from_db(user, "User deleted permanently")

        for session_ in sessions:
            if datetime.now() - session_.trash_date >= timedelta(days=30):
                delete_from_db(session_, "Session deleted permanently")
def edit_view(event_id, session_id):
    event = DataGetter.get_event(event_id)
    if not event.has_session_speakers:
        return render_template('gentelella/users/events/info/enable_module.html', active_page='sessions',
                               title='Sessions', event=event)

    session = get_session_or_throw(session_id)
    if request.method == 'POST':
        DataManager.edit_session(request, session)
        return redirect(url_for('.index_view', event_id=event_id))

    form_elems = DataGetter.get_custom_form_elements(event_id)
    if not form_elems:
        flash("Speaker and Session forms have been incorrectly configured for this event."
              " Session creation has been disabled", "danger")
        return redirect(url_for('.index_view', event_id=event_id))
    session_form = json.loads(form_elems.session_form)
    speakers = DataGetter.get_speakers(event_id).all()
    return render_template('gentelella/users/events/sessions/edit.html', session=session,
                           session_form=session_form, event=event, speakers=speakers)
示例#55
0
def user_role_invite_decline(event_id, hash):
    """Decline User-Role invite for the event.
    """
    event = DataGetter.get_event(event_id)
    user = current_user
    role_invite = DataGetter.get_event_role_invite(event.id, hash,
                                                   email=user.email)

    if role_invite:
        if role_invite.has_expired():
            delete_from_db(role_invite, 'Deleted RoleInvite')

            flash('Sorry, the invitation link has expired.', 'error')
            return redirect(url_for('.details_view', event_id=event.id))

        DataManager.decline_role_invite(role_invite)

        flash('You have declined the role invite.')
        return redirect(url_for('.details_view', event_id=event.id))
    else:
        abort(404)
def create_event(name='TestEvent', creator_email=None):
    """Creates Event and returns its `id`.
    :param name Name of Event
    """
    copyright = Copyright(holder='copyright holder')
    event = Event(name=name,
                  start_time=datetime(2016, 4, 8, 12, 30, 45),
                  end_time=datetime(2016, 4, 9, 12, 30, 45),
                  copyright=copyright)
    if creator_email:
        event.creator = User.query.filter_by(email=creator_email).first()

    save_to_db(event, 'Event saved')

    if creator_email:
        # Add creator as Organizer
        data = {
            'user_email': creator_email,
            'user_role': ORGANIZER,
        }
        DataManager.add_role_to_event(data, event.id, record=False)

    return event.id