def edit_session(form, session, slide_file, audio_file, video_file):

        event_id = session.event_id

        form_state = form.get('state', 'draft')

        if slide_file != "":
            slide_url = upload(slide_file,
                               'events/%d/session/%d/slide' % (int(event_id), int(session.id)))
            session.slides = slide_url

        if audio_file != "":
            audio_url = upload(audio_file,
                               'events/%d/session/%d/audio' % (int(event_id), int(session.id)))
            session.audio = audio_url
        if video_file != "":
            video_url = upload(video_file,
                               'events/%d/session/%d/video' % (int(event_id), int(session.id)))
            session.video = video_url

        if form_state == 'pending' and session.state != 'pending' and session.state != 'accepted' and session.state != 'rejected':
            link = url_for('event_sessions.session_display_view',
                           event_id=event_id, session_id=session.id, _external=True)
            organizers = DataGetter.get_user_event_roles_by_role_name(event_id, 'organizer')
            for organizer in organizers:
                send_new_session_organizer(organizer.user.email, session.event.name, link)
            session.state = form_state

        session.title = form.get('title', '')
        session.subtitle = form.get('subtitle', '')
        session.long_abstract = form.get('long_abstract', '')
        session.short_abstract = form.get('short_abstract', '')

        save_to_db(session, 'Session Updated')
 def edit_view(self, user_id=None):
     if not user_id:
         user_id = login.current_user.id
     if request.method == 'POST':
         avatar_img = request.files['avatar']
         url = upload(avatar_img, 'users/%d/avatar' % int(user_id))
         profile = DataManager.update_user(request.form, int(user_id), url)
         return redirect(url_for('.index_view'))
     profile = DataGetter.get_user(int(user_id))
     return self.render('/gentelella/admin/profile/edit.html', profile=profile)
示例#3
0
 def edit_view(self, user_id=None):
     if not user_id:
         user_id = login.current_user.id
     if request.method == 'POST':
         avatar_img = request.files['avatar']
         url = upload(avatar_img, 'users/%d/avatar' % int(user_id))
         profile = DataManager.update_user(request.form, int(user_id), url)
         return redirect(url_for('.index_view'))
     profile = DataGetter.get_user(int(user_id))
     return self.render('/gentelella/admin/profile/edit.html',
                        profile=profile)
    def edit_session(form, session, slide_file, audio_file, video_file):

        event_id = session.event_id

        form_state = form.get('state', 'draft')

        if slide_file != "":
            slide_url = upload(
                slide_file, 'events/%d/session/%d/slide' %
                (int(event_id), int(session.id)))
            session.slides = slide_url

        if audio_file != "":
            audio_url = upload(
                audio_file, 'events/%d/session/%d/audio' %
                (int(event_id), int(session.id)))
            session.audio = audio_url
        if video_file != "":
            video_url = upload(
                video_file, 'events/%d/session/%d/video' %
                (int(event_id), int(session.id)))
            session.video = video_url

        if form_state == 'pending' and session.state != 'pending' and session.state != 'accepted' and session.state != 'rejected':
            link = url_for('event_sessions.session_display_view',
                           event_id=event_id,
                           session_id=session.id,
                           _external=True)
            organizers = DataGetter.get_user_event_roles_by_role_name(
                event_id, 'organizer')
            for organizer in organizers:
                send_new_session_organizer(organizer.user.email,
                                           session.event.name, link)
            session.state = form_state

        session.title = form.get('title', '')
        session.subtitle = form.get('subtitle', '')
        session.long_abstract = form.get('long_abstract', '')
        session.short_abstract = form.get('short_abstract', '')

        save_to_db(session, 'Session Updated')
    def create_event(form, img_files):
        """
        Event will be saved to database with proper Event id
        :param form: view data form
        """
        event = Event(name=form['name'],
                      email='dsads',
                      color='#f5f5f5',
                      logo=form['logo'],
                      start_time=datetime.strptime(form['start_date'] + ' ' + form['start_time'], '%m/%d/%Y %H:%M'),
                      end_time=datetime.strptime(form['start_date'] + ' ' + form['end_time'], '%m/%d/%Y %H:%M'),
                      latitude=form['latitude'],
                      longitude=form['longitude'],
                      location_name=form['location_name'],
                      description=form['description'],
                      event_url=form['event_url'],
                      background_url=form['background_url'],
                      type=form['event_type'],
                      topic=form['topic'],
                      privacy=form.get('privacy', 'public'),
                      ticket_url=form['ticket_url'],
                      organizer_name=form['organizer_name'],
                      organizer_description=form['organizer_description'],
                      creator=login.current_user)

        state = form.get('state', None)
        if state and ((state == u'Published' and not string_empty(event.location_name)) or state != u'Published'):
            event.state = state

        if event.start_time <= event.end_time:
            save_to_db(event, "Event Saved")
            role = Role.query.filter_by(name=ORGANIZER).first()
            db.session.add(event)
            db.session.flush()
            db.session.refresh(event)

            session_type_names = form.getlist('session_type[name]')
            session_type_length = form.getlist('session_type[length]')

            social_link_name = form.getlist('social[name]')
            social_link_link = form.getlist('social[link]')

            track_name = form.getlist('tracks[name]')
            track_color = form.getlist('tracks[color]')

            room_name = form.getlist('rooms[name]')
            room_color = form.getlist('rooms[color]')

            sponsor_name = form.getlist('sponsors[name]')
            sponsor_url = form.getlist('sponsors[url]')
            sponsor_level = form.getlist('sponsors[level]')
            sponsor_description = form.getlist('sponsors[description]')
            sponsor_logo_url = []

            custom_forms_name = form.getlist('custom_form[name]')
            custom_forms_value = form.getlist('custom_form[value]')


            for index, name in enumerate(session_type_names):
                if not string_empty(name):
                    session_type = SessionType(name=name, length=session_type_length[index], event_id=event.id)
                    db.session.add(session_type)

            for index, name in enumerate(social_link_name):
                if not string_empty(social_link_link[index]):
                    social_link = SocialLink(name=name, link=social_link_link[index], event_id=event.id)
                    db.session.add(social_link)

            for index, name in enumerate(track_name):
                track = Track(name=name, description="", track_image_url="", color=track_color[index],
                              event_id=event.id)
                db.session.add(track)

            for index, name in enumerate(room_name):
                if not string_empty(name):
                    room = Microlocation(name=name, event_id=event.id)
                    db.session.add(room)

            for index, name in enumerate(sponsor_name):
                if not string_empty(name):
                    sponsor = Sponsor(name=name, url=sponsor_url[index],
                                      level=sponsor_level[index], description=sponsor_description[index], event_id=event.id)
                    save_to_db(sponsor, "Sponsor created")
                    img_url = upload(img_files[index], 'events/%d/sponsor/%d/image' % (int(event.id), int(sponsor.id)))
                    sponsor_logo_url.append(img_url)
                    sponsor.logo = sponsor_logo_url[index]
                    save_to_db(sponsor, "Sponsor updated")

            session_form = ""
            speaker_form = ""
            for index, name in enumerate(custom_forms_name):
                print name
                if name == "session_form":
                    session_form = custom_forms_value[index]
                elif name == "speaker_form":
                    speaker_form = custom_forms_value[index]

            custom_form = CustomForms(session_form=session_form, speaker_form=speaker_form, event_id=event.id)
            db.session.add(custom_form)

            if form.get('call_for_speakers_state', u'off') == u'on':
                call_for_speakers = CallForPaper(announcement=form['announcement'],
                                                 start_date=datetime.strptime(form['cfs_start_date'], '%m/%d/%Y'),
                                                 end_date=datetime.strptime(form['cfs_end_date'], '%m/%d/%Y'),
                                                 event_id=event.id)
                save_to_db(call_for_speakers, "Call for speakers saved")

            uer = UsersEventsRoles(login.current_user, event, role)
            if save_to_db(uer, "Event saved"):
                return event
        else:
            raise ValidationError("start date greater than end date")
    def add_session_to_event(form, event_id, speaker_img_file, slide_file, audio_file, video_file, state=None):
        """
        Session will be saved to database with proper Event id
        :param speaker_img_file:
        :param state:
        :param form: view data form
        :param event_id: Session belongs to Event by event id
        """
        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', ''),
                              state=state)

        speaker = Speaker.query.filter_by(email=form.get('email', '')).filter_by(event_id=event_id).first()
        if not speaker:
            speaker = Speaker(name=form.get('name', ''),
                              short_biography=form.get('short_biography', ''),
                              email=form.get('email', ''),
                              website=form.get('website', ''),
                              event_id=event_id,
                              twitter=form.get('twitter', ''),
                              facebook=form.get('facebook', ''),
                              github=form.get('github', ''),
                              linkedin=form.get('linkedin', ''),
                              organisation=form.get('organisation', ''),
                              position=form.get('position', ''),
                              country=form.get('country', ''),
                              user=login.current_user if login and login.current_user.is_authenticated else None)

        new_session.speakers.append(speaker)
        save_to_db(new_session, "Session saved")

        if state == 'pending':
            link = url_for('event_sessions.session_display_view',
                           event_id=event.id, session_id=new_session.id, _external=True)
            organizers = DataGetter.get_user_event_roles_by_role_name(event.id, 'organizer')
            for organizer in organizers:
                send_new_session_organizer(organizer.user.email, event.name, link)

        slide_url = ""
        if slide_file != "":
            slide_url = upload(slide_file,
                               'events/%d/session/%d/slide' % (int(event_id), int(new_session.id)))
        audio_url = ""
        if audio_file != "":
            audio_url = upload(audio_file,
                               'events/%d/session/%d/audio' % (int(event_id), int(new_session.id)))
        video_url = ""
        if video_file != "":
            video_url = upload(video_file,
                               'events/%d/session/%d/video' % (int(event_id), int(new_session.id)))
        speaker_img = ""
        if speaker_img_file != "":
            speaker_img = upload(speaker_img_file,
                                 'events/%d/speaker/%d/photo' % (int(event_id), int(speaker.id)))

        speaker.photo = speaker_img
        new_session.audio = audio_url
        new_session.video = video_url
        new_session.slides = slide_url
        save_to_db(new_session, "Session saved")
        save_to_db(speaker, "Speaker saved")
        update_version(event_id, False, "speakers_ver")
        update_version(event_id, False, "session_ver")

        invite_emails = form.getlist("speakers[email]")
        for index, email in enumerate(invite_emails):
            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)
    def create_event(form, img_files):
        """
        Event will be saved to database with proper Event id
        :param form: view data form
        """
        event = Event(name=form['name'],
                      email='dsads',
                      color='#f5f5f5',
                      logo=form['logo'],
                      start_time=datetime.strptime(
                          form['start_date'] + ' ' + form['start_time'],
                          '%m/%d/%Y %H:%M'),
                      end_time=datetime.strptime(
                          form['start_date'] + ' ' + form['end_time'],
                          '%m/%d/%Y %H:%M'),
                      latitude=form['latitude'],
                      longitude=form['longitude'],
                      location_name=form['location_name'],
                      description=form['description'],
                      event_url=form['event_url'],
                      background_url=form['background_url'],
                      type=form['event_type'],
                      topic=form['topic'],
                      privacy=form.get('privacy', 'public'),
                      ticket_url=form['ticket_url'],
                      organizer_name=form['organizer_name'],
                      organizer_description=form['organizer_description'],
                      creator=login.current_user)

        state = form.get('state', None)
        if state and (
            (state == u'Published' and not string_empty(event.location_name))
                or state != u'Published'):
            event.state = state

        if event.start_time <= event.end_time:
            save_to_db(event, "Event Saved")
            role = Role.query.filter_by(name=ORGANIZER).first()
            db.session.add(event)
            db.session.flush()
            db.session.refresh(event)

            session_type_names = form.getlist('session_type[name]')
            session_type_length = form.getlist('session_type[length]')

            social_link_name = form.getlist('social[name]')
            social_link_link = form.getlist('social[link]')

            track_name = form.getlist('tracks[name]')
            track_color = form.getlist('tracks[color]')

            room_name = form.getlist('rooms[name]')
            room_color = form.getlist('rooms[color]')

            sponsor_name = form.getlist('sponsors[name]')
            sponsor_url = form.getlist('sponsors[url]')
            sponsor_level = form.getlist('sponsors[level]')
            sponsor_description = form.getlist('sponsors[description]')
            sponsor_logo_url = []

            custom_forms_name = form.getlist('custom_form[name]')
            custom_forms_value = form.getlist('custom_form[value]')

            for index, name in enumerate(session_type_names):
                if not string_empty(name):
                    session_type = SessionType(
                        name=name,
                        length=session_type_length[index],
                        event_id=event.id)
                    db.session.add(session_type)

            for index, name in enumerate(social_link_name):
                if not string_empty(social_link_link[index]):
                    social_link = SocialLink(name=name,
                                             link=social_link_link[index],
                                             event_id=event.id)
                    db.session.add(social_link)

            for index, name in enumerate(track_name):
                track = Track(name=name,
                              description="",
                              track_image_url="",
                              color=track_color[index],
                              event_id=event.id)
                db.session.add(track)

            for index, name in enumerate(room_name):
                if not string_empty(name):
                    room = Microlocation(name=name, event_id=event.id)
                    db.session.add(room)

            for index, name in enumerate(sponsor_name):
                if not string_empty(name):
                    sponsor = Sponsor(name=name,
                                      url=sponsor_url[index],
                                      level=sponsor_level[index],
                                      description=sponsor_description[index],
                                      event_id=event.id)
                    save_to_db(sponsor, "Sponsor created")
                    img_url = upload(
                        img_files[index], 'events/%d/sponsor/%d/image' %
                        (int(event.id), int(sponsor.id)))
                    sponsor_logo_url.append(img_url)
                    sponsor.logo = sponsor_logo_url[index]
                    save_to_db(sponsor, "Sponsor updated")

            session_form = ""
            speaker_form = ""
            for index, name in enumerate(custom_forms_name):
                print name
                if name == "session_form":
                    session_form = custom_forms_value[index]
                elif name == "speaker_form":
                    speaker_form = custom_forms_value[index]

            custom_form = CustomForms(session_form=session_form,
                                      speaker_form=speaker_form,
                                      event_id=event.id)
            db.session.add(custom_form)

            if form.get('call_for_speakers_state', u'off') == u'on':
                call_for_speakers = CallForPaper(
                    announcement=form['announcement'],
                    start_date=datetime.strptime(form['cfs_start_date'],
                                                 '%m/%d/%Y'),
                    end_date=datetime.strptime(form['cfs_end_date'],
                                               '%m/%d/%Y'),
                    event_id=event.id)
                save_to_db(call_for_speakers, "Call for speakers saved")

            uer = UsersEventsRoles(login.current_user, event, role)
            if save_to_db(uer, "Event saved"):
                return event
        else:
            raise ValidationError("start date greater than end date")
    def add_session_to_event(form,
                             event_id,
                             speaker_img_file,
                             slide_file,
                             audio_file,
                             video_file,
                             state=None):
        """
        Session will be saved to database with proper Event id
        :param speaker_img_file:
        :param state:
        :param form: view data form
        :param event_id: Session belongs to Event by event id
        """
        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', ''),
                              state=state)

        speaker = Speaker.query.filter_by(
            email=form.get('email', '')).filter_by(event_id=event_id).first()
        if not speaker:
            speaker = Speaker(
                name=form.get('name', ''),
                short_biography=form.get('short_biography', ''),
                email=form.get('email', ''),
                website=form.get('website', ''),
                event_id=event_id,
                twitter=form.get('twitter', ''),
                facebook=form.get('facebook', ''),
                github=form.get('github', ''),
                linkedin=form.get('linkedin', ''),
                organisation=form.get('organisation', ''),
                position=form.get('position', ''),
                country=form.get('country', ''),
                user=login.current_user
                if login and login.current_user.is_authenticated else None)

        new_session.speakers.append(speaker)
        save_to_db(new_session, "Session saved")

        if state == 'pending':
            link = url_for('event_sessions.session_display_view',
                           event_id=event.id,
                           session_id=new_session.id,
                           _external=True)
            organizers = DataGetter.get_user_event_roles_by_role_name(
                event.id, 'organizer')
            for organizer in organizers:
                send_new_session_organizer(organizer.user.email, event.name,
                                           link)

        slide_url = ""
        if slide_file != "":
            slide_url = upload(
                slide_file, 'events/%d/session/%d/slide' %
                (int(event_id), int(new_session.id)))
        audio_url = ""
        if audio_file != "":
            audio_url = upload(
                audio_file, 'events/%d/session/%d/audio' %
                (int(event_id), int(new_session.id)))
        video_url = ""
        if video_file != "":
            video_url = upload(
                video_file, 'events/%d/session/%d/video' %
                (int(event_id), int(new_session.id)))
        speaker_img = ""
        if speaker_img_file != "":
            speaker_img = upload(
                speaker_img_file, 'events/%d/speaker/%d/photo' %
                (int(event_id), int(speaker.id)))

        speaker.photo = speaker_img
        new_session.audio = audio_url
        new_session.video = video_url
        new_session.slides = slide_url
        save_to_db(new_session, "Session saved")
        save_to_db(speaker, "Speaker saved")
        update_version(event_id, False, "speakers_ver")
        update_version(event_id, False, "session_ver")

        invite_emails = form.getlist("speakers[email]")
        for index, email in enumerate(invite_emails):
            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)