From 782a6e15d2e4ab7f23a16284a840261860d2718a Mon Sep 17 00:00:00 2001 From: Kris Lamoureux Date: Sun, 14 Oct 2012 06:21:53 -0700 Subject: [PATCH] Added custom title pages. Added variable: "basetitle" to the config file which sets the title on index, login and registration pages as well as the admin pages. I then moved the code that connects to the SMTP server to above where the user is created in registration. I did this because if the connection fails then it wont continue and create a user that wont be able get an activation link. I also adjusted some indentions to make it easier to read on github.com --- config.txt | 21 ++-- myproject/myproject/settings.py | 1 + .../myproject/templates/admin/base_site.html | 4 +- myproject/myproject/views.py | 118 ++++++++++-------- 4 files changed, 80 insertions(+), 64 deletions(-) diff --git a/config.txt b/config.txt index b35eeb2..e85ef9a 100644 --- a/config.txt +++ b/config.txt @@ -10,6 +10,7 @@ // CUSTOM VARIABLES v baseurl http://127.0.0.1:8000 +v basetitle DJ-BaseSite v admin_name Kris619 v admin_email KrisPublicEmail@gmail.com @@ -38,7 +39,9 @@ v HOSTpass HereItIs_HaveMyAccount // !!!!!!HEY, PAY ATTENTION FOR A SECOND!!!!!! // Don't mess with anything below unless you -// know what you are doing. +// know what you are doing. You can easily +// crash the Setup by putting things in the +// wrong order. // DYNAMIC FILES %here%/myproject/manage.py 1 @@ -47,6 +50,14 @@ v HOSTpass HereItIs_HaveMyAccount %here%/myproject/myproject/urls.py 1 %here%/myproject/manage.py 1 +// Add these dir commands before actually adding +// the files from inside the folders. + +// Admin +dir templates +dir templates/admin +%here%/myproject/myproject/templates/admin/base_site.html 1 + // STATIC FILES %here%/myproject/myproject/__init__.py 2 %here%/myproject/myproject/views.py 2 @@ -58,13 +69,9 @@ v HOSTpass HereItIs_HaveMyAccount // Activation Email %here%/myproject/myproject/activation_email.html 2 -// Add these dir commands before actually adding -// the files from inside the folders. - // HTML/CSS dir static dir static/css -dir templates %here%/myproject/myproject/static/css/default.css 2 %here%/myproject/myproject/templates/base.html 2 %here%/myproject/myproject/templates/index.html 2 @@ -80,10 +87,6 @@ dir templates/auth %here%/myproject/myproject/templates/auth/newaccount.html 2 %here%/myproject/myproject/templates/auth/registration.html 2 -// Admin -dir templates/admin -%here%/myproject/myproject/templates/admin/base_site.html 2 - // Backend Django app dir backends root %here%/myproject/backends/__init__.py 2 diff --git a/myproject/myproject/settings.py b/myproject/myproject/settings.py index df99213..336fbdc 100644 --- a/myproject/myproject/settings.py +++ b/myproject/myproject/settings.py @@ -16,6 +16,7 @@ DEBUG = True TEMPLATE_DEBUG = DEBUG baseurl = "<%baseurl%>" # "example.com" +base_title = "<%basetitle%>" ''' You need to sign up at http://recaptcha.net/ for a public/private key to use their CAPTCHA service. diff --git a/myproject/myproject/templates/admin/base_site.html b/myproject/myproject/templates/admin/base_site.html index 866660c..af90f2a 100644 --- a/myproject/myproject/templates/admin/base_site.html +++ b/myproject/myproject/templates/admin/base_site.html @@ -1,10 +1,10 @@ {% extends "admin/base.html" %} {% load i18n %} -{% block title %}{{ title }} | {% trans 'Admin Site' %}{% endblock %} +{% block title %}{{ title }} | {% trans '<%basetitle%> Admin Site' %}{% endblock %} {% block branding %} -

{% trans 'Administration' %}

+

{% trans '<%basetitle%> Administration' %}

{% endblock %} {% block nav-global %}{% endblock %} diff --git a/myproject/myproject/views.py b/myproject/myproject/views.py index 06ddfcc..0bd3fbb 100644 --- a/myproject/myproject/views.py +++ b/myproject/myproject/views.py @@ -31,7 +31,8 @@ from django.core.mail import EmailMessage from django.core import mail # Variables from Settings.py -from settings import EMAIL_HOST_USER, baseurl, EMAIL_MESSAGE +from settings import EMAIL_HOST_USER, EMAIL_MESSAGE +from settings import baseurl, base_title # User Profile model from accountprofile.models import UserProfile @@ -149,27 +150,25 @@ def login_user(request): # No object so the username and password are invalid. login_errors = True responce = render_to_response( - 'auth/login.html', - locals(), - context_instance=RequestContext(request) - ) + 'auth/login.html', + locals(), + context_instance=RequestContext(request) + ) else: # User isn't online and hasn't sent any POST data, give them a login form. responce = render_to_response( - 'auth/login.html', - locals(), - context_instance=RequestContext(request) + 'auth/login.html', + locals(), + context_instance=RequestContext(request) ) else: # User is logged on, don't let them login until he's logged out. user_navigation = user_nav(request.user.username) error = "You're already logged on." - responce = render_to_response( - 'error.html', - locals() - ) + responce = render_to_response('error.html',locals()) + return responce def register_user(request): @@ -198,11 +197,11 @@ def register_user(request): # Is human? HumanTestResult = captcha.submit( - request.POST["recaptcha_challenge_field"], - request.POST["recaptcha_response_field"], - captcha_privatekey, - get_ip(request) - ) + request.POST["recaptcha_challenge_field"], + request.POST["recaptcha_response_field"], + captcha_privatekey, + get_ip(request) + ) # If not human: display errors if HumanTestResult.is_valid: @@ -241,34 +240,43 @@ def register_user(request): else: registration_errors.append("Invalid human verification code.") captcha_test = captcha.displayhtml( - captcha_publickey, - False, - HumanTestResult.error_code) + captcha_publickey, + False, + HumanTestResult.error_code + ) + + # Connect to SMTP server + connection = mail.get_connection() + connection.open() # If no errors: create user. if len(registration_errors) == 0: new_user = User.objects.create_user( - username, - email, - request.POST["repassw"] - ) + username, + email, + request.POST["repassw"] + ) + new_user.is_active = True new_user.save() # Create activation key and user profile activation_key = UserActivationKey() profile = UserProfile( - activatekey=activation_key, - activated=False, - user=new_user) + activatekey=activation_key, + activated=False, + user=new_user) profile.save() # User is created and saved. Send an activation link via email - connection = mail.get_connection() - connection.open() - message_activateurl = baseurl+"/activate/?key="+str(activation_key)+"&user="+str(new_user.username) - message_deactivateurl = baseurl+"/deactivate/?key="+str(activation_key)+"&user="+str(new_user.username) + # Activation link + message_activateurl = baseurl+"/activate/?key="+str(activation_key) + message_activateurl = message_activateurl+"&user="+str(new_user.username) + + # Deactivation link + message_deactivateurl = baseurl+"/deactivate/?key="+str(activation_key) + message_deactivateurl = message_deactivateurl+"&user="+str(new_user.username) f = open(EMAIL_MESSAGE, 'r') message = f.read() @@ -278,35 +286,39 @@ def register_user(request): message = message.replace("<$disablelink>", message_deactivateurl) email = EmailMessage( - "Account Activation", - message, - EMAIL_HOST_USER, - [new_user.email]) + "Account Activation", + message, + EMAIL_HOST_USER, + [new_user.email] + ) + email.send() connection.close() # Return new account page accountname = new_user.username responce = render_to_response( - 'auth/newaccount.html', - locals(), - context_instance=RequestContext(request) - ) + 'auth/newaccount.html', + locals(), + context_instance=RequestContext(request) + ) + else: # Return registration form with errors in registration_errors responce = render_to_response( - 'auth/registration.html', - locals(), - context_instance=RequestContext(request) - ) + 'auth/registration.html', + locals(), + context_instance=RequestContext(request) + ) # If user hasn't sent POST data (not logged on) else: responce = render_to_response( - 'auth/registration.html', - locals(), - context_instance=RequestContext(request) - ) + 'auth/registration.html', + locals(), + context_instance=RequestContext(request) + ) + # User is logged on else: user_navigation = user_nav(request.user.username) @@ -346,14 +358,14 @@ def activate_user(request): if key_correct: user_name = user.username responce = render_to_response( - 'auth/activated.html', - locals() - ) + 'auth/activated.html', + locals() + ) else: error = "Activation failed." responce = render_to_response( - 'error.html', - locals() - ) + 'error.html', + locals() + ) return responce