Ejemplo n.º 1
0
def contributor_upload(request, username):
	"""Request for new upload by the contributor"""
	context = RequestContext(request)
	uploaded= False
	if request.method == 'POST':
	        print "we have a request for upload by the contributor"    
	        contributor_upload_form = ContributorUploadForm(request.POST,request.FILES)
		if contributor_upload_form.is_valid():	
			print "Forms are valid"
			contributor=Contributor.objects.all().filter(username=username)
			subject.name = contributor.specialised_subject
			subject.contributor = contributor.id
			if 'pdf_doc' in request.FILES:
                		subject = Subject(pdf_doc = request.FILES['pdf_doc'])
			if 'video_doc' in request.FILES:
                		subject = Subject(pdf_doc = request.FILES['video_doc'])
			if 'animations_doc' in request.FILES:
                		subject = Subject(pdf_doc = request.FILES['animations_doc'])
			subject = contributor_upload_form.save(commit=False)                       
                        subject.save()
			return HttpResponseRedirect('webapp/home')
	        else:
			if contributor_upload_form.errors:
				print contributor_upload_form.errors
	else:
		contributor_upload_form = ContributorUploadForm()	
           
        context_dict = {'contributor_upload_form': contributor_upload_form,'subject.name':subject.name, 'contributor.id':contributor.id, 'uploaded':uploaded}
        return render_to_response("webapp/upload.html", context_dict, context)
Ejemplo n.º 2
0
def contributor_upload(request):
    """
    Argument:

    `request`: Request from contributor for a new upload.

     This function is used to upload a new file by contributor.

    """
    context = RequestContext(request)
    uploaded = False
    if request.POST:
        print "we have a request for upload by the contributor"
        contributor_upload_form = ContributorUploadForm(request.POST,
                                                        request.FILES)

        if contributor_upload_form.is_valid():
            print "Forms is/are valid"
            subject = contributor_upload_form.save(commit=False)
            if ('pdf' not in request.FILES
                and 'animation' not in request.FILES
                    and 'video' not in request.FILES):
                # Bad upload details were provided.
                messages.error(request, "need to provide atleast one upload")
                contributor_upload_form = ContributorUploadForm()
                context_dict = {
                    'contributor_upload_form': contributor_upload_form,
                    'uploaded': uploaded}
                return render_to_response("upload.html", context_dict, context)
            else:
                if 'pdf' in request.FILES:
                    subject.pdf = request.FILES['pdf']
                if 'video' in request.FILES:
                    subject.video = request.FILES['video']
                if 'animation' in request.FILES:
                    subject.animation = request.FILES['animation']
            contributor = Contributor.objects.get(user=request.user)
            subject.contributor = contributor

            subject.save()
            uploaded = True
            contributor_name = request.user.username
            return HttpResponseRedirect('/contributor/profile/')
        else:
            if contributor_upload_form.errors:
                print contributor_upload_form.errors
    else:
        # empty form
        contributor_upload_form = ContributorUploadForm()

    context_dict = {
        'contributor_upload_form': contributor_upload_form,
        'uploaded': uploaded
    }

    return render_to_response("upload.html", context_dict, context)
Ejemplo n.º 3
0
def contributor_upload(request):
    """
    Argument:

    `request`: Request from contributor for a new upload.

     This function is used to upload a new file by contributor.

    """
    context = RequestContext(request)
    uploaded = False
    if request.POST:
        print "we have a request for upload by the contributor"
        contributor_upload_form = ContributorUploadForm(
            request.POST, request.FILES)

        if contributor_upload_form.is_valid():
            print "Forms is/are valid"
            subject = contributor_upload_form.save(commit=False)
            if ('pdf' not in request.FILES and 'animation' not in request.FILES
                    and 'video' not in request.FILES):
                # Bad upload details were provided.
                messages.error(request, "need to provide atleast one upload")
                contributor_upload_form = ContributorUploadForm()
                context_dict = {
                    'contributor_upload_form': contributor_upload_form,
                    'uploaded': uploaded
                }
                return render_to_response("upload.html", context_dict, context)
            else:
                if 'pdf' in request.FILES:
                    subject.pdf = request.FILES['pdf']
                if 'video' in request.FILES:
                    subject.video = request.FILES['video']
                if 'animation' in request.FILES:
                    subject.animation = request.FILES['animation']
            contributor = Contributor.objects.get(user=request.user)
            subject.contributor = contributor

            subject.save()
            uploaded = True
            contributor_name = request.user.username
            return HttpResponseRedirect('/contributor/profile/')
        else:
            if contributor_upload_form.errors:
                print contributor_upload_form.errors
    else:
        # empty form
        contributor_upload_form = ContributorUploadForm()

    context_dict = {
        'contributor_upload_form': contributor_upload_form,
        'uploaded': uploaded
    }

    return render_to_response("upload.html", context_dict, context)
Ejemplo n.º 4
0
def contributor_upload(request, username):
    """Request for new upload by the contributor"""
    context = RequestContext(request)
    uploaded = False
    if request.method == 'POST':
        print "we have a request for upload by the contributor"
        contributor_upload_form = ContributorUploadForm(
            request.POST, request.FILES)
        if contributor_upload_form.is_valid():
            print "Forms are valid"
            contributor = Contributor.objects.all().filter(username=username)
            subject.name = contributor.specialised_subject
            subject.contributor = contributor.id
            if 'pdf_doc' in request.FILES:
                subject = Subject(pdf_doc=request.FILES['pdf_doc'])
            if 'video_doc' in request.FILES:
                subject = Subject(pdf_doc=request.FILES['video_doc'])
            if 'animations_doc' in request.FILES:
                subject = Subject(pdf_doc=request.FILES['animations_doc'])
            subject = contributor_upload_form.save(commit=False)
            subject.save()
            return HttpResponseRedirect('webapp/home')
        else:
            if contributor_upload_form.errors:
                print contributor_upload_form.errors
    else:
        contributor_upload_form = ContributorUploadForm()

    context_dict = {
        'contributor_upload_form': contributor_upload_form,
        'subject.name': subject.name,
        'contributor.id': contributor.id,
        'uploaded': uploaded
    }
    return render_to_response("webapp/upload.html", context_dict, context)
Ejemplo n.º 5
0
def contributor_upload(request):
	"""Request for new upload by the contributor"""
	context = RequestContext(request)
	uploaded= False
	if request.method == 'POST':
	        print "we have a request for upload by the contributor"    
	        contributor_upload_form = ContributorUploadForm(request.POST,request.FILES)
		if contributor_upload_form.is_valid():	
			print "Forms are valid"
			subject=contributor_upload_form.save(commit=False)
			# contri=Contributor.objects.get(user_id=id)
      			contri = Contributor.objects.get(user=request.user)
			subject.contributor=contri
			subject.name=contri.specialised_subject
			if 'pdf' in request.FILES:
                		subject.pdf=request.FILES['pdf']
			if 'video' in request.FILES:
                		subject.video = request.FILES['video']
			if 'animation' in request.FILES:
                		subject.animation = request.FILES['animation']
			                     
                        subject.save()
			uploaded = True
			return HttpResponseRedirect(reverse('webapp.views.contributor_profile'))
	        else:
			if contributor_upload_form.errors:
				print contributor_upload_form.errors
	else:
		contributor_upload_form = ContributorUploadForm()	
           
        context_dict = {'contributor_upload_form': contributor_upload_form, 'uploaded':uploaded}
        return render_to_response("webapp/upload.html", context_dict, context)
Ejemplo n.º 6
0
def contributor_upload(request):
    """Request for new upload by the contributor.
    """
    context = RequestContext(request)
    uploaded= False
    if request.POST:
        print "we have a request for upload by the contributor"
        contributor_upload_form = ContributorUploadForm(request.POST,
                                                        request.FILES)
        if contributor_upload_form.is_valid():
            print "Forms is valid"
            subject=contributor_upload_form.save(commit=False)
            # contri=Contributor.objects.get(user_id=id)
            contributor = Contributor.objects.get(user=request.user)
            subject.contributor=contributor
            if 'pdf' in request.FILES:
                subject.pdf=request.FILES['pdf']
            if 'video' in request.FILES:
                subject.video = request.FILES['video']
            if 'animation' in request.FILES:
                subject.animation = request.FILES['animation']

            subject.save()
            uploaded = True
            contributor_name = request.user.username
            return HttpResponseRedirect('/contributor/profile/')
        else:
            if contributor_upload_form.errors:
                print contributor_upload_form.errors
    else:
        # empty form
        contributor_upload_form = ContributorUploadForm()

    context_dict = {
        'contributor_upload_form': contributor_upload_form,
        'uploaded': uploaded
    }

    return render_to_response("upload.html", context_dict, context)
Ejemplo n.º 7
0
def contributor_upload(request):
    """Request for new upload by the contributor.
    """
    context = RequestContext(request)
    uploaded = False
    if request.POST:
        print "we have a request for upload by the contributor"
        contributor_upload_form = ContributorUploadForm(
            request.POST, request.FILES)
        if contributor_upload_form.is_valid():
            print "Forms is valid"
            subject = contributor_upload_form.save(commit=False)
            # contri=Contributor.objects.get(user_id=id)
            contributor = Contributor.objects.get(user=request.user)
            subject.contributor = contributor
            if 'pdf' in request.FILES:
                subject.pdf = request.FILES['pdf']
            if 'video' in request.FILES:
                subject.video = request.FILES['video']
            if 'animation' in request.FILES:
                subject.animation = request.FILES['animation']

            subject.save()
            uploaded = True
            contributor_name = request.user.username
            return HttpResponseRedirect('/contributor/profile/')
        else:
            if contributor_upload_form.errors:
                print contributor_upload_form.errors
    else:
        # empty form
        contributor_upload_form = ContributorUploadForm()

    context_dict = {
        'contributor_upload_form': contributor_upload_form,
        'uploaded': uploaded
    }

    return render_to_response("upload.html", context_dict, context)