Example #1
0
def posterUpload(request):
    # Handle file upload
    c = {}
    c.update(csrf(request))
    if request.method == 'POST':
        form = PosterForm(request.POST)
        if form.is_valid():
            newPoster = Poster(posterFile1 = File(open(settings.SITE_ROOT + "/media/posters/"+form.cleaned_data['filename'])), event_date = form.cleaned_data['event_date'], start_time = form.cleaned_data['start_time'], end_time = form.cleaned_data['end_time'], tag1 = form.cleaned_data['tag1'], email = form.cleaned_data['email'], title = form.cleaned_data['title'])
            newPoster.save()
            if request.is_ajax():
		print "AJAX"
		return HttpResponse('success')
	    # Redirect to the document list after POST
            # return HttpResponseRedirect(reverse('PosterBoard.PosterBoardApp.views.upload_page'))
    else:
        form = PosterForm() # A empty, unbound form

    # Load documents for the list page
    posters = Poster.objects.all()

    # Render list page with the documents and the form
    return render_to_response(
        'posterupload.html',
        {'posters': posters, 'form': form},
        context_instance = RequestContext(request)
   )
Example #2
0
def upload_page( request ):
    ctx = RequestContext( request, {
      'csrf_token': get_token( request ),
      } )
    if request.method == 'POST':
        form = PosterForm(request.POST)
        if form.is_valid():
	    fname = form.cleaned_data['filename'].split("/")
	    print fname
            fname = fname[len(fname)-1]
            print fname
 	    newPoster = Poster(posterFile1 = fname, event_date = form.cleaned_data['event_date'], start_time = form.cleaned_data['start_time'], end_time = form.cleaned_data['end_time'], tag1 = form.cleaned_data['tag1'], tag2 = form.cleaned_data['tag2'], tag3 = form.cleaned_data['tag3'], tag4 = form.cleaned_data['tag4'], tag5 = form.cleaned_data['tag5'], email = form.cleaned_data['email'], title = form.cleaned_data['title'])
            newPoster.save()
            print "Poster objects:", Poster.objects.count()
            # Redirect to the document list after POST
	    return HttpResponse('<div id = "temp ' + str(newPoster.id) + '" class="poster-div" event_date="' + str(newPoster.event_date.year) + ' ' + str(newPoster.event_date.month) + ' ' + str(newPoster.event_date.day) + '"><img class="thumbnail" data-tags="' + newPoster.tag1 + ',' + newPoster.tag2 + ',' + newPoster.tag3 + ',' + newPoster.tag4 + ',' + newPoster.tag5 + '" src="' + settings.MEDIA_URL +'posters/' + newPoster.posterFile1 + '" data-uid="' + str(newPoster.id) + '"/> <br /><br /></div>')
    else:
        form = PosterForm() # A empty, unbound form

    # Load documents for the list page
    posters = Poster.objects.all()
    # Render list page with the documents and the form
    return render_to_response(
        'upload_page.html',
        {'posters': posters, 'form': form},
        context_instance = ctx )
Example #3
0
def home(request):
    posters = Poster.objects.all()
    json_serializer = serializers.get_serializer("json")()
    serial = json_serializer.serialize(posters, ensure_ascii=False)
    form = PosterForm()
    return render_to_response(
        'index.html',
        {'posters': posters,
        'postersserial' : serial,
	'form' : form}, 
        context_instance = RequestContext(request)
   )