예제 #1
0
파일: views.py 프로젝트: kayethano/howmuch
def post(request):
    from howmuch.tags.functions import input_to_words, add_tags
    #Si la cuenta de usuario esta bloqueada que lo indique
    if request.user.profile.is_block == True:
        return HttpResponse('Tu Cuenta esta bloqueada')
    #Formulario
    if request.method == 'POST':
        form=ArticleForm(request.POST)
        if form.is_valid():
            newPost = form.save(commit=False)
            newPost.owner = request.user
            #Se genera el campo url sustituyendo caracteres
            newPost.title_url=newPost.title.replace(u'\xf1', 'n').replace(' ','-')
            newPost.save()
            #Se agregan los tags
            words = input_to_words(request.POST['tags'])
            add_tags(words,request.POST['category'], newPost)
            #Download pictures
            pictures = download_picture(newPost.title)
            save_post_pictures(newPost,pictures)
            #Se anade un +1 al total_purchases del usario
            request.user.profile.add_purchases()
            #Se indexa al motor de busqueda searchify
            index_article(newPost)
            #Se agregan 5 puntos Positivos a quien publica la compra, Action 1
            add_points(request.user, POINTS_FOR_PUBLISH)
            return HttpResponseRedirect(str(newPost.get_url()) + '?new_post=True')
    else:
        form=ArticleForm()
    return render_to_response('article/post.html', {'form' : form }, context_instance = RequestContext(request))
예제 #2
0
파일: views.py 프로젝트: kayethano/howmuch
def assignment(request, articleID, candidateID):
    validate_assignment(articleID, request)
    article = get_object_or_404(Article, pk = articleID)
    offer = get_object_or_404(Offer, owner = candidateID, article = article)
    candidate = get_object_or_404(User, pk = candidateID)
    invoice = candidate.profile.get_current_invoice()
    #Formulario
    if request.method == 'POST':
        form = AssignmentForm(request.POST)
        if form.is_valid():
            newAssignment = form.save(commit=False)
            newAssignment.owner = candidate
            newAssignment.article = article
            newAssignment.save()
            #Articulo pasa a NO Activo
            article.is_active = False
            article.save()
            #Se genera un cargo a la factura del vendedor seleccionado
            generate_charge(newAssignment,offer.cprice, invoice)
            #Se checa la factura actual, si excede el limite, se asigna fecha limite de pago
            check_invoice(invoice)
            #Agregar puntos tanto al comprador por seleccionar, asi como al vendedor
            add_points(request.user, POINTS_FOR_SELECT)
            add_points(candidate, POINTS_FOR_ASSIGNMNET)
            #Enviar Notificacion
            NotificationOptions(newAssignment, 'assignment').send()
            
            return HttpResponseRedirect('/messages/' + str(newAssignment.conversation.pk))
    else:
        form = AssignmentForm()
    return render_to_response('article/assignment.html', {'form' : form, 'candidate' : candidate, 'article' : article }, 
        context_instance=RequestContext(request))
예제 #3
0
def post(request):
    from howmuch.tags.functions import input_to_words, add_tags
    #Si la cuenta de usuario esta bloqueada que lo indique
    if request.user.profile.is_block == True:
        return HttpResponse('Tu Cuenta esta bloqueada')
    #Formulario
    if request.method == 'POST':
        form = ArticleForm(request.POST)
        if form.is_valid():
            newPost = form.save(commit=False)
            newPost.owner = request.user
            #Se genera el campo url sustituyendo caracteres
            newPost.title_url = newPost.title.replace(u'\xf1',
                                                      'n').replace(' ', '-')
            newPost.save()
            #Se agregan los tags
            words = input_to_words(request.POST['tags'])
            add_tags(words, request.POST['category'], newPost)
            #Download pictures
            pictures = download_picture(newPost.title)
            save_post_pictures(newPost, pictures)
            #Se anade un +1 al total_purchases del usario
            request.user.profile.add_purchases()
            #Se indexa al motor de busqueda searchify
            index_article(newPost)
            #Se agregan 5 puntos Positivos a quien publica la compra, Action 1
            add_points(request.user, POINTS_FOR_PUBLISH)
            return HttpResponseRedirect(
                str(newPost.get_url()) + '?new_post=True')
    else:
        form = ArticleForm()
    return render_to_response('article/post.html', {'form': form},
                              context_instance=RequestContext(request))
예제 #4
0
def offer(request, articleID):
    #Si la cuenta de usuario esta bloqueada que lo indique
    if request.user.profile.is_block:
        return HttpResponse('Tu Cuenta esta bloqueada')
    #Validar que el Article exista, si no existe regresa error 404
    article = get_object_or_404(Article, pk=articleID)
    #Validar Offer
    errors = validate_offer(articleID, request.user)
    #Formulario
    if request.method == 'POST':
        form = OfferForm(request.POST, request.FILES)
        if form.is_valid():
            pictures = []
            quantity = form.cleaned_data['quantity']
            cprice = form.cleaned_data['cprice']
            message = form.cleaned_data['message']

            #Verifica cada campo de tipo input file, si el usuario lo uso, entonces lo agrega al diccionario para enseguida guardarlos
            pictures.append(form.cleaned_data['picture1'])
            if form.cleaned_data['picture2'] is not None:
                pictures.append(form.cleaned_data['picture2'])
            if form.cleaned_data['picture3'] is not None:
                pictures.append(form.cleaned_data['picture3'])
            if form.cleaned_data['picture4'] is not None:
                pictures.append(form.cleaned_data['picture4'])
            if form.cleaned_data['picture5'] is not None:
                pictures.append(form.cleaned_data['picture5'])

            thisOffer = Offer.objects.create(owner=request.user,
                                             article=article,
                                             quantity=quantity,
                                             cprice=cprice,
                                             message=message)
            thisOffer.save()

            #Guarda el diccionario de imagenes en thisOffer.pictures
            for picture in pictures:
                thisPicture = Picture(owner=request.user, picture=picture)
                thisPicture.save()
                thisOffer.pictures.add(thisPicture)
                thisOffer.save()

            #Se envia una notificacion
            NotificationOptions(thisOffer, 'offer').send()

            #Se agregan 5 puntos Positivos a quien realiza la oferta, Action 2
            add_points(request.user, POINTS_FOR_OFFER)

            return HttpResponseRedirect('/account/offers/')
    else:
        form = OfferForm()
    return render_to_response('article/offer.html', {
        'form': form,
        'article': article,
        'user': request.user,
        'errors': errors
    },
                              context_instance=RequestContext(request))
예제 #5
0
파일: views.py 프로젝트: kayethano/howmuch
def offer(request,articleID):
    #Si la cuenta de usuario esta bloqueada que lo indique
    if request.user.profile.is_block:
        return HttpResponse('Tu Cuenta esta bloqueada')
    #Validar que el Article exista, si no existe regresa error 404
    article = get_object_or_404(Article, pk = articleID)    
    #Validar Offer
    errors = validate_offer(articleID, request.user)
    #Formulario
    if request.method == 'POST':
        form = OfferForm(request.POST, request.FILES)
        if form.is_valid():
            pictures=[]
            quantity=form.cleaned_data['quantity'] 
            cprice = form.cleaned_data['cprice']
            message = form.cleaned_data['message']

            #Verifica cada campo de tipo input file, si el usuario lo uso, entonces lo agrega al diccionario para enseguida guardarlos
            pictures.append(form.cleaned_data['picture1'])
            if form.cleaned_data['picture2'] is not None:
                pictures.append(form.cleaned_data['picture2'])
            if form.cleaned_data['picture3'] is not None:
                pictures.append(form.cleaned_data['picture3'])
            if form.cleaned_data['picture4'] is not None:
                pictures.append(form.cleaned_data['picture4'])
            if form.cleaned_data['picture5'] is not None:
                pictures.append(form.cleaned_data['picture5'])

            thisOffer = Offer.objects.create(owner=request.user, article=article, quantity=quantity ,cprice=cprice, message=message)
            thisOffer.save()

            #Guarda el diccionario de imagenes en thisOffer.pictures
            for picture in pictures:
                thisPicture = Picture(owner = request.user, picture = picture)
                thisPicture.save()
                thisOffer.pictures.add(thisPicture)
                thisOffer.save()

            #Se envia una notificacion 
            NotificationOptions(thisOffer, 'offer').send()

            #Se agregan 5 puntos Positivos a quien realiza la oferta, Action 2
            add_points(request.user, POINTS_FOR_OFFER)

            return HttpResponseRedirect('/account/offers/')
    else:
        form = OfferForm()
    return render_to_response('article/offer.html', {'form' : form, 'article' : article, 
            'user' : request.user, 'errors':errors }, 
        context_instance=RequestContext(request))
예제 #6
0
def critique(request, assignmentID):
    assignment = get_object_or_404(Assignment, pk= assignmentID)
    #Valida que seas el Comprador o el vendedor para que puedas criticar
    if assignment.is_buyer(request.user):
        to = assignment.get_seller()
    elif assignment.is_seller(request.user):
        to = assignment.get_buyer()
    else:
        return HttpResponse("No tienes permiso para prestigiar a este usuario")
    #Se valida que esta critica no haya sido efectuado anteriormente
    try:
        Critique.objects.get(assignment = assignment, de = request.user)
    except Critique.DoesNotExist:
        pass
    else:
        return HttpResponse("Ya has criticado a tu socio, no puedes hacerlo nuevamente")

    if request.method == 'POST':
        form = CritiqueForm(request.POST)
        if form.is_valid():
            critique = form.save(commit = False)
            critique.de = request.user
            critique.to = to
            critique.assignment = assignment
            critique.save()
            #Se agregan puntos a quien critica
            add_points(request.user, POINTS_FOR_CRITIQUE)
            #Si la critica es positiva, se agregan 5 puntos, si es negativa se quitan 15 a la contraparte
            check_critique(critique,to)
            #Se verifica si la asignacion ya posee critica de la contraparte, en caso que si se pasa a 5, si no a 4
            if assignment.has_been_critiqued_before():
                assignment.status = "5"
                assignment.save()
                #Se actualiza el prestigio de los involucrados en la transaccion
                update_prestige(request.user)
                update_prestige(assignment.owner)
            elif assignment.status == "3":
                assignment.status = "4"
                assignment.save()
            #Se activa el sistema de Notificaciones
            NotificationOptions(critique, 'critique').send()                
            return HttpResponseRedirect('/messages/' + str(assignment.conversation.pk) )
    else:
        form =CritiqueForm()
    return render_to_response('prestige/critique.html' ,{
            'form' : form, 'assignment': assignment, 'to' : to }, 
        context_instance = RequestContext(request))
예제 #7
0
def assignment(request, articleID, candidateID):
    validate_assignment(articleID, request)
    article = get_object_or_404(Article, pk=articleID)
    offer = get_object_or_404(Offer, owner=candidateID, article=article)
    candidate = get_object_or_404(User, pk=candidateID)
    invoice = candidate.profile.get_current_invoice()
    #Formulario
    if request.method == 'POST':
        form = AssignmentForm(request.POST)
        if form.is_valid():
            newAssignment = form.save(commit=False)
            newAssignment.owner = candidate
            newAssignment.article = article
            newAssignment.save()
            #Articulo pasa a NO Activo
            article.is_active = False
            article.save()
            #Se genera un cargo a la factura del vendedor seleccionado
            generate_charge(newAssignment, offer.cprice, invoice)
            #Se checa la factura actual, si excede el limite, se asigna fecha limite de pago
            check_invoice(invoice)
            #Agregar puntos tanto al comprador por seleccionar, asi como al vendedor
            add_points(request.user, POINTS_FOR_SELECT)
            add_points(candidate, POINTS_FOR_ASSIGNMNET)
            #Enviar Notificacion
            NotificationOptions(newAssignment, 'assignment').send()

            return HttpResponseRedirect('/messages/' +
                                        str(newAssignment.conversation.pk))
    else:
        form = AssignmentForm()
    return render_to_response('article/assignment.html', {
        'form': form,
        'candidate': candidate,
        'article': article
    },
                              context_instance=RequestContext(request))