def PrizeParticipateForm(request, prize_id, user_token): if request.method == 'POST': meguzForm = MeguzForm(request.POST) if(meguzForm.is_valid()): # Load model with form meguz = Meguz(**meguzForm.cleaned_data) slug = slugify(request.POST['title']) meguz.slug = slug meguz.status = 'B' meguz.prize_id = prize_id meguz.vote_count = 0 # Load user id from main.models import User user = User.objects.get(token=user_token) if user is None: context = {'response':'Forbidden'} else: meguz.user_id = user.id meguz.save() context = {'response':meguz.id} else: context = {'response':'fail'} else: context = {'response': 'invalid'} return render_to_response('meguz/participate.html', context, context_instance=RequestContext(request))
def PrizeParticipateForm(request, prize_id, user_token): if request.method == "POST": meguzForm = MeguzForm(request.POST) if meguzForm.is_valid(): # Load model with form meguz = Meguz(**meguzForm.cleaned_data) slug = slugify(request.POST["title"]) meguz.slug = slug meguz.status = "B" meguz.prize_id = prize_id meguz.vote_count = 0 # Load user id from main.models import User user = User.objects.get(token=user_token) if user is None: context = {"response": "Forbidden"} else: meguz.user_id = user.id meguz.save() context = {"response": meguz.id} else: context = {"response": "fail"} else: context = {"response": "invalid"} return render_to_response("meguz/participate.html", context, context_instance=RequestContext(request))
def MeguzCreateBase(request): if request.method == "POST": # Imports for django_youtube from django.core.urlresolvers import reverse from django.contrib import messages from django_youtube.api import Api, AccessControl, ApiError # Get POST params title = request.POST["title"] description = request.POST["description"] offer_id = request.POST["offer_id"] # Get and validate Offer offer = Offer.objects.get(pk=offer_id) if offer is None: response = "Premio no existe" else: # Offer is OK # Get and validate User from main.models import User user = User.objects.get(token=request.COOKIES.get("fbmgz_234778956683382")) if user is None: response = "Usuario no existe" else: # User is OK # Save Meguz meguz = Meguz() meguz.title = title meguz.description = description meguz.slug = slugify(title) meguz.status = "B" meguz.prize_id = offer_id meguz.vote_count = 0 meguz.user_id = user.id meguz.save() # Generate video metadata title = title + " | Meguz.com" keywords = offer.category.name + "," + offer.prize_name + "," + offer.company.name + ", Meguz, Premios" description = description + "... Visita www.meguz.com para mas informacion" # Try to create post_url and token try: api = Api() api.authenticate() data = api.upload( title, description=description, keywords=keywords, access_control=AccessControl.Unlisted ) # Api error happend except ApiError as e: response = e.message # Other error except Error as e: response = e.message response = data["youtube_token"] + "[GLUE]" + data["post_url"] + "[GLUE]" + str(meguz.id) else: response = "Forbidden" context = {"response": response} return render_to_response("meguz/create_base.html", context, context_instance=RequestContext(request))