Ejemplo n.º 1
0
def talk_new(request):
    if request.method == 'POST': # If the form has been submitted...
        talk_form = TalkForm(request.POST, request.FILES)
        location_form = None

        if talk_form.is_valid():
            talk = Talk()
            talk.name = talk_form.cleaned_data['name']
            talk.abstract = talk_form.cleaned_data['abstract']
            talk.speaker = request.user

            talk.save()

            return redirect('/talk/' + str(talk.id))

    return HttpResponseNotFound()
Ejemplo n.º 2
0
def generate_talk(speaker):
    talk = Talk()
    talk.name = random.choice(verbs) + " " + random.choice(things) + ": " + random.choice(long_actions)
    talk.abstract = talk_description

    if random.choice(range(0,10)) % 2 == 0:
        talk.published = False

    talk.speaker = speaker
    talk.save()

    for i in range(0, random.choice(range(2,7))):
        tag = TalkTag.objects.get(name=random.choice(profile_tags))

        if tag not in talk.tags.all():
            talk.tags.add(tag)

    return talk
Ejemplo n.º 3
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")