Esempio n. 1
0
def delete_ad(request, identifier):

    authenticate(request, VALID_FACTORS)
    ispm = request.user.is_posts_mod()

    ad = Post.objects.get(id=identifier)
    if request.user == ad.creator or ispm:
        ad.delete()
        update_daysElapsed()
        update_scores()
        return HttpResponseRedirect("/webapps/classifieds/deleted/")
    else:
        return HttpResponseRedirect("/webapps/classifieds/")
Esempio n. 2
0
def create_ad(request):

    authenticate(request, VALID_FACTORS)

    if request.method == "POST":
        form = AdForm(request.POST)
        creator = request.META["REMOTE_USER"]
        ad_creator = request.user
        if form.is_valid():
            cd = form.cleaned_data
            num_ads = len(list(Post.objects.all()))
            update_ranks()
            ad = Post(
                title=cd["title"],
                text=cd["text"],
                category=cd["category"],
                creator_email=cd["email"],
                creator_phone=cd["phone"],
                sub_category="foo",
                creator=ad_creator,
                timestamp=datetime.today().date(),
                daysElapsed=0,
                upvotes=0,
                downvotes=0,
                score=100,
                rank=num_ads + 1,
            )
            ad.save()
            update_daysElapsed()
            update_scores()
            update_ranks()
            return HttpResponseRedirect("/webapps/classifieds/thanks/")
        else:
            return render_to_response(
                "classifieds/new_ad_form.phtml",
                {"form": form, "category": "New Post"},
                context_instance=RequestContext(request),
            )
    else:
        form = AdForm()

    return render_to_response(
        "classifieds/new_ad_form.phtml",
        {"form": form, "category": "New Post"},
        context_instance=RequestContext(request),
    )
Esempio n. 3
0
def edit_ad(request, identifier):

    authenticate(request, VALID_FACTORS)

    ad = Post.objects.get(id=identifier)
    if request.method == "POST":
        form = AdForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            ad.category = cd["category"]
            ad.title = cd["title"]
            ad.text = cd["text"]
            ad.timestamp = datetime.today().date()
            ad.daysElapsed = 0
            ad.creator_email = cd["email"]
            ad.creator_phone = cd["phone"]
            ad.save()
            update_daysElapsed()
            update_scores()
            return HttpResponseRedirect("/webapps/classifieds/thanks/")
        else:
            return render_to_response(
                "classifieds/edit_ad_form.phtml", {"form": form}, context_instance=RequestContext(request)
            )
    else:
        form = AdForm(
            initial={
                "title": ad.title,
                "text": ad.text,
                "category": ad.category,
                "sub_category": ad.sub_category,
                "email": ad.creator_email,
                "phone": ad.creator_phone,
            }
        )
    return render_to_response(
        "classifieds/edit_ad_form.phtml", {"form": form}, context_instance=RequestContext(request)
    )