示例#1
0
 def add_invite_to_event(user_id, event_id):
     """
     Invite will be saved to database with proper Event id and User id
     :param user_id: Invite belongs to User by user id
     :param event_id: Invite belongs to Event by event id
     """
     new_invite = Invite(user_id=user_id, event_id=event_id)
     hash = random.getrandbits(128)
     new_invite.hash = "%032x" % hash
     save_to_db(new_invite, "Invite saved")
     record_activity('invite_user', event_id=event_id, user_id=user_id)
示例#2
0
 def add_invite_to_event(user_id, event_id):
     """
     Invite will be saved to database with proper Event id and User id
     :param user_id: Invite belongs to User by user id
     :param event_id: Invite belongs to Event by event id
     """
     new_invite = Invite(user_id=user_id,
                         event_id=event_id)
     hash = random.getrandbits(128)
     new_invite.hash = "%032x" % hash
     save_to_db(new_invite, "Invite saved")
     record_activity('invite_user', event_id=event_id, user_id=user_id)
示例#3
0
def invitefirend():
    if session.get("id") is None:
        return redirect("/user/login")
    name2 = session.get("name")

    if request.method == "GET":

        return render_template(
            'student_templates/choosefriend.html',
            name=name2,
        )
    else:
        name = request.form.get("name")

        student = Student.query.filter_by(name=name).first()
        if student is None:
            return render_template('student_templates/voteleader.html',
                                   message="该学生不存在",
                                   name=name2)

        member = Member.query.filter(Member.studentId == student.id).first()
        if member is not None:
            return render_template('student_templates/voteleader.html',
                                   message="该学生已经加入小组,不能邀请",
                                   name=name2)
        member = Member.query.filter(
            Member.studentId == session.get("id")).first()

        with db.auto_commit():
            invite = Invite()
            invite.inviteeId = session.get("id")
            invite.inviteId = student.id
            invite.teamId = member.teamId
            db.session.add(invite)
        return render_template('student_templates/voteleader.html',
                               message="已经发送邀请",
                               name=name2)
示例#4
0
    def add_session_to_event(request, event_id, state=None, use_current_user=True):
        """
        Session will be saved to database with proper Event id
        :param use_current_user:
        :param state:
        :param request: The request
        :param event_id: Session belongs to Event by event id
        """
        form = request.form
        slide_temp_url = form.get('slides_url')
        video_temp_url = form.get('video_url')
        audio_temp_url = form.get('audio_url')
        slide_file = ''
        video_file = ''
        audio_file = ''

        if slide_temp_url:
            slide_file = UploadedFile(get_path_of_temp_url(slide_temp_url), slide_temp_url.rsplit('/', 1)[1])

        if video_temp_url:
            video_file = UploadedFile(get_path_of_temp_url(video_temp_url), video_temp_url.rsplit('/', 1)[1])

        if audio_temp_url:
            audio_file = UploadedFile(get_path_of_temp_url(audio_temp_url), audio_temp_url.rsplit('/', 1)[1])

        if not state:
            state = form.get('state', 'draft')

        event = DataGetter.get_event(event_id)

        new_session = Session(title=form.get('title', ''),
                              subtitle=form.get('subtitle', ''),
                              long_abstract=form.get('long_abstract', ''),
                              start_time=event.start_time,
                              end_time=event.start_time + timedelta(hours=1),
                              event_id=event_id,
                              short_abstract=form.get('short_abstract', ''),
                              level=form.get('level', ''),
                              comments=form.get('comments', ''),
                              language=form.get('language', ''),
                              state=state)

        if form.get('track', None) != "":
            new_session.track_id = form.get('track', None)

        if form.get('session_type', None) != "":
            new_session.session_type_id = form.get('session_type', None)

        speaker = Speaker.query.filter_by(email=form.get('email', '')).filter_by(event_id=event_id).first()
        speaker = save_speaker(
            request,
            event_id=event_id,
            speaker=speaker,
            user=login.current_user if use_current_user else None
        )

        new_session.speakers.append(speaker)

        save_to_db(new_session, "Session saved")

        if state == 'pending':
            trigger_new_session_notifications(new_session.id, event=event)

        if slide_temp_url != "" and slide_file:
            slide_url = upload(
                slide_file,
                UPLOAD_PATHS['sessions']['slides'].format(
                    event_id=int(event_id), id=int(new_session.id)
                ))
            new_session.slides = slide_url
        if audio_temp_url != "" and audio_file:
            audio_url = upload(
                audio_file,
                UPLOAD_PATHS['sessions']['audio'].format(
                    event_id=int(event_id), id=int(new_session.id)
                ))
            new_session.audio = audio_url
        if video_temp_url != "" and video_file:
            video_url = upload(
                video_file,
                UPLOAD_PATHS['sessions']['video'].format(
                    event_id=int(event_id), id=int(new_session.id)
                ))
            new_session.video = video_url

        record_activity('create_session', session=new_session, event_id=event_id)
        update_version(event_id, False, 'sessions_ver')

        invite_emails = form.getlist("speakers[email]")
        for index, email in enumerate(invite_emails):
            if not string_empty(email):
                new_invite = Invite(event_id=event_id, session_id=new_session.id)
                hash = random.getrandbits(128)
                new_invite.hash = "%032x" % hash
                save_to_db(new_invite, "Invite saved")

                link = url_for('event_sessions.invited_view', session_id=new_session.id, event_id=event_id,
                               _external=True)
                Helper.send_email_invitation(email, new_session.title, link)
                # If a user is registered by the email, send a notification as well
                user = DataGetter.get_user_by_email(email, no_flash=True)
                if user:
                    cfs_link = url_for('event_detail.display_event_cfs', identifier=event.identifier)
                    Helper.send_notif_invite_papers(user, event.name, cfs_link, link)
示例#5
0
    def add_session_to_event(request, event_id, state=None, use_current_user=True, no_name=False):
        """
        Session will be saved to database with proper Event id
        :param use_current_user:
        :param state:
        :param request: The request
        :param event_id: Session belongs to Event by event id
        """
        form = request.form
        slide_temp_url = form.get('slides_url')
        video_temp_url = form.get('video_url')
        audio_temp_url = form.get('audio_url')
        slide_file = ''
        video_file = ''
        audio_file = ''

        if slide_temp_url:
            slide_file = UploadedFile(get_path_of_temp_url(slide_temp_url), slide_temp_url.rsplit('/', 1)[1])

        if video_temp_url:
            video_file = UploadedFile(get_path_of_temp_url(video_temp_url), video_temp_url.rsplit('/', 1)[1])

        if audio_temp_url:
            audio_file = UploadedFile(get_path_of_temp_url(audio_temp_url), audio_temp_url.rsplit('/', 1)[1])

        if not state:
            state = form.get('state', 'draft')

        event = DataGetter.get_event(event_id)

        new_session = Session(title=form.get('title', ''),
                              subtitle=form.get('subtitle', ''),
                              long_abstract=form.get('long_abstract', ''),
                              start_time=event.start_time,
                              end_time=event.start_time + timedelta(hours=1),
                              event_id=event_id,
                              short_abstract=form.get('short_abstract', ''),
                              level=form.get('level', ''),
                              comments=form.get('comments', ''),
                              language=form.get('language', ''),
                              state=state)

        if form.get('track', None) != "":
            new_session.track_id = form.get('track', None)

        if form.get('session_type', None) != "":
            new_session.session_type_id = form.get('session_type', None)

        if form.get('email', '') != '':
            speaker = Speaker.query.filter_by(email=form.get('email', '')).filter_by(event_id=event_id).first()
            speaker = save_speaker(
                request,
                event_id=event_id,
                speaker=speaker,
                user=login.current_user if use_current_user else None,
                no_name=no_name
            )

            new_session.speakers.append(speaker)

        save_to_db(new_session, "Session saved")

        if state == 'pending':
            trigger_new_session_notifications(new_session.id, event=event)

        if slide_temp_url != "" and slide_file:
            slide_url = upload(
                slide_file,
                UPLOAD_PATHS['sessions']['slides'].format(
                    event_id=int(event_id), id=int(new_session.id)
                ))
            new_session.slides = slide_url
        if audio_temp_url != "" and audio_file:
            audio_url = upload(
                audio_file,
                UPLOAD_PATHS['sessions']['audio'].format(
                    event_id=int(event_id), id=int(new_session.id)
                ))
            new_session.audio = audio_url
        if video_temp_url != "" and video_file:
            video_url = upload(
                video_file,
                UPLOAD_PATHS['sessions']['video'].format(
                    event_id=int(event_id), id=int(new_session.id)
                ))
            new_session.video = video_url
        record_activity('create_session', session=new_session, event_id=event_id)
        update_version(event_id, False, 'sessions_ver')

        invite_emails = form.getlist("speakers[email]")
        for index, email in enumerate(invite_emails):
            if not string_empty(email):
                new_invite = Invite(event_id=event_id, session_id=new_session.id)
                hash = random.getrandbits(128)
                new_invite.hash = "%032x" % hash
                save_to_db(new_invite, "Invite saved")

                link = url_for('event_sessions.invited_view', session_id=new_session.id, event_id=event_id,
                               _external=True)
                Helper.send_email_invitation(email, new_session.title, link)
                # If a user is registered by the email, send a notification as well
                user = DataGetter.get_user_by_email(email, no_flash=True)
                if user:
                    cfs_link = url_for('event_detail.display_event_cfs', identifier=event.identifier)
                    Helper.send_notif_invite_papers(user, event.name, cfs_link, link)