示例#1
0
 def test_home_page_returns_correct_html(self):
     from django.contrib.auth.forms import UserCreationForm
     from main.forms import UserProfileForm
     request = HttpRequest()
     response = homepage(request)
     expected_html = render_to_string('main/home.html',
                                      {'userform': UserCreationForm(),
                                       'profileform': UserProfileForm()})
     self.assertEqual(response.content.decode(), expected_html)
示例#2
0
def postdeleted(request):
    if request.user.is_authenticated():
	username = request.user.username
	newsid = request.POST.get("newsid")
	newstodelete = newsitem.objects.filter(id=request.POST.get("newsid"))
	newstodelete.delete()
	return homepage(request)
    else:
	return index(request)
示例#3
0
    def test_home_page_can_save_POST_request(self):
        request = HttpRequest()
        request.method = 'POST'
        request.POST['username'] = '******'

        response = homepage(request)

        self.assertEqual(response.status_code, 302)
        self.assertEqual(response['location'], '/?registration=success')
示例#4
0
    def test_home_page_can_save_POST_request(self):
        request = HttpRequest()
        request.method = 'POST'
        request.POST['username'] = '******'

        response = homepage(request)

        self.assertEqual(response.status_code, 302)
        self.assertEqual(response['location'], '/?registration=success')
示例#5
0
 def test_home_page_returns_correct_html(self):
     from django.contrib.auth.forms import UserCreationForm
     from main.forms import UserProfileForm
     request = HttpRequest()
     response = homepage(request)
     expected_html = render_to_string('main/home.html', {
         'userform': UserCreationForm(),
         'profileform': UserProfileForm()
     })
     self.assertEqual(response.content.decode(), expected_html)
示例#6
0
def savechanges(request):
    if request.user.is_authenticated():
	user = request.user
	user.first_name = request.POST.get('firstname')
	user.last_name = request.POST.get('lastname')
	user.email = request.POST.get('email')
	user.save()
	username = request.user.username
	return homepage(request)
    else:
	return index(request)
示例#7
0
def authenticater(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)
	    return homepage(request)
	else:
	    return HttpResponse("fail")
    else:
	return HttpResponse("login failed")
示例#8
0
def posttonews(request):
    if request.user.is_authenticated():
	username = request.user.username
	title = request.POST.get('title')
	newstext = request.POST.get('newstext')
	now = datetime.datetime.now()
	receiver = request.POST.get('receiver')
	if title == '':
	    return HttpResponse('please enter in a title for your fancy little news post')
	elif newstext == '':
	    return HttpResponse('your fancy little news post needs a news post, please type news into your news')
	else:
	    addnews = newsitem(user_name=username, news_title=title, news_body=newstext, pub_date=now, receiver_name=receiver)
	    addnews.save()
	    return homepage(request)
    else:
	return index(request)
示例#9
0
def index(request):
    if request.user.is_authenticated():
	return homepage(request)
    else:
        return render(request, 'login/index.html')