def add_program(request): #title = request.POST["title"] #description = request.POST["description"] user = request.POST["owner"] print user owner = User.objects.get(google_id=user) content = request.POST["content"] content = content.encode('utf-8') print owner print "before printing out content in add_program" print content program = Program( #title = title, #description = description, owner = owner, content = content ) program.save() data = {'content':program.content, 'owner':program.owner.google_id, 'id':program.id} response_data = {'data':data} return HttpResponse(json.dumps(response_data), content_type="application/json")
def program_upload(request): user = request.user if request.method == 'POST': if user.is_authenticated(): file = request.FILES.get('filename', '') file_name = file.name dest_dir = os.path.join(settings.USR_PROGRAM_ROOT, user.username) if not os.path.exists(dest_dir): os.makedirs(dest_dir) # os.chmod(dest_dir, 0775) full_path = os.path.join(dest_dir, file_name) destination = open(full_path, "wb+") for chunk in file.chunks(): destination.write(chunk) destination.close() language = request.POST['lang'] description = request.POST['description'] access = request.POST['access'] new_program = Program(owner = user, path = full_path, name = file_name, language = language, description = description, access = access) new_program.save() notice = "Congratulations! Your model has been successfully uploaded." return render_to_response('program/success.html', RequestContext(request, {'program': new_program, 'notice': notice})) else: notice = "You must be logged in to upload programs" form = UploadProgramForm() return render_to_response('program/upload.html', RequestContext(request, {'form': form, 'notice': notice})) else: form = UploadProgramForm() return render_to_response('program/upload.html', RequestContext(request, {'form': form}))
def post(self): form = Program.NewProgramForm(self.request.POST) if form.validate(): user = Program.save(self, form, LEGACY_TEMPLATE) else: self.response.write(LEGACY_TEMPLATE.render({"form": form}))