def create_adex(request): if request.POST: # (re)Verify input v = request.POST.copy() errors = processCreateVars(v) data, media_list = genData(v) if not errors: user = request.user if request.user.is_authenticated() else None adex = Adex.objects.create( user = user, ip = request.META['REMOTE_ADDR'], item_code = genItemCode(), domain = v.get('domain'), title = v.get('title'), description = v.get('description'), type = v.get('type'), tags = v.get('tags'), data = data, expiration = v.get('expiration'), ) if len(media_list) > 0: for media_id in media_list: adex.media.add(LibraryFile.objects.get(pk=media_id)) if adex.type == 3: webthumb(v['url'], settings.MEDIA_ROOT+'webthumb/%d.jpg'%adex.pk) try: del request.session['uploaded_media'] except KeyError: pass return HttpResponse(json.dumps({'success':True, 'value':'http://anondex.com/?'+adex.item_code})) else: return HttpResponse(json.dumps({'success':False, 'error':'<div><ul><li>'+'</li><li>'.join(errors)+'</li></ul></div>'})) else: return redirect('/')
def preview(request): if request.POST: # (re)Verify input v = request.POST.copy() errors = processCreateVars(v) data, media_list = genData(v) if not errors: user = request.user if request.user.is_authenticated() else None adex = Adex( user = user, ip = request.META['REMOTE_ADDR'], domain = v.get('domain'), title = v.get('title'), description = v.get('description'), type = v.get('type'), tags = v.get('tags'), data = data, expiration = v.get('expiration'), ) media = list() tags = list() for i in v.get('tags').split(','): tags.append(Tag(name=i)) if len(media_list) > 0: for media_id in media_list: media.append(LibraryFile.objects.get(pk=media_id)) return adex_render(request, adex, tags, media) else: return HttpResponse('<div><ul><li>'+'</li><li>'.join(errors)+'</li></ul></div>') else: return redirect('/')