コード例 #1
0
ファイル: views.py プロジェクト: pqzada/meguz.com
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))
コード例 #2
0
ファイル: views.py プロジェクト: stochastic-ltda/meguz.com
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))
コード例 #3
0
ファイル: views.py プロジェクト: pqzada/meguz.com
def MeguzEditForm(request, meguz_id, user_token):

	from django.core.urlresolvers import reverse
	from django.contrib import messages
	from django_youtube.api import Api, AccessControl, ApiError	

	if request.method == 'POST':
		meguzForm = MeguzForm(request.POST)

		if(meguzForm.is_valid()):

			# Load model with form
			meguz = Meguz.objects.get(pk=meguz_id)
			meguz.title = request.POST['title']
			meguz.description = request.POST['description']
			meguz.id = meguz_id

			# Load user id
			from main.models import User
			user = User.objects.get(token=user_token)
			if user is None:
				context = {'response':'Forbidden'}	
			else:
				meguz.save()

				if meguz.status == 'C':
					es = ES("localhost:9200")
					meguzES = es.get("meguz","meguz",meguz.id)
					meguzES.title = meguz.title
					meguzES.description = meguz.description
					meguzES.save()

				# Update youtube data
				try:
					api = Api()
					api.authenticate()

					title = meguz.title + " | Meguz.com"
					description = meguz.description + "... Visita www.meguz.com para mas informacion"
					keywords = meguz.prize.category.name + "," + meguz.prize.prize_name + "," + meguz.prize.company.name
					
					if meguz.video_id != '':
						api.update_video(meguz.video_id, title, description, keywords)

				# Api error happend
				except ApiError as e:
					messages.add_message(request, messages.ERROR, e.message)
					return HttpResponseRedirect("/")

				# Other error
				except:
					messages.add_message(request, messages.ERROR, _('Ha ocurrido un error, por favor intenta de nuevo'))
					return HttpResponseRedirect("/")


				context = {'response':meguz.id}
		else:
			context = {'response':'fail'}

	else:			
		context = {'response': 'invalid'}

	return render_to_response('meguz/edit_form.html', context, context_instance=RequestContext(request))