def locations():
    names = []
    for event in DataGetter.get_all_live_events():
        if not string_empty(event.location_name) and not string_empty(event.latitude) and not string_empty(event.longitude):
            response = requests.get("https://maps.googleapis.com/maps/api/geocode/json?latlng=" + str(event.latitude) + "," + str(
                event.longitude)).json()
            if response['status'] == u'OK':
                for addr in response['results'][0]['address_components']:
                    if addr['types'] == ['locality', 'political']:
                        names.append(addr['short_name'])

    cnt = Counter()
    for location in names:
        cnt[location] += 1
    return dict(locations=[v for v, k in cnt.most_common()][:10])
Ejemplo n.º 2
0
    def create_view(self,):
        if request.method == 'POST':
            img_files = []
            imd = ImmutableMultiDict(request.files)
            if 'sponsors[logo]' in imd and request.files['sponsors[logo]'].filename != "":
                for img_file in imd.getlist('sponsors[logo]'):
                    img_files.append(img_file)
            event = DataManager.create_event(request.form, img_files)
            if request.form.get('state', u'Draft') == u'Published' and string_empty(event.location_name):
                flash(
                    "Your event was saved. To publish your event please review the highlighted fields below.",
                    "warning")
                return redirect(url_for(
                    '.edit_view', event_id=event.id) + "#step=location_name")
            if event:
                return redirect(url_for('.details_view', event_id=event.id))
            return redirect(url_for('.index_view'))

        return self.render(
            '/gentelella/admin/event/new/new.html',
            start_date=datetime.datetime.now() + datetime.timedelta(days=10),
            event_types=DataGetter.get_event_types(),
            event_licences=DataGetter.get_event_licences(),
            event_topics=DataGetter.get_event_topics(),
            event_sub_topics=DataGetter.get_event_subtopics(),
            timezones=DataGetter.get_all_timezones())
    def create_view(self, ):
        if request.method == 'POST':
            img_files = []
            imd = ImmutableMultiDict(request.files)
            if 'sponsors[logo]' in imd and request.files[
                    'sponsors[logo]'].filename != "":
                for img_file in imd.getlist('sponsors[logo]'):
                    img_files.append(img_file)
            event = DataManager.create_event(request.form, img_files)
            if request.form.get('state',
                                u'Draft') == u'Published' and string_empty(
                                    event.location_name):
                flash(
                    "Your event was saved. To publish your event please review the highlighted fields below.",
                    "warning")
                return redirect(
                    url_for('.edit_view', event_id=event.id) +
                    "#step=location_name")
            if event:
                return redirect(url_for('.details_view', event_id=event.id))
            return redirect(url_for('.index_view'))

        return self.render('/gentelella/admin/event/new/new.html',
                           start_date=datetime.datetime.now() +
                           datetime.timedelta(days=10),
                           event_types=DataGetter.get_event_types(),
                           event_topics=DataGetter.get_event_topics(),
                           timezones=DataGetter.get_all_timezones())
def locations():
    names = []
    for event in DataGetter.get_all_live_events():
        if not string_empty(event.location_name) and not string_empty(
                event.latitude) and not string_empty(event.longitude):
            response = requests.get(
                "https://maps.googleapis.com/maps/api/geocode/json?latlng=" +
                str(event.latitude) + "," + str(event.longitude)).json()
            if response['status'] == u'OK':
                for addr in response['results'][0]['address_components']:
                    if addr['types'] == ['locality', 'political']:
                        names.append(addr['short_name'])

    cnt = Counter()
    for location in names:
        cnt[location] += 1
    return dict(locations=[v for v, k in cnt.most_common()][:10])
Ejemplo n.º 5
0
 def publish_event(self, event_id):
     event = DataGetter.get_event(event_id)
     if string_empty(event.location_name):
         flash("Your event was saved. To publish your event please review the highlighted fields below.", "warning")
         return redirect(url_for('.edit_view', event_id=event.id) + "#step=location_name")
     event.state = 'Published'
     save_to_db(event, 'Event Published')
     flash("Your event has been published.", "success")
     return redirect(url_for('.details_view', event_id=event_id))
Ejemplo n.º 6
0
    def edit_view(self, event_id):
        event = DataGetter.get_event(event_id)
        session_types = DataGetter.get_session_types_by_event_id(
            event_id).all()
        tracks = DataGetter.get_tracks(event_id).all()
        social_links = DataGetter.get_social_links_by_event_id(event_id)
        microlocations = DataGetter.get_microlocations(event_id).all()
        call_for_speakers = DataGetter.get_call_for_papers(event_id).first()
        sponsors = DataGetter.get_sponsors(event_id)
        custom_forms = DataGetter.get_custom_form_elements(event_id).first()
        speaker_form = json.loads(custom_forms.speaker_form)
        session_form = json.loads(custom_forms.session_form)

        preselect = []
        required = []
        for session_field in session_form:
            if session_form[session_field]['include'] == 1:
                preselect.append(session_field)
                if session_form[session_field]['require'] == 1:
                    required.append(session_field)
        for speaker_field in speaker_form:
            if speaker_form[speaker_field]['include'] == 1:
                preselect.append(speaker_field)
                if speaker_form[speaker_field]['require'] == 1:
                    required.append(speaker_field)
        print preselect

        if request.method == 'GET':
            return self.render('/gentelella/admin/event/edit/edit.html',
                               event=event,
                               session_types=session_types,
                               tracks=tracks,
                               social_links=social_links,
                               microlocations=microlocations,
                               call_for_speakers=call_for_speakers,
                               sponsors=sponsors,
                               event_types=DataGetter.get_event_types(),
                               event_topics=DataGetter.get_event_topics(),
                               preselect=preselect,
                               required=required)
        if request.method == "POST":
            event = DataManager.edit_event(request, event_id, event,
                                           session_types, tracks, social_links,
                                           microlocations, call_for_speakers,
                                           sponsors, custom_forms)
            if request.form.get('state',
                                u'Draft') == u'Published' and string_empty(
                                    event.location_name):
                flash(
                    "Your event was saved. To publish your event please review the highlighted fields below.",
                    "warning")
                return redirect(
                    url_for('.edit_view', event_id=event.id) +
                    "#step=location_name")
            return redirect(url_for('.details_view', event_id=event_id))
Ejemplo n.º 7
0
 def publish_event(self, event_id):
     event = DataGetter.get_event(event_id)
     if string_empty(event.location_name):
         flash(
             "Your event was saved. To publish your event please review the highlighted fields below.",
             "warning")
         return redirect(
             url_for('.edit_view', event_id=event.id) +
             "#step=location_name")
     event.state = 'Published'
     save_to_db(event, 'Event Published')
     flash("Your event has been published.", "success")
     return redirect(url_for('.details_view', event_id=event_id))
Ejemplo n.º 8
0
    def edit_view(self, event_id):
        event = DataGetter.get_event(event_id)
        session_types = DataGetter.get_session_types_by_event_id(event_id).all()
        tracks = DataGetter.get_tracks(event_id).all()
        social_links = DataGetter.get_social_links_by_event_id(event_id)
        microlocations = DataGetter.get_microlocations(event_id).all()
        call_for_speakers = DataGetter.get_call_for_papers(event_id).first()
        sponsors = DataGetter.get_sponsors(event_id)
        custom_forms = DataGetter.get_custom_form_elements(event_id).first()
        speaker_form = json.loads(custom_forms.speaker_form)
        session_form = json.loads(custom_forms.session_form)

        preselect = []
        required = []
        for session_field in session_form:
            if session_form[session_field]['include'] == 1:
                preselect.append(session_field)
                if session_form[session_field]['require'] == 1:
                    required.append(session_field)
        for speaker_field in speaker_form:
            if speaker_form[speaker_field]['include'] == 1:
                preselect.append(speaker_field)
                if speaker_form[speaker_field]['require'] == 1:
                    required.append(speaker_field)
        print preselect

        if request.method == 'GET':
            return self.render('/gentelella/admin/event/edit/edit.html', event=event, session_types=session_types,
                               tracks=tracks, social_links=social_links, microlocations=microlocations,
                               call_for_speakers=call_for_speakers, sponsors=sponsors, event_types=DataGetter.get_event_types(),
                               event_topics=DataGetter.get_event_topics(), preselect=preselect,
                               required=required)
        if request.method == "POST":
            event = DataManager.edit_event(request, event_id, event, session_types, tracks, social_links,
                                           microlocations, call_for_speakers, sponsors, custom_forms)
            if request.form.get('state', u'Draft') == u'Published' and string_empty(event.location_name):
                flash("Your event was saved. To publish your event please review the highlighted fields below.",
                      "warning")
                return redirect(url_for('.edit_view', event_id=event.id) + "#step=location_name")
            return redirect(url_for('.details_view', event_id=event_id))
Ejemplo n.º 9
0
    def publish_event(self, event_id):
        event = DataGetter.get_event(event_id)
        if string_empty(event.location_name):
            flash(
                "Your event was saved. To publish your event please review the highlighted fields below.",
                "warning")
            return redirect(url_for('.edit_view',
                                    event_id=event.id) + "#step=location_name")
        if not is_verified_user():
            return redirect(url_for('.details_view', event_id=event_id))
        event.state = 'Published'
        save_to_db(event, 'Event Published')
        organizers = DataGetter.get_user_event_roles_by_role_name(event_id, 'organizer')
        speakers = DataGetter.get_user_event_roles_by_role_name(event_id, 'speaker')
        link = url_for('.details_view', event_id=event_id, _external=True)

        for organizer in organizers:
            send_event_publish(organizer.user.email, event.name, link)
        for speaker in speakers:
            send_event_publish(speaker.user.email, event.name, link)

        record_activity('publish_event', event_id=event.id, status='published')
        flash("Your event has been published.", "success")
        return redirect(url_for('.details_view', event_id=event_id))
Ejemplo n.º 10
0
    def edit_event(request, event_id, event, session_types, tracks, social_links, microlocations, call_for_papers,
                   sponsors, custom_forms):
        """
        Event will be updated in database
        :param data: view data form
        :param event: object contains all earlier data
        """
        form = request.form
        event.name = form['name']
        event.logo = form['logo']
        event.start_time = datetime.strptime(form['start_date'] + ' ' + form['start_time'], '%m/%d/%Y %H:%M')
        event.end_time = datetime.strptime(form['start_date'] + ' ' + form['end_time'], '%m/%d/%Y %H:%M')
        event.latitude = form['latitude']
        event.longitude = form['longitude']
        event.location_name = form['location_name']
        event.description = form['description']
        event.event_url = form['event_url']
        event.background_url = form['background_url']
        event.type = form['event_type']
        event.topic = form['topic']
        event.privacy = form.get('privacy', 'public')
        event.organizer_name = form['organizer_name']
        event.organizer_description = form['organizer_description']
        event.ticket_url = form['ticket_url']

        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

        for session_type in session_types:
            delete_from_db(session_type, 'Session Type Deleted')

        for track in tracks:
            delete_from_db(track, 'Track')

        for social_link in social_links:
            delete_from_db(social_link, 'Social Link Deleted')

        for microlocation in microlocations:
            delete_from_db(microlocation, 'Microlocation deleted')

        for sponsor in sponsors:
            delete_from_db(sponsor, 'Sponsor deleted')

        if call_for_papers:
            delete_from_db(call_for_papers, 'Call for paper deleted')

        if custom_forms:
            delete_from_db(custom_forms, 'Customs form deleted')

        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_logo = request.files.getlist('sponsors[logo]')
        sponsor_url = form.getlist('sponsors[url]')
        sponsor_level = form.getlist('sponsors[level]')
        sponsor_description = form.getlist('sponsors[description]')

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

        # save the edited info to database
        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):
            if not string_empty(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, logo=sponsor_logo[index].filename, url=sponsor_url[index], level=sponsor_level[index],
                                  description=sponsor_description[index], event_id=event.id)
                db.session.add(sponsor)

        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)

        save_to_db(event, "Event saved")
        return event
Ejemplo n.º 11
0
    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 edit_view_stepped(self, event_id, step):
        event = DataGetter.get_event(event_id)
        session_types = DataGetter.get_session_types_by_event_id(
            event_id).all()
        tracks = DataGetter.get_tracks(event_id).all()
        social_links = DataGetter.get_social_links_by_event_id(event_id)
        microlocations = DataGetter.get_microlocations(event_id).all()
        call_for_speakers = DataGetter.get_call_for_papers(event_id).first()
        sponsors = DataGetter.get_sponsors(event_id)
        custom_forms = DataGetter.get_custom_form_elements(event_id)
        speaker_form = json.loads(custom_forms.speaker_form)
        session_form = json.loads(custom_forms.session_form)

        preselect = []
        required = []
        for session_field in session_form:
            if session_form[session_field]['include'] == 1:
                preselect.append(session_field)
                if session_form[session_field]['require'] == 1:
                    required.append(session_field)
        for speaker_field in speaker_form:
            if speaker_form[speaker_field]['include'] == 1:
                preselect.append(speaker_field)
                if speaker_form[speaker_field]['require'] == 1:
                    required.append(speaker_field)
        print preselect

        if request.method == 'GET':
            return self.render('/gentelella/admin/event/edit/edit.html',
                               event=event,
                               session_types=session_types,
                               tracks=tracks,
                               social_links=social_links,
                               microlocations=microlocations,
                               call_for_speakers=call_for_speakers,
                               sponsors=sponsors,
                               event_types=DataGetter.get_event_types(),
                               event_topics=DataGetter.get_event_topics(),
                               preselect=preselect,
                               timezones=DataGetter.get_all_timezones(),
                               step=step,
                               required=required)
        if request.method == "POST":
            img_files = []
            imd = ImmutableMultiDict(request.files)
            if 'sponsors[logo]' in imd and request.files[
                    'sponsors[logo]'].filename != "":
                for img_file in imd.getlist('sponsors[logo]'):
                    img_files.append(img_file)

            old_sponsor_logos = []
            old_sponsor_names = []
            for sponsor in sponsors:
                old_sponsor_logos.append(sponsor.logo)
                old_sponsor_names.append(sponsor.name)

            event = DataManager.edit_event(request, event_id, event,
                                           session_types, tracks, social_links,
                                           microlocations, call_for_speakers,
                                           sponsors, custom_forms, img_files,
                                           old_sponsor_logos,
                                           old_sponsor_names)

            if request.form.get('state',
                                u'Draft') == u'Published' and string_empty(
                                    event.location_name):
                flash(
                    "Your event was saved. To publish your event please review the highlighted fields below.",
                    "warning")
                return redirect(
                    url_for('.edit_view', event_id=event.id) +
                    "#highlight=location_name")

            return redirect(url_for('.details_view', event_id=event_id))
Ejemplo n.º 13
0
    def edit_event(request, event_id, event, session_types, tracks,
                   social_links, microlocations, call_for_papers, sponsors,
                   custom_forms):
        """
        Event will be updated in database
        :param data: view data form
        :param event: object contains all earlier data
        """
        form = request.form
        event.name = form['name']
        event.logo = form['logo']
        event.start_time = datetime.strptime(
            form['start_date'] + ' ' + form['start_time'], '%m/%d/%Y %H:%M')
        event.end_time = datetime.strptime(
            form['start_date'] + ' ' + form['end_time'], '%m/%d/%Y %H:%M')
        event.latitude = form['latitude']
        event.longitude = form['longitude']
        event.location_name = form['location_name']
        event.description = form['description']
        event.event_url = form['event_url']
        event.background_url = form['background_url']
        event.type = form['event_type']
        event.topic = form['topic']
        event.privacy = form.get('privacy', 'public')
        event.organizer_name = form['organizer_name']
        event.organizer_description = form['organizer_description']
        event.ticket_url = form['ticket_url']

        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

        for session_type in session_types:
            delete_from_db(session_type, 'Session Type Deleted')

        for track in tracks:
            delete_from_db(track, 'Track')

        for social_link in social_links:
            delete_from_db(social_link, 'Social Link Deleted')

        for microlocation in microlocations:
            delete_from_db(microlocation, 'Microlocation deleted')

        for sponsor in sponsors:
            delete_from_db(sponsor, 'Sponsor deleted')

        if call_for_papers:
            delete_from_db(call_for_papers, 'Call for paper deleted')

        if custom_forms:
            delete_from_db(custom_forms, 'Customs form deleted')

        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_logo = request.files.getlist('sponsors[logo]')
        sponsor_url = form.getlist('sponsors[url]')
        sponsor_level = form.getlist('sponsors[level]')
        sponsor_description = form.getlist('sponsors[description]')

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

        # save the edited info to database
        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):
            if not string_empty(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,
                                  logo=sponsor_logo[index].filename,
                                  url=sponsor_url[index],
                                  level=sponsor_level[index],
                                  description=sponsor_description[index],
                                  event_id=event.id)
                db.session.add(sponsor)

        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)

        save_to_db(event, "Event saved")
        return event
Ejemplo n.º 14
0
    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")
Ejemplo n.º 15
0
    def edit_view_stepped(self, event_id, step):
        event = DataGetter.get_event(event_id)
        session_types = DataGetter.get_session_types_by_event_id(event_id).all(
        )
        tracks = DataGetter.get_tracks(event_id).all()
        social_links = DataGetter.get_social_links_by_event_id(event_id)
        microlocations = DataGetter.get_microlocations(event_id).all()
        call_for_speakers = DataGetter.get_call_for_papers(event_id).first()
        sponsors = DataGetter.get_sponsors(event_id)
        custom_forms = DataGetter.get_custom_form_elements(event_id)
        speaker_form = json.loads(custom_forms.speaker_form)
        session_form = json.loads(custom_forms.session_form)

        preselect = []
        required = []
        for session_field in session_form:
            if session_form[session_field]['include'] == 1:
                preselect.append(session_field)
                if session_form[session_field]['require'] == 1:
                    required.append(session_field)
        for speaker_field in speaker_form:
            if speaker_form[speaker_field]['include'] == 1:
                preselect.append(speaker_field)
                if speaker_form[speaker_field]['require'] == 1:
                    required.append(speaker_field)
        print preselect

        if request.method == 'GET':
            return self.render('/gentelella/admin/event/edit/edit.html',
                               event=event,
                               session_types=session_types,
                               tracks=tracks,
                               social_links=social_links,
                               microlocations=microlocations,
                               call_for_speakers=call_for_speakers,
                               sponsors=sponsors,
                               event_types=DataGetter.get_event_types(),
                               event_licences=DataGetter.get_event_licences(),
                               event_topics=DataGetter.get_event_topics(),
                               event_sub_topics=DataGetter.get_event_subtopics(),
                               preselect=preselect,
                               timezones=DataGetter.get_all_timezones(),
                               step=step,
                               required=required)
        if request.method == "POST":
            img_files = []
            imd = ImmutableMultiDict(request.files)
            if 'sponsors[logo]' in imd and request.files['sponsors[logo]'].filename != "":
                for img_file in imd.getlist('sponsors[logo]'):
                    img_files.append(img_file)

            old_sponsor_logos = []
            old_sponsor_names = []
            for sponsor in sponsors:
                old_sponsor_logos.append(sponsor.logo)
                old_sponsor_names.append(sponsor.name)

            event = DataManager.edit_event(
                request, event_id, event, session_types, tracks, social_links,
                microlocations, call_for_speakers, sponsors, custom_forms, img_files, old_sponsor_logos, old_sponsor_names)


            if request.form.get('state',
                                u'Draft') == u'Published' and string_empty(
                                event.location_name):
                flash(
                    "Your event was saved. To publish your event please review the highlighted fields below.",
                    "warning")
                return redirect(url_for('.edit_view', event_id=event.id) + "#highlight=location_name")

            return redirect(url_for('.details_view', event_id=event_id))
Ejemplo n.º 16
0
 def string_empty(string):
     from open_event.helpers.helpers import string_empty
     return string_empty(string)