예제 #1
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
    }))
예제 #2
0
def submit(request, scope, id=None, template='proceedings/submit.html'):
    """View to submit the proceedings paper.
    """

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

    if request.method == 'POST':
        register_form = RegisterForm(data=request.POST)

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

                login(request, login_form.get_user())

                redirect_to = reverse('scipycon_submit_proceedings',
                                      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)

        proceedings_form = ProceedingsForm(data=request.POST,
                                           files=request.FILES)

        if proceedings_form.is_valid():
            if user.is_authenticated():
                # Data from reSt file is appended to the data in fields
                title, abstract, body, authors = handleUploadedFile(
                    proceedings_form.cleaned_data, request.FILES.get('file'))

                paper = edit(id,
                             title=title,
                             abstract=abstract,
                             body=body,
                             authors=authors) if id else create(
                                 title=title,
                                 abstract=abstract,
                                 body=body,
                                 authors=authors)

                # Successfully saved. So get back to the edit page.
                redirect_to = reverse('scipycon_submit_proceedings',
                                      args=[paper.id],
                                      kwargs={'scope': scope})
                return set_message_cookie(
                    redirect_to, msg=u'Thanks, your paper has been submitted.')
            else:
                # This is impossible. Something was wrong so return back
                # to submit page
                redirect_to = reverse('scipycon_submit_proceedings',
                                      kwargs={'scope': scope})
                return set_message_cookie(redirect_to,
                                          msg=u'Something is wrong here.')
    else:
        if id:
            # If id exists initialize the form with old values
            paper = Paper.objects.get(id=id)
            proceedings_form = ProceedingsForm(
                initial={
                    'title':
                    paper.title,
                    'abstract':
                    paper.abstract,
                    'body':
                    paper.body,
                    'authors':
                    ', '.join(
                        [author.username for author in paper.authors.all()])
                })
        else:
            # Otherwise create a new form
            proceedings_form = ProceedingsForm()

        register_form = RegisterForm()
        login_form = AuthenticationForm()

    context = RequestContext(
        request, {
            'proceedings_form': proceedings_form,
            'register_form': register_form,
            'message': message,
            'login_form': login_form
        })

    context['id'] = id if id else None

    return render_to_response(template, context)
예제 #3
0
파일: views.py 프로젝트: FOSSEE/scipycon
def submit(request, scope, id=None, template='proceedings/submit.html'):
    """View to submit the proceedings paper.
    """

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

    if request.method == 'POST':
        register_form = RegisterForm(data=request.POST)

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

                login(request, login_form.get_user())

                redirect_to = reverse('scipycon_submit_proceedings',
                                      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)

        proceedings_form = ProceedingsForm(data=request.POST,
                                           files=request.FILES)
  
        if proceedings_form.is_valid():
            if user.is_authenticated():
                # Data from reSt file is appended to the data in fields
                title, abstract, body, authors = handleUploadedFile(
                    proceedings_form.cleaned_data, request.FILES.get('file'))

                paper = edit(id, title=title,
                    abstract=abstract, body=body,
                    authors=authors) if id else create(title=title,
                    abstract=abstract, body=body,
                    authors=authors)

                # Successfully saved. So get back to the edit page.
                redirect_to = reverse('scipycon_submit_proceedings',
                                      args=[paper.id], kwargs={'scope': scope})
                return set_message_cookie(
                redirect_to, msg = u'Thanks, your paper has been submitted.')
            else:
                # This is impossible. Something was wrong so return back
                # to submit page
                redirect_to = reverse('scipycon_submit_proceedings',
                                      kwargs={'scope': scope})
                return set_message_cookie(
                redirect_to, msg = u'Something is wrong here.')          
    else:
        if id:
            # If id exists initialize the form with old values
            paper = Paper.objects.get(id=id)
            proceedings_form = ProceedingsForm(
                initial={'title': paper.title,
                         'abstract': paper.abstract,
                         'body': paper.body,
                         'authors': ', '.join([
                             author.username for author in paper.authors.all()])
                })
        else:
            # Otherwise create a new form
            proceedings_form = ProceedingsForm()

        register_form = RegisterForm()
        login_form = AuthenticationForm()

    context = RequestContext(request, {
        'proceedings_form': proceedings_form,
        'register_form' : register_form,
        'message' : message,
        'login_form' : login_form
        })

    context['id'] = id if id else None

    return render_to_response(template, context)
예제 #4
0
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
            }))
예제 #5
0
파일: views.py 프로젝트: FOSSEE/scipycon
def login(request, scope, template_name="user/login.html"):
    """Custom view to login or register/login a user.
       Integration of register and login form
       It uses Django's standard AuthenticationForm, though.
    """

    user = request.user
    if user.is_authenticated():
        redirect_to = reverse("scipycon_account", kwargs={'scope': scope})
        return set_message_cookie(redirect_to,
                msg = u"Redirected to account from login form.")

    # Using Djangos default AuthenticationForm
    login_form = AuthenticationForm()
    register_form = RegisterForm()

    if request.POST.get("action") == "login":
        login_form = AuthenticationForm(data=request.POST)

        if login_form.is_valid():
            redirect_to = request.POST.get("next")
            # Light security check -- make sure redirect_to isn't garbage.
            if not redirect_to or '//' in redirect_to or ' ' in redirect_to:
                redirect_to = reverse('scipycon_account',
                                      kwargs={'scope': scope})

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

            return set_message_cookie(redirect_to, msg = u"You have been logged in.")

    elif request.POST.get("action") == "register":
        register_form = RegisterForm(data=request.POST)
        if register_form.is_valid():

            user = scipycon_createuser(request, register_form.data, scope)

            redirect_to = request.POST.get("next")
            if not redirect_to or '//' in redirect_to or ' ' in redirect_to:
                redirect_to = reverse('scipycon_account',
                                      kwargs={'scope': scope})

            return set_message_cookie(
                redirect_to, msg = u"You have been registered and logged in.")

    # Get next_url
    next_url = request.REQUEST.get("next")
    if next_url is None:
        next_url = request.META.get("HTTP_REFERER")
    if next_url is None:
        next_url = reverse('scipycon_account', kwargs={'scope': scope})

    # Get just the path of the url.
    # See django.contrib.auth.views.login for more
    next_url = urlparse(next_url)
    next_url = next_url[2]

    try:
        login_form_errors = login_form.errors["__all__"]
    except KeyError:
        login_form_errors = None

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