Exemplo n.º 1
0
def talk_slides_new(request, talk_id):
    talk = get_object_or_404(Talk, pk=talk_id)

    if request.user != talk.speaker:
        return HttpResponseForbidden()

    if request.method == 'POST':
        form = TalkSlideDeckForm(request.POST)

        if form.is_valid():
            deck = TalkSlideDeck.from_embed(talk, form.cleaned_data['embed'], form.cleaned_data['source'])

            if deck:
                deck.save()
                return redirect(talk)
            else:
                return HttpResponseNotFound()


    return HttpResponseNotFound()
Exemplo n.º 2
0
def process_event_upload(upload):
    upload.state = EventUpload.IMPORT_STARTED
    upload.save()

    csv_reader = csv.reader(upload.import_file)
    rows = [r for r in csv_reader]
    upload.import_file.close()

    rows = [Row(num, *r) for num, r in enumerate(rows)]

    #Test if they deleted any of the example lines 1 through 5
    test_rows = rows[:5]
    bad_session_titles = ("Session Title", "Text", "REQUIRED", "", "Super Advanced Python")
    good_rows = [r for r in test_rows if r.session_title not in bad_session_titles]
    rows = good_rows + rows[5:]

    new_speakers = []
    for row in rows:
        try:
            speaker = SpkrbarUser.objects.get(email=row.speaker_email)
        except:
            password = SpkrbarUser.objects.make_random_password()
            speaker = SpkrbarUser.objects.create_user(row.speaker_email, password=password)
            speaker.save()
            new_speakers.append(speaker)

        if not speaker.full_name:
            speaker.full_name = strip_tags(row.speaker_name)

        if not speaker.about_me:
            speaker.about_me = strip_tags(row.speaker_bio)

        process_event_upload_tags(speaker, UserTag, strip_tags(row.speaker_tags))

        process_event_upload_speaker_link(speaker, 'LIN', row.speaker_linkedin)
        process_event_upload_speaker_link(speaker, 'TWI', row.speaker_twitter)
        process_event_upload_speaker_link(speaker, 'FAC', row.speaker_facebook)
        process_event_upload_speaker_link(speaker, 'WEB', row.speaker_website)

        speaker.save()

        try:
            talk = speaker.talks.get(name=row.session_title)
        except:
            talk = Talk()
            talk.speaker = speaker
            talk.name = strip_tags(row.session_title)

        if not talk.abstract:
            talk.abstract = strip_tags(row.session_abstract)

        talk.save()

        process_event_upload_tags(talk, TalkTag, strip_tags(row.session_tags))

        if row.session_video and talk.videos.count() == 0:
            video = TalkVideo.from_embed(talk, row.session_video)
            if video:
                video.save()

        if row.session_slide and talk.slides.count() == 0:
            deck = TalkSlideDeck.from_embed(talk, row.session_slide)
            if deck:
                deck.save()

        links = strip_tags(row.session_links).split(',')

        for l in links:
            if l and not talk.links.filter(url=l).exists():
                link = TalkLink()
                link.talk = talk
                link.name = "Session Resource"
                link.url = l
                link.save()

        start_date = dtparse(strip_tags(row.session_date))
        start_time = dtparse(strip_tags(row.session_start_time))

        eng = talk.engagements.filter(
            event_name=upload.name,
            date=start_date,
            time=start_time).exists()

        if not eng:
            en = Engagement()
            en.talk = talk
            en.speaker = speaker
            en.event_name = upload.name
            en.location = upload.location
            en.date = start_date
            en.time = start_time
            en.room = strip_tags(row.session_room_name)
            en.save()

    upload.state = EventUpload.IMPORT_FINISHED
    upload.save()

    #Notify every new speaker
    for speaker in new_speakers:
        assign_basic_permissions(speaker)

        mes = email_template.render(Context({'name': speaker.full_name, 'event': upload.name}))
        send_html_mail("Claim your profile on SpkrBar", strip_tags(mes), mes, [speaker.email])

    return HttpResponse(json.dumps({'success': True}), content_type="application/json")