Ejemplo n.º 1
0
def write_ticker_history(request, pk=False):
	ticker_form = generate_form(request, TickerHistory, TickerHistoryForm, pk)
	if ticker_form.is_valid():
		tf = ticker_form.save()
		messages.success(request, u'Ticker history added/updated with ID=%s' % tf.pk)
		set_redirect_session(request, 'app_stocks', {})
		return HttpResponseRedirect(get_previous_page(request, APP_NAME))

	if pk:
		request.session['redirect_next'] = safe_referrer(request)
		try:
			header_text = "Redigere markedspris"
			delete_link_pk = pk
			redirect_url = None
		except:
			return Http404
	else:
		header_text = u'Ny markedspris'
		redirect_url = None
		delete_link_pk = None

	return render(request, 'stocks_edit.html', {
		u'form': ticker_form,
		u'header_text': header_text,
		u'redirect': redirect_url,
		u'delete_link_name': "stocks_ticker_remove",
		u'delete_link_pk': delete_link_pk,
	})
Ejemplo n.º 2
0
def img_remove(request, image_id):

    try:
        image = models.Image.objects.get(pk=image_id)
    except:
        messages.error(request, 'Image ID could not be found')

    if request.method == "POST":
        images_remove(request, image_id)
        request.session['redirect_next'] = safe_referrer(request)
        return HttpResponseRedirect(
            reverse('image_upload', args=[image.blog.pk]))
    else:
        return render(request, 'image_delete.html', {
            u'image': image,
        })
Ejemplo n.º 3
0
def delete_blog_comment(request, comment_pk):
    csrf_token = csrf.get_token(request)
    request_token = request.GET.get('token')
    if request_token == csrf_token:
        try:
            comment = models.Comment.objects.get(pk=comment_pk)
            comment.delete()
            messages.success(request, 'Commet was deleted!')
        except:
            messages.error(request, 'Comment could not be deleted')
        request.session['redirect_next'] = safe_referrer(request)
        return HttpResponseRedirect(get_previous_page(request, APP_NAME))
    else:
        messages.error(request, u'Token did not match')

    return HttpResponseRedirect(get_previous_page(request, APP_NAME))
Ejemplo n.º 4
0
def user_login(request):
    form = LoginForm()
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            if form.cleaned_data:
                if user_not_blocked(request):
                    username = request.POST['username']
                    password = request.POST['password']
                    user = authenticate(username=username, password=password)
                    if user is not None:
                        if user.is_active:
                            login(request, user)
                            user_name = user.get_full_name()
                            if user_name == '':
                                user_name = request.user
                            messages.success(
                                request,
                                'You are logged in as %s.' % user_name)
                            add_to_log(request,
                                       "Successful user authentication")
                            return HttpResponseRedirect(
                                get_previous_page(request, 'root'))
                        else:
                            messages.error(request, 'Your are disabled.')
                            add_to_log(
                                request,
                                "Successful user authentication, but account is blocked",
                                1)
                    else:
                        messages.error(request,
                                       'I could not verify your identity.')
                        log_message = "Failed attempt at authentication (%s)" % username
                        add_to_log(request, log_message, 2)
                else:
                    messages.error(request,
                                   'I could not verify your identity.')
                    log_message = "IP %s was blocked" % get_client_ip(request)
                    add_to_log(request, log_message, 1)

    request.session['redirect_next'] = safe_referrer(request)
    return render(request, 'login.html', {
        'form': form,
    })
Ejemplo n.º 5
0
def file_remove(request, blog_id, file_id):
    file_unlink(request, blog_id, file_id)
    request.session['redirect_next'] = safe_referrer(request)
    return HttpResponseRedirect(get_previous_page(request, APP_NAME))
Ejemplo n.º 6
0
def user_logout(request):
    logout(request)
    messages.info(request, 'Your session has been destroyed.')
    return HttpResponseRedirect(safe_referrer(request))