Created
May 23, 2012 22:32
-
-
Save anonymous/2778242 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@login_required | |
def backgroundview(request): | |
if request.is_ajax(): | |
form = BackgroundModelForm(request.POST, request.FILES) | |
if form.is_valid(): | |
try: | |
g = BackgroundModel.objects.get(user=request.user) | |
except BackgroundModel.DoesNotExist: | |
data = form.save(commit=False) | |
data.user = request.user | |
data.save() | |
else: | |
if g.tmpbg != '' and g.tmpbg != g.background: | |
image_path = os.path.join(settings.MEDIA_ROOT, str(g.tmpbg)) | |
try: | |
os.unlink(image_path) | |
except: | |
pass | |
data = BackgroundModelForm(request.POST, request.FILES, instance=g).save() | |
return HttpResponse(data.tmpbg.url) | |
else: | |
try: | |
g = BackgroundModel.objects.get(user=request.user) | |
except BackgroundModel.DoesNotExist: | |
pass | |
else: | |
if g.tmpbg != '' and g.tmpbg != g.background: | |
image_path = os.path.join(settings.MEDIA_ROOT, str(g.tmpbg)) | |
try: | |
os.unlink(image_path) | |
except: | |
pass | |
form = BackgroundModelForm() | |
return render_to_response("cover.html", {'form': form}, context_instance=RequestContext(request)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment