コード例 #1
0
ファイル: views.py プロジェクト: muskanmahajan37/scipycon
def edit_talk(request, scope, id, template_name='talk/edit-talk.html'):
    """Allows users that submitted a talk to edit it until the talk is approved.
    """

    talk = Talk.objects.get(pk=id)

    if talk.approved == True:
        redirect_to = reverse('scipycon_account', kwargs={'scope': scope})
        return set_message_cookie(redirect_to,
                msg = u'Sorry but you cannot edit the talk once'\
                      + ' it has been accepted.')

    if talk.speaker != request.user:
        redirect_to = reverse('scipycon_account', kwargs={'scope': scope})
        return set_message_cookie(redirect_to,
                msg = u'Redirected to account because the talk you selected' \
                      + ' is not your own.')

    if request.method == 'POST':
        form = TalkEditForm(data=request.POST)
        if form.is_valid():
            talk.slug = slugify(form.data.get('title'))
            talk.authors_bio = form.data.get('authors_bio')
            talk.contact = form.data.get('contact')
            talk.title = form.data.get('title')
            talk.abstract = form.data.get('abstract')
            talk.topic = form.data.get('topic')
            talk.duration = form.data.get('duration')
            talk.audience = form.data.get('audience')
            talk.save()

            # Saved.. redirect
            redirect_to = reverse('scipycon_edit_talk',
                                  kwargs={
                                      'scope': scope,
                                      'id': talk.id
                                  })
            return set_message_cookie(redirect_to,
                                      msg=u'Your changes have been saved.')
    else:
        form = TalkEditForm(
            initial={
                'id': id,
                'authors_bio': talk.authors_bio,
                'contact': talk.contact,
                'title': talk.title,
                'abstract': talk.abstract,
                'topic': talk.topic,
                'duration': talk.duration,
                'audience': talk.audience,
            })

    context = locals()
    context['params'] = {'scope': scope}

    return render_to_response(template_name, RequestContext(request, context))
コード例 #2
0
ファイル: views.py プロジェクト: FOSSEE/scipycon
def edit_talk(request, scope, id, template_name='talk/edit-talk.html'):
    """Allows users that submitted a talk to edit it until the talk is approved.
    """

    talk = Talk.objects.get(pk=id)

    if talk.approved == True:
        redirect_to = reverse('scipycon_account', kwargs={'scope': scope})
        return set_message_cookie(redirect_to,
                msg = u'Sorry but you cannot edit the talk once'\
                      + ' it has been accepted.')

    if talk.speaker != request.user:
        redirect_to = reverse('scipycon_account', kwargs={'scope': scope})
        return set_message_cookie(redirect_to,
                msg = u'Redirected to account because the talk you selected' \
                      + ' is not your own.')

    if request.method == 'POST':
        form = TalkEditForm(data=request.POST)
        if form.is_valid():
            talk.slug = slugify(form.data.get('title'))
            talk.authors_bio = form.data.get('authors_bio')
            talk.contact = form.data.get('contact')
            talk.title = form.data.get('title')
            talk.abstract = form.data.get('abstract')
            talk.topic = form.data.get('topic')
            talk.duration = form.data.get('duration')
            talk.audience = form.data.get('audience')
            talk.save()

            # Saved.. redirect
            redirect_to = reverse('scipycon_edit_talk', 
                                  kwargs={'scope': scope, 'id': talk.id})
            return set_message_cookie(redirect_to,
                    msg = u'Your changes have been saved.')
    else:
        form = TalkEditForm(initial={
                                    'id' : id,
                                    'authors_bio' : talk.authors_bio,
                                    'contact' : talk.contact,
                                    'title' : talk.title,
                                    'abstract' : talk.abstract,
                                    'topic' : talk.topic,
                                    'duration' : talk.duration,
                                    'audience' : talk.audience,
            })

    context = locals()
    context['params'] = {'scope': scope}

    return render_to_response(template_name, RequestContext(request, context))
コード例 #3
0
ファイル: views.py プロジェクト: FOSSEE/scipycon
def submit_talk(request, scope, template_name='talk/submit-talk.html'):
    """Allows user to edit profile
    """

    scope_entity = Event.objects.get(scope=scope)

    user = request.user
    if user.is_authenticated():
        try:
            profile = user.get_profile()
        except:
            profile, new = UserProfile.objects.get_or_create(
                user=user, scope=scope_entity)
            if new:
                profile.save()

    message = None

    if request.method == 'POST':
        talk_form = TalkSubmitForm(data=request.POST)

        register_form = RegisterForm(data=request.POST, files=request.FILES)

        if request.POST.get('action', None) == 'login':
            login_form = AuthenticationForm(data=request.POST)
            if login_form.is_valid():

                from django.contrib.auth import login
                login(request, login_form.get_user())

                redirect_to = reverse('scipycon_submit_talk',
                                      kwargs={'scope': scope})
                return set_message_cookie(redirect_to,
                        msg = u'You have been logged in.')

        if request.POST.get('action', None) == 'register':
            # add the new user
            if register_form.is_valid():

                user = scipycon_createuser(request, register_form.data)

        if talk_form.is_valid():
            if user.is_authenticated():
                title = talk_form.data.get('title')
                talk = Talk.objects.create(
                    slug = slugify(title),
                    scope = scope_entity,
                    speaker = User.objects.get(pk=user.id),
                    authors_bio = talk_form.data.get('authors_bio'),
                    contact = talk_form.data.get('contact'),
                    title = talk_form.data.get('title'),
                    abstract = talk_form.data.get('abstract'),
                    topic = talk_form.data.get('topic'),
                    duration = talk_form.data.get('duration'),
                    audience = talk_form.data.get('audience'),
                    approved = False,
#                    tags = talk_form.data.get('tags')
                    )
                talk.save()
                # Saved, ... redirect back to account
                redirect_to = reverse('scipycon_edit_talk', 
                                      kwargs={'scope': scope, 'id': talk.id})
                return set_message_cookie(redirect_to,
                        msg = u'Thanks, your talk has been submitted.')
            else:
                redirect_to = reverse('scipycon_submit_talk',
                                      kwargs={'scope': scope})
                return set_message_cookie(redirect_to,
                        msg = u'Something is wrong here.')

    else:
        talk_form = TalkSubmitForm()
        register_form = RegisterForm()
    login_form = AuthenticationForm()


    return render_to_response(template_name, RequestContext(request, {
        'params': {'scope': scope},
        'talk_form': talk_form,
        'register_form' : register_form,
        'message' : message,
        'login_form' : login_form
    }))
コード例 #4
0
ファイル: views.py プロジェクト: muskanmahajan37/scipycon
def submit_talk(request, scope, template_name='talk/submit-talk.html'):
    """Allows user to edit profile
    """

    scope_entity = Event.objects.get(scope=scope)

    user = request.user
    if user.is_authenticated():
        try:
            profile = user.get_profile()
        except:
            profile, new = UserProfile.objects.get_or_create(
                user=user, scope=scope_entity)
            if new:
                profile.save()

    message = None

    if request.method == 'POST':
        talk_form = TalkSubmitForm(data=request.POST)

        register_form = RegisterForm(data=request.POST, files=request.FILES)

        if request.POST.get('action', None) == 'login':
            login_form = AuthenticationForm(data=request.POST)
            if login_form.is_valid():

                from django.contrib.auth import login
                login(request, login_form.get_user())

                redirect_to = reverse('scipycon_submit_talk',
                                      kwargs={'scope': scope})
                return set_message_cookie(redirect_to,
                                          msg=u'You have been logged in.')

        if request.POST.get('action', None) == 'register':
            # add the new user
            if register_form.is_valid():

                user = scipycon_createuser(request, register_form.data)

        if talk_form.is_valid():
            if user.is_authenticated():
                title = talk_form.data.get('title')
                talk = Talk.objects.create(
                    slug=slugify(title),
                    scope=scope_entity,
                    speaker=User.objects.get(pk=user.id),
                    authors_bio=talk_form.data.get('authors_bio'),
                    contact=talk_form.data.get('contact'),
                    title=talk_form.data.get('title'),
                    abstract=talk_form.data.get('abstract'),
                    topic=talk_form.data.get('topic'),
                    duration=talk_form.data.get('duration'),
                    audience=talk_form.data.get('audience'),
                    approved=False,
                    #                    tags = talk_form.data.get('tags')
                )
                talk.save()
                # Saved, ... redirect back to account
                redirect_to = reverse('scipycon_edit_talk',
                                      kwargs={
                                          'scope': scope,
                                          'id': talk.id
                                      })
                return set_message_cookie(
                    redirect_to, msg=u'Thanks, your talk has been submitted.')
            else:
                redirect_to = reverse('scipycon_submit_talk',
                                      kwargs={'scope': scope})
                return set_message_cookie(redirect_to,
                                          msg=u'Something is wrong here.')

    else:
        talk_form = TalkSubmitForm()
        register_form = RegisterForm()
    login_form = AuthenticationForm()

    return render_to_response(
        template_name,
        RequestContext(
            request, {
                'params': {
                    'scope': scope
                },
                'talk_form': talk_form,
                'register_form': register_form,
                'message': message,
                'login_form': login_form
            }))