From bdaf7da98d94204d6f1132ee4ca8b190afa777cf Mon Sep 17 00:00:00 2001 From: dellsystem Date: Tue, 8 Nov 2011 14:52:52 -0500 Subject: [PATCH] add rudimentary ucp (#31 in progress) --- templates/base.html | 2 +- templates/main/ucp.html | 15 +++++++ templates/ucp/account.html | 1 + templates/ucp/overview.html | 5 +++ templates/ucp/preferences.html | 31 +++++++++++++ templates/ucp/profile.html | 80 ++++++++++++++++++++++++++++++++++ urls.py | 1 + views/main.py | 34 +++++++++++++++ 8 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 templates/main/ucp.html create mode 100644 templates/ucp/account.html create mode 100644 templates/ucp/overview.html create mode 100644 templates/ucp/preferences.html create mode 100644 templates/ucp/profile.html diff --git a/templates/base.html b/templates/base.html index 8fc990f..3c3b786 100755 --- a/templates/base.html +++ b/templates/base.html @@ -87,7 +87,7 @@ Stay logged in {% else %} -

Settings{% if user.is_staff %} Admin{% endif %}

+

User control panel{% if user.is_staff %} Admin{% endif %}

{% load gravatar %}
Your Gravatar
{% endif %} diff --git a/templates/main/ucp.html b/templates/main/ucp.html new file mode 100644 index 0000000..adb3194 --- /dev/null +++ b/templates/main/ucp.html @@ -0,0 +1,15 @@ +{% extends "base.html" %} + +{% block content %} +
+
+

User control panel

+ + {% include template %} +
+
+{% endblock %} diff --git a/templates/ucp/account.html b/templates/ucp/account.html new file mode 100644 index 0000000..c5cbe0c --- /dev/null +++ b/templates/ucp/account.html @@ -0,0 +1 @@ +

Here you can edit your account info. Can you change your username? Nah, not yet. Can you change your email and password? Sure.

diff --git a/templates/ucp/overview.html b/templates/ucp/overview.html new file mode 100644 index 0000000..97fd04e --- /dev/null +++ b/templates/ucp/overview.html @@ -0,0 +1,5 @@ +

Welcome to your user control panel. There is not much here, so I'll just present you with some useless statistics:

+ +

You have been a member

+ +

Found a bug? Contact dellsystem@wikinotes.ca.

diff --git a/templates/ucp/preferences.html b/templates/ucp/preferences.html new file mode 100644 index 0000000..fdb0343 --- /dev/null +++ b/templates/ucp/preferences.html @@ -0,0 +1,31 @@ +
+
+
+
+ {% csrf_token %} + Edit site preferences + {% if success %} +
+
+
+

Successfully updated site preferences.

+
+
+
+ {% endif %} +
+ +
+ No Yes +
+
+
+   +
+
+
+
+
+

Configure if you want logged-in users to be able to see your email I guess. That's all I have for now.

+
+
diff --git a/templates/ucp/profile.html b/templates/ucp/profile.html new file mode 100644 index 0000000..9fa2d5e --- /dev/null +++ b/templates/ucp/profile.html @@ -0,0 +1,80 @@ +
+
+
+
+ {% csrf_token %} + Edit profile information + {% if success %} +
+
+
+

Successfully updated profile.

+
+
+
+ {% endif %} +
+ +
+ + + A short description of yourself. Limit it to 300 characters or so. Markdown is not parsed. + +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+   +
+
+
+
+
+

All fields are optional.

+ +
    +
  • Edit your bio
  • +
  • Edit your major
  • +
  • Link to website
  • +
  • Twitter
  • +
  • Github
  • +
  • Facebook
  • +
  • Google plus
  • +
+
+
diff --git a/urls.py b/urls.py index abd86f4..088e328 100755 --- a/urls.py +++ b/urls.py @@ -16,6 +16,7 @@ url(r'^faculty/(?P\w+)$', 'views.courses.faculty_overview'), url(r'^department/(?P\w{4})$', 'views.courses.department_overview'), url(r'^user/(?P\w+)$', 'views.main.profile'), + url(r'^ucp/?(?P\w*)$', 'views.main.ucp'), # Registration stuff url(r'^register$', 'views.main.register'), diff --git a/views/main.py b/views/main.py index fec70e0..635111c 100755 --- a/views/main.py +++ b/views/main.py @@ -127,3 +127,37 @@ def register(request): return index(request, show_welcome=True) else: return render(request, 'main/registration.html') + +def ucp(request, mode): + # Need a better way of dealing with logged-out users + modes = ['overview', 'account', 'profile', 'preferences'] + if mode == '' or mode not in modes: + mode = 'overview' + if request.user.is_authenticated(): + user = request.user + user_profile = user.get_profile() + data = { + 'mode': mode, + 'modes': modes, + 'template': 'ucp/' + mode + '.html', + 'success': False, + } + + # Now check if a request has been submitted + if request.POST: + data['success'] = True + if mode == 'preferences': + user_profile.show_email = request.POST['show_email'] == '1' + if mode == 'profile': + user_profile.bio = request.POST['ucp_bio'] + user_profile.website = request.POST['ucp_website'] + user_profile.twitter = request.POST['ucp_twitter'] + user_profile.github = request.POST['ucp_github'] + user_profile.facebook = request.POST['ucp_facebook'] + user_profile.gplus = request.POST['ucp_gplus'] + user_profile.major = request.POST['ucp_major'] + user_profile.save() + + return render(request, 'main/ucp.html', data) + else: + return index(request)