Beispiel #1
0
def list_screws(request):
    screws = ScrewListing.published.filter(screwed_at=None).order_by('-pub_date')
    profile = get_user_profile(request)
    
    needs_email = not request.user.email
    if request.method == 'POST':
        form = SubmitScreweeForm(request.POST, needs_email=needs_email)
        if form.is_valid():
            screw = form.save(commit=False)
            profile = get_user_profile(request)
            screw.screwee = profile
            screw.save()
            if needs_email:
                profile.user.email = form.cleaned_data['email']
                profile.save()
            form.save_m2m()
            # return HttpResponseRedirect(reverse(book_success))
            return HttpResponseRedirect(reverse(list_screws))
    else:
        form = SubmitScreweeForm(needs_email=needs_email)
    
    return render_to_response('listings/screw/list.html', {
        'screws': screws,
        'screwee': profile,
        'form': form,
        'user': profile,
    }, context_instance=RequestContext(request))
Beispiel #2
0
def establishment(request, slug):
    'View for "establishment" pages.'
    estab = get_object_or_404(Establishment, slug=slug)
    user = get_user_profile(request)

    if request.method == "POST":
        form = SubmitReviewForm(request.POST)
        if form.is_valid():
            try:
                review = estab.reviews.get(reviewer=user)
            except Review.DoesNotExist:
                review = Review(establishment=estab, reviewer=user)
            review.cost = form.cleaned_data["cost"]
            review.rating = form.cleaned_data["rating"]
            review.text = form.cleaned_data["text"]
            review.save()
            return HttpResponseRedirect(reverse(establishment, kwargs={"slug": slug}))
    else:
        try:
            review = estab.reviews.get(reviewer=user)
            form = SubmitReviewForm(review.__dict__)
        except Review.DoesNotExist:
            form = SubmitReviewForm()

    return render_to_response(
        "reviews/establishment.html",
        {"establishment": estab, "reviews": estab.reviews.exclude(reviewer=user), "form": form},
        context_instance=RequestContext(request),
    )
Beispiel #3
0
def concept_save_page(request, template="staff/submit.html"):
    if request.method == 'POST':
        form = ConceptSaveForm(request.POST)
        if form.is_valid():
            if form.cleaned_data['due']:
                due = form.cleaned_data['due']
            else:
                due = ""
                
            if form.cleaned_data['notes']:
                notes = form.cleaned_data['notes']
            else:
                notes = ""
            name = form.cleaned_data['name']
            
            concept = StoryConcept.objects.get(name=name)
            
            concept.due = due
            concept.notes = notes
            
            concept.save()
            
            user = get_user_profile(request)
            personal, claimed, unclaimed = StoryConcept.unpublished.get_concepts(user=user)
            admin_announcement = Announcement.admin.latest()
            newform = SubmitStoryConcept()
            data = {
                'form': newform,
                'minutes': admin_announcement,
                'personal': personal,
                'unclaimed': unclaimed,
                'claimed': [concept],
                'author': user,
        		'unpublished_stories': Article.objects.exclude(status='p')
            }
            rc = RequestContext(request)
            return render_to_response("staff/index.html", data, context_instance=rc)
        else:
            return HttpResponse('failure')
    elif request.GET.has_key('name'):
        story_name = request.GET.get('name')
        concept = StoryConcept.objects.get(name=story_name)
        
        form = ConceptSaveForm(
            initial={
                'name': concept.name,
                'due': concept.due,
                'notes': concept.notes
            }
        )
        data = {
            'form': form,
        }
        rc = RequestContext(request)
        return render_to_response("staff/concept_save_form.html", data, context_instance=rc)
    else:
        form = ConceptSaveForm()
        data = { 'form': form }
        rc = RequestContext(request)
        return render_to_response(template, data, context_instance=rc)
Beispiel #4
0
def submit_poll(request, year=None, slug=None):
    if request.method != 'POST':
        return HttpResponse('POST or gtfo')
    else:
        print repr(request.POST['option'])
        poll = get_object_or_404(Poll, time_start__year=year, slug=slug)
        
        ip = get_ip(request)
        user = get_user_profile(request)
        
        option_pk = request.POST['option']
        try:
            option = poll.options.get(pk=option_pk)
        except:
            return HttpResponse('error: invalid option "%s"' % option_pk)
        
        try:
            poll.vote(option=option, user=user, ip=ip)
        except gazjango.polls.exceptions.NotVoting:
            return HttpResponse("This poll is not accepting votes at this time.")
        except gazjango.polls.exceptions.AlreadyVoted:
            return HttpResponse("You've already voted in this poll.")
        except gazjango.polls.exceptions.PermissionDenied:
            return HttpResponse("You're not allowed to vote in this poll.")
        except Exception, e:
            return HttpResponse("Unknown problem: " + repr(e))
        else:
Beispiel #5
0
def show_article(request, story, form, print_view=False):
    "Shows the requested article."
    d = story.pub_date
    template = (
        "stories/view_%s_%s_%s_%s.html" % (d.year, d.month, d.day, story.slug),
        "stories/view_from_sub_%s.html" % story.subsection.slug if story.subsection else '',
        "stories/view_from_sec_%s.html" % story.section.slug,
        "stories/view.html"
    )
    
    cs = PublicComment.visible.order_by('-time').exclude(article=story)
    
    user = get_user_profile(request)
    ip = get_ip(request)
    comments = PublicComment.objects.for_article(story, user, ip)
    
    context = RequestContext(request, {
        'story': story,
        'comments': comments,
        'print_view': print_view,
        'comment_form': form,
        'poster': Poster.published.get_running(),
        'recent_stories': Article.published.order_by('-pub_date')[:3],
        'related': story.related_list(3),
        
        'top_banner': BannerAd.article_top.pick(allow_zero_priority=False),
        'side_banner': BannerAd.article_side.pick(allow_zero_priority=False),
    })
    return render_to_response(template, context_instance=context)
Beispiel #6
0
def page(request, url):
    'View for "stacked" pages.'
    
    if not url.endswith('/') and settings.APPEND_SLASH:
        url += '/'
    if not url.startswith('/'):
        url = '/' + url
    
    page = get_object_or_404(Page, url__exact=url, sites__id__exact=settings.SITE_ID)
    
    if page.staff_only:
        user = get_user_profile(request)
        if not user.is_staff:
            raise Http404
    
    page.title = mark_safe(page.title)
    page.content = mark_safe(page.formatted_content())
    
    if page.template_name:
        template = (f.template_name, DEFAULT_TEMPLATE)
    else:
        template = DEFAULT_TEMPLATE
    
    tops, mids, lows = Article.published.get_stories(num_top=1, num_mid=3, num_low=0)
    rc = RequestContext(request)
    context = {
        'page': page,
        'topstory': tops[0],
        'stories': mids,
        'comments': PublicComment.visible.order_by('-time')[:3],
        'poster': Poster.published.get_running(),
    }
    
    return render_to_response(template, context, context_instance=rc)
Beispiel #7
0
def submit_poster(request, template="listings/posters/submit.html"):
    if request.method == 'POST':
        form = SubmitPosterForm(request.POST, request.FILES)
        if form.is_valid():
            profile = get_user_profile(request)
            
            args = dict( (k, v) for k, v in form.cleaned_data.items() if k != 'poster' )
            poster = Poster(**args)
            poster.sponsor_user = profile
            
            poster_file_path = handle_file_upload(request.FILES['poster'], 'posters')
            poster.poster = ImageFile.objects.create(
                name = poster.title,
                slug = slugify(poster.title),
                bucket = MediaBucket.objects.get_or_create(slug="posters", defaults={
                    'name': "Posters",
                    'description': "Posters uploaded by the community."
                })[0],
                license_type='p',
                data=poster_file_path,
            )
            poster.poster.users = [profile]
            
            poster.save()
            return HttpResponseRedirect(reverse(poster_success))
    else:
        form = SubmitPosterForm()
    
    return render_to_response(template, context_instance=RequestContext(request, {
        'form': form,
        'poster': Poster.published.get_running(),
    }))
Beispiel #8
0
def list_books(request):
    books = BookListing.published.filter(sold_at=None).order_by('-pub_date')
    profile = get_user_profile(request)
    
    return render_to_response('listings/books/list.html', {
        'books': books,
        'user_profile': profile,
    }, context_instance=RequestContext(request))
Beispiel #9
0
def subscribe(request):
    profile = get_user_profile(request)
    if profile.kind:
        racy = profile.kind.kind in 'sk'
    else:
        racy = False
    Subscriber.objects.create(receive='i', user=profile, racy_content=racy)
    return HttpResponseRedirect('/accounts/manage/')
Beispiel #10
0
def post_comment(request, slug, year, month, day):
    story = get_by_date_or_404(Article, year, month, day, slug=slug)
    if not story.comments_allowed:
        raise Http404 # semantically incorrect, but whatever
    
    logged_in = request.user.is_authenticated()
    staff = logged_in and get_user_profile(request).staff_status()
    form = make_comment_form(data=request.POST, logged_in=logged_in, staff=staff)
    
    if form.is_valid():
        data = form.cleaned_data
        args = {
            'subject': story,
            'text': escape(data['text']).replace("\n", "<br/>"),
            'ip_address': get_ip(request),
            'user_agent': request.META.get('HTTP_USER_AGENT', '')
        }
        
        if logged_in:
            args['user'] = get_user_profile(request)
            if data['anonymous']:# and data['name'] != request.user.get_full_name():
                args['name'] = data['name']
            args['speaking_officially'] = data['speaking_officially']
        else:
            args['name']  = data['name']
            args['email'] = data['email']
        
        try:
            comment = PublicComment.objects.new(**args)    
        except CommentIsSpam, e:
            # put data in the session, because we're silly like that
            url = e.comment.subject.get_absolute_url()
            request.session.set_expiry(0)
            request.session['comment:%s' % url] = e.comment
            
            # NOTE: coupling with url for comment captchas
            redirect = request.build_absolute_uri(url + 'comment/captcha')
            if request.is_ajax():
                return HttpResponse('redirect: %s' % redirect)
            else:
                return HttpResponseRedirect(redirect)
        
        if request.is_ajax():
            return HttpResponse('success')
        else:
            return HttpResponseRedirect(comment.get_absolute_url())
Beispiel #11
0
def manage(request, template="accounts/manage.html"):
    profile = get_user_profile(request)
    subscribers = Subscriber.issues.filter(user=profile)

    rc = RequestContext(request, {
            'subscriber': subscribers[0] if subscribers else None,
        })
    return render_to_response(template, context_instance=rc)
Beispiel #12
0
def list_housing(request):
    housing = HousingListing.published.order_by('-pub_date')
    profile = get_user_profile(request)
    
    newuser = True
    if profile:
        for listing in housing:
            if listing.student == profile:
                newuser = False
    
    if profile:
        needs_email = not request.user.email
        needs_name  = not request.user.get_full_name()
        if request.method == 'POST':
            form = SubmitHousingForm(request.POST, needs_email=needs_email, needs_name=needs_name)
            if form.is_valid():
                submission = form.save(commit=False)
                profile = get_user_profile(request)
                submission.student = profile
                submission.save()
                if needs_email:
                    profile.user.email = form.cleaned_data['email']
                if needs_name:
                    names = (form.cleaned_data['name'] + ' ').split(' ', 1)
                    profile.user.first_name, profile.user.last_name = names
                if needs_email or needs_name:
                    profile.user.save()
                    profile.save()
                form.save_m2m()
                return HttpResponseRedirect(reverse(list_housing))
        else:
            form = SubmitHousingForm(needs_email=needs_email,needs_name=needs_name)
    else:
        form = SubmitHousingForm(needs_email=False,needs_name=False)
    
    return render_to_response('listings/housing/list.html', {
        'housing': housing,
        'form': form,
        'person': profile,
        'newuser': newuser,
        'GMAPS_API_KEY': settings.GMAPS_API_KEY,
    }, context_instance=RequestContext(request))
Beispiel #13
0
def vote_on_comment(request, slug, year, month, day, num, val):
    if is_robot(request):
        return HttpResponse('sorry, you seem to be a robot, no voting for you!')
    
    comment = _get_comment_or_404(year, month, day, slug, num)
    positive = (val == 'up') if val in ('up', 'down') else None
    result = comment.vote(positive, ip=get_ip(request), user=get_user_profile(request))
    
    if request.is_ajax():
        return HttpResponse("success" if result else "failure")
    else:
        return HttpResponseRedirect(comment.get_absolute_url())
Beispiel #14
0
def specific_article(request, story, num=None, form=None, print_view=False):
    "Displays an article without searching the db for it."
    
    logged_in = request.user.is_authenticated()
    if form is None:
        initial = { 'text': 'Have your say.' }
        if logged_in:
            initial['name'] = request.user.get_full_name()
        staff = logged_in and get_user_profile(request).staff_status()
        form = make_comment_form(logged_in=logged_in, initial=initial, staff=staff)

    if story.is_swat_only():
        if not is_from_swat(user=get_user_profile(request), ip=get_ip(request)):
            return show_swat_only(request, story)
    
    try:
        photospread = story.photospread
    except PhotoSpread.DoesNotExist:
        return show_article(request, story, form, print_view)
    else:
        return show_photospread_page(request, photospread, num, form)
Beispiel #15
0
def comments_for_article(request, slug, year, month, day, num=None):
    """
    Returns the comments for the specified article, rendered as they are
    on article view pages, starting after number `num`. Used for after
    you've posted an AJAX comment.
    """
    story = get_by_date_or_404(Article, year, month, day, slug=slug)
    
    user = get_user_profile(request)
    ip = get_ip(request)
    
    spec = Q(number__gt=num) if num else Q()
    comments = PublicComment.objects.for_article(story, user, ip, spec=spec)
    
    rc = RequestContext(request, { 'comments': comments, 'new': True })
    return render_to_response("stories/comments.html", context_instance=rc)
Beispiel #16
0
def mark_as_screwed(request, slug):
    screw = get_object_or_404(ScrewListing, slug=slug)
    profile = get_user_profile(request)
    
    if profile and profile == screw.screwee:
        screw.screwed_at = datetime.datetime.now()
        screw.save()
        if request.is_ajax():
            return HttpResponse('success')
        else:
            return HttpResponseRedirect(reverse(list_screws))
    else:
        if request.is_ajax():
            return 'denied'
        else:
            raise Http404
Beispiel #17
0
def mark_as_sold(request, slug):
    book = get_object_or_404(BookListing, slug=slug)
    profile = get_user_profile(request)
    
    if profile and profile == book.seller:
        book.sold_at = datetime.datetime.now()
        book.save()
        if request.is_ajax():
            return HttpResponse('success')
        else:
            return HttpResponseRedirect(reverse(list_books))
    else:
        if request.is_ajax():
            return 'denied'
        else:
            raise Http404
Beispiel #18
0
def show_photospread_page(request, spread, num=None, form=None, whole_page=None):
    if num is None:
        num = 1
    
    page = spread.get_photo_number(num)
    if not page:
        raise Http404('This photospread does not have a photo number "%s".' % num)
    
    data = {
        'story': spread,
        'page': page,
        'next': page.next(),
        'prev': page.prev()
    }
    
    if whole_page is None:
        whole_page = not request.is_ajax()
    
    user = get_user_profile(request)
    ip = get_ip(request)
    
    if whole_page:
        data.update(
            comments=PublicComment.objects.for_article(spread, user, ip),
            comment_form=form,

            poster=Poster.published.get_running(),
            recent_stories=Article.published.order_by('-pub_date')[:3],
            related=spread.related_list(3),

            top_banner=BannerAd.article_top.pick(allow_zero_priority=False),
            side_banner=BannerAd.article_side.pick(allow_zero_priority=False),
        )

        d = spread.pub_date
        template = (
            "stories/photospread_%s_%s_%s_%s.html" % (d.year, d.month, d.day, spread.slug),
            "stories/photospread_from_sub_%s.html" % spread.subsection.slug if spread.subsection else '',
            "stories/photospread_from_sec_%s.html" % spread.section.slug,
            "stories/photospread.html"
        )
    else:
        template = "stories/photo.html"
    
    rc = RequestContext(request, data)
    return render_to_response(template, context_instance=rc)
Beispiel #19
0
def submit_book(request):
    needs_email = not request.user.email
    if request.method == 'POST':
        form = SubmitBookForm(request.POST, needs_email=needs_email)
        if form.is_valid():
            book = form.save(commit=False)
            profile = get_user_profile(request)
            book.seller = profile
            book.save()
            if needs_email:
                profile.user.email = form.cleaned_data['email']
                profile.user.save()
            form.save_m2m()
            # return HttpResponseRedirect(reverse(book_success))
            return HttpResponseRedirect(reverse(list_books))
    else:
        form = SubmitBookForm(needs_email=needs_email)
    
    return render_to_response('listings/books/submit.html', {
        'form': form,
        'poster': Poster.published.get_running(),
    }, context_instance=RequestContext(request))
Beispiel #20
0
def staff(request,  template="staff/index.html"):
    user = get_user_profile(request)
    personal, claimed, unclaimed = StoryConcept.unpublished.get_concepts(user=user)
    admin_announcement = Announcement.admin.latest()
    if request.method == 'POST':
        form = SubmitStoryConcept(request.POST)
        if form.is_valid():
            concept = form.save(commit=False)
            concept.save()
            form.save_m2m()
            return HttpResponseRedirect(reverse(staff))
    else:
        form = SubmitStoryConcept()
    data = {
        'form': form,
        'minutes': admin_announcement,
        'personal': personal,
        'unclaimed': unclaimed,
        'claimed': claimed,
        'author': user,
		'unpublished_stories': Article.objects.exclude(status='p')
    }
    rc = RequestContext(request)
    return render_to_response(template, data, context_instance=rc)
Beispiel #21
0
def unsubscribe(request):
    profile = get_user_profile(request)
    today = datetime.datetime.today()
    Subscriber.issues.filter(user=profile).update(unsubscribed=today)
    return HttpResponseRedirect('/accounts/manage/')
Beispiel #22
0
def racy_switch(request, val):
    profile = get_user_profile(request)
    Subscriber.issues.filter(user=profile).update(racy_content=(val == "on"))
    return HttpResponseRedirect('/accounts/manage/')
Beispiel #23
0
 def associate_profile(self, request):
     profile = get_user_profile(request)
     profile.facebook_id = self.cookie(request, '_user')
     profile.save()
     self.facebook_user_is_authenticated = True
     request.facebook_user = request.user