def news_add(request): if not 'news.add_news' in request.user.get_all_permissions(): return cnq_render_to_response('error.html', request, { 'error_message': "You are not allowed to add news items.", }) # Nothing was POSTed? Just display the form. if not 'news_title' in request.POST: return cnq_render_to_response('news_add.html', request, { }) # News was POSTed. Try to add it. error_message = "" if len(request.POST['news_title']) == 0: error_message = "Please enter the news title." elif len(request.POST['news_text']) == 0: error_message = "Please enter the news text." if len(error_message) > 0: return cnq_render_to_response('news_add.html', request, { 'body_top_error': error_message, 'news_text': request.POST['news_text'], 'news_title': request.POST['news_title'], }) n = News() n.title = request.POST['news_title'] n.text = request.POST['news_text'] n.added_by = request.user n.save() # We should redirect to /news/<new_id>/ here, with possibly the # message "Quote added" at the top. return HttpResponseRedirect("/news/")
def quote_add(request): # Nothing was POSTed? Just display the form. if not "quote_title" in request.POST: return cnq_render_to_response("quote_add.html", request, {}) # A quote was POSTed. Try to add it. error_message = "" if len(request.POST["quote_title"]) == 0: error_message = "Please enter the quote's title." elif len(request.POST["quote_text"]) == 0: error_message = "Please enter the quote's text." if len(error_message) > 0: return cnq_render_to_response( "quote_add.html", request, { "body_top_error": error_message, "quote_text": request.POST["quote_text"], "quote_title": request.POST["quote_title"], }, ) q = Quote() q.title = request.POST["quote_title"] q.text = request.POST["quote_text"] q.added_by = request.user q.save() # We should redirect to /quotes/<new_id>/ here, with possibly the # message "Quote added" at the top. return HttpResponseRedirect("/quotes/%d/" % q.id)
def quote_add(request): # Nothing was POSTed? Just display the form. if not 'quote_title' in request.POST: return cnq_render_to_response('quote_add.html', request, {}) # A quote was POSTed. Try to add it. error_message = "" if len(request.POST['quote_title']) == 0: error_message = "Please enter the quote's title." elif len(request.POST['quote_text']) == 0: error_message = "Please enter the quote's text." if len(error_message) > 0: return cnq_render_to_response( 'quote_add.html', request, { 'body_top_error': error_message, 'quote_text': request.POST['quote_text'], 'quote_title': request.POST['quote_title'], }) q = Quote() q.title = request.POST['quote_title'] q.text = request.POST['quote_text'] q.added_by = request.user q.save() # We should redirect to /quotes/<new_id>/ here, with possibly the # message "Quote added" at the top. return HttpResponseRedirect("/quotes/%d/" % q.id)
def quotes_view(request): page_number = request.GET.get("p") if page_number: page_number = int(page_number) else: page_number = 1 order_by = request.GET.get("o") search_term = request.GET.get("q") quotes = Quote.objects if search_term: quotes = quotes.filter(text__icontains=search_term) if order_by and order_by == "score": quotes = quotes.order_by("-score", "-id").all() else: quotes = quotes.order_by("-id").all() if not len(quotes): return cnq_render_to_response("quotes_none_found.html", request, {"search_term": search_term}) result = _get_page_of_quotes(quotes, page_number) quote_url = reverse(quotes_view) get_params = [] if search_term: get_params.append("q=%s" % urlquote(search_term)) if order_by: get_params.append("o=%s" % order_by) addition = "&".join(get_params) quote_url += "?%s" % addition if addition: quote_url += "&" return cnq_render_to_response( "quote_page.html", request, { "quote_list": result["paged_quotes"], "search_term": search_term or "", "pager_data": { "first_page": 1, "previous_page": result["previous_page"], "current_page": page_number, "next_page": result["next_page"], "last_page": result["num_pages"], "close_nav": result["close_nav"], "url": quote_url, }, }, )
def quotes_view(request): page_number = request.GET.get('p') if page_number: page_number = int(page_number) else: page_number = 1 order_by = request.GET.get('o') search_term = request.GET.get('q') quotes = Quote.objects if search_term: quotes = quotes.filter(text__icontains=search_term) if order_by and order_by == 'score': quotes = quotes.order_by('-score', '-id').all() else: quotes = quotes.order_by('-id').all() if not len(quotes): return cnq_render_to_response('quotes_none_found.html', request, { 'search_term': search_term, }) result = _get_page_of_quotes(quotes, page_number) quote_url = reverse(quotes_view) get_params = [] if search_term: get_params.append("q=%s" % urlquote(search_term)) if order_by: get_params.append("o=%s" % order_by) addition = '&'.join(get_params) quote_url += "?%s" % addition if addition: quote_url += '&' return cnq_render_to_response( 'quote_page.html', request, { 'quote_list': result['paged_quotes'], 'search_term': search_term or '', 'pager_data': { 'first_page': 1, 'previous_page': result['previous_page'], 'current_page': page_number, 'next_page': result['next_page'], 'last_page': result['num_pages'], 'close_nav': result['close_nav'], 'url': quote_url, } })
def profile_edit(request, username): u = get_carnique_user(username) if not u: raise Http404() editing_user = request.user profile_raw = u.get_profile().text profile_html = convert_bb_to_html(profile_raw) if not _can_edit_profile(username, editing_user): return cnq_render_to_response( 'profile.html', request, { 'puser': u, 'profile_text': profile_html, 'body_top_error': 'You cannot edit this profile.', }) if not 'profile_birthday' in request.POST: return cnq_render_to_response('profile_edit.html', request, { 'puser': u, 'profile': u.get_profile(), 'profile_text': profile_raw, }) # Verify and commit changes if u.get_profile().text != request.POST['profile_text']: u.get_profile().text = request.POST['profile_text'] u.get_profile().last_updated = datetime.datetime.now() u.get_profile().realname = request.POST['profile_realname'] u.get_profile().location = request.POST['profile_location'] u.get_profile().twitter_username = request.POST['profile_twitter_username'] u.get_profile().blog_url = request.POST['profile_blog_url'] u.get_profile().blog_name = request.POST['profile_blog_name'] if request.POST['profile_birthday']: u.get_profile().birthday = request.POST['profile_birthday'] u.save() u.get_profile().save() profile_text = convert_bb_to_html(u.get_profile().text) return cnq_render_to_response( 'profile.html', request, { 'puser': u, 'profile_birthday': u.get_profile().birthday, 'profile': u.get_profile(), 'profile_text': profile_text, 'body_top_message': 'The changes to your profile have been saved.', })
def profile_edit(request, username): u = get_carnique_user(username) if not u: raise Http404() editing_user = request.user profile_raw = u.get_profile().text profile_html = convert_bb_to_html(profile_raw) if not _can_edit_profile(username, editing_user): return cnq_render_to_response('profile.html', request, { 'puser': u, 'profile_text': profile_html, 'body_top_error': 'You cannot edit this profile.', }) if not 'profile_birthday' in request.POST: return cnq_render_to_response('profile_edit.html', request, { 'puser': u, 'profile': u.get_profile(), 'profile_text': profile_raw, }) # Verify and commit changes if u.get_profile().text != request.POST['profile_text']: u.get_profile().text = request.POST['profile_text'] u.get_profile().last_updated = datetime.datetime.now() u.get_profile().realname = request.POST['profile_realname'] u.get_profile().location = request.POST['profile_location'] u.get_profile().twitter_username = request.POST['profile_twitter_username'] u.get_profile().blog_url = request.POST['profile_blog_url'] u.get_profile().blog_name = request.POST['profile_blog_name'] if request.POST['profile_birthday']: u.get_profile().birthday = request.POST['profile_birthday'] u.save() u.get_profile().save() profile_text = convert_bb_to_html(u.get_profile().text) return cnq_render_to_response('profile.html', request, { 'puser': u, 'profile_birthday': u.get_profile().birthday, 'profile': u.get_profile(), 'profile_text': profile_text, 'body_top_message': 'The changes to your profile have been saved.', })
def quote_vote_down(request, quote_id): quote = get_object_or_404(Quote, pk=quote_id) if not _already_voted(quote, request): _vote(quote, request, -1) return cnq_render_to_response("quote.html", request, {"quote": quote, "quote_text": convert_bb_to_html(quote.text)})
def quote_view(request, quote_id): q = get_object_or_404(Quote, pk=quote_id) return cnq_render_to_response('quote.html', request, { 'quote': q, 'quote_text': convert_bb_to_html(q.text), })
def quote_view_random(request): num_quotes = Quote.objects.count() q = Quote.objects.all()[randint(0, num_quotes - 1)] return cnq_render_to_response('quote.html', request, { 'quote': q, 'quote_text': convert_bb_to_html(q.text), })
def quote_vote_down(request, quote_id): quote = get_object_or_404(Quote, pk=quote_id) if not _already_voted(quote, request): _vote(quote, request, -1) return cnq_render_to_response('quote.html', request, { 'quote': quote, 'quote_text': convert_bb_to_html(quote.text), })
def news_list(request): news = News.objects.order_by('-id').all() can_add_news = False if request.user.is_authenticated: if request.user.has_perm('main.add_news'): can_add_news = True return cnq_render_to_response('news_list.html', request, { 'news_list': news, 'can_add_news': can_add_news, })
def profile_view(request, username): u = get_carnique_user(username) if not u: raise Http404() profile_text = convert_bb_to_html(u.get_profile().text) return cnq_render_to_response('profile.html', request, { 'puser': u, 'profile_text': profile_text, })
def news_list(request): news = News.objects.order_by('-id').all() can_add_news = False if request.user.is_authenticated: if request.user.has_perm('main.add_news'): can_add_news = True return cnq_render_to_response('news_list.html', request, { 'news_list': news, 'can_add_news': can_add_news, })
def profile_view(request, username): u = get_carnique_user(username) if not u: raise Http404() profile_text = convert_bb_to_html(u.get_profile().text) return cnq_render_to_response('profile.html', request, { 'puser': u, 'profile_text': profile_text, })
def news_add(request): if not 'news.add_news' in request.user.get_all_permissions(): return cnq_render_to_response( 'error.html', request, { 'error_message': "You are not allowed to add news items.", }) # Nothing was POSTed? Just display the form. if not 'news_title' in request.POST: return cnq_render_to_response('news_add.html', request, {}) # News was POSTed. Try to add it. error_message = "" if len(request.POST['news_title']) == 0: error_message = "Please enter the news title." elif len(request.POST['news_text']) == 0: error_message = "Please enter the news text." if len(error_message) > 0: return cnq_render_to_response( 'news_add.html', request, { 'body_top_error': error_message, 'news_text': request.POST['news_text'], 'news_title': request.POST['news_title'], }) n = News() n.title = request.POST['news_title'] n.text = request.POST['news_text'] n.added_by = request.user n.save() # We should redirect to /news/<new_id>/ here, with possibly the # message "Quote added" at the top. return HttpResponseRedirect("/news/")
def quote_view_random(request): num_quotes = Quote.objects.count() q = Quote.objects.all()[randint(0, num_quotes - 1)] return cnq_render_to_response("quote.html", request, {"quote": q, "quote_text": convert_bb_to_html(q.text)})
def quote_view(request, quote_id): q = get_object_or_404(Quote, pk=quote_id) return cnq_render_to_response("quote.html", request, {"quote": q, "quote_text": convert_bb_to_html(q.text)})