Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
add rudimentary ucp (#31 in progress)
Browse files Browse the repository at this point in the history
  • Loading branch information
dellsystem committed Nov 8, 2011
1 parent b01358b commit bdaf7da
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 1 deletion.
2 changes: 1 addition & 1 deletion templates/base.html
Expand Up @@ -87,7 +87,7 @@
<input type="checkbox" /><span> Stay logged in</span>
</div>
{% else %}
<div style="float: right;"><p><a href="" class="btn info" style="font-weight: normal;">Settings</a>{% if user.is_staff %} <a href="/admin" class="btn" style="font-weight: normal; color: #000;">Admin</a>{% endif %}</p><p><input type="submit" class="btn danger" value="Log out ({{ user }})" name="logout" /></p></div>
<div style="float: right;"><p><a href="/ucp" class="btn info" style="font-weight: normal;">User control panel</a>{% if user.is_staff %} <a href="/admin" class="btn" style="font-weight: normal; color: #000;">Admin</a>{% endif %}</p><p><input type="submit" class="btn danger" value="Log out ({{ user }})" name="logout" /></p></div>
{% load gravatar %}
<div style="float: left; margin-right: 10px;"><a href="{{ user.get_profile.get_url }}"><img src="{% gravatar_for_user user 70 %}" alt="Your Gravatar" /></a></div>
{% endif %}
Expand Down
15 changes: 15 additions & 0 deletions templates/main/ucp.html
@@ -0,0 +1,15 @@
{% extends "base.html" %}

{% block content %}
<div class="container">
<section>
<h1>User control panel</h1>
<ul class="tabs">
{% for mode_name in modes %}
<li{% if mode_name == mode %} class="active"{% endif %}><a href="/ucp/{{ mode_name }}">{{ mode_name|title }}</a></li>
{% endfor %}
</ul>
{% include template %}
</section>
</div>
{% endblock %}
1 change: 1 addition & 0 deletions templates/ucp/account.html
@@ -0,0 +1 @@
<p>Here you can edit your account info. Can you change your username? Nah, not yet. Can you change your email and password? Sure.</p>
5 changes: 5 additions & 0 deletions templates/ucp/overview.html
@@ -0,0 +1,5 @@
<p>Welcome to your user control panel. There is not much here, so I'll just present you with some useless statistics:</p>

<p>You have been a member </p>

<p>Found a bug? Contact dellsystem@wikinotes.ca.</p>
31 changes: 31 additions & 0 deletions templates/ucp/preferences.html
@@ -0,0 +1,31 @@
<div class="row">
<div class="span12">
<form method="post" action="">
<fieldset>
{% csrf_token %}
<legend>Edit site preferences</legend>
{% if success %}
<div class="clearfix">
<div class="input">
<div class="alert-message block-message success">
<p>Successfully updated site preferences.</p>
</div>
</div>
</div>
{% endif %}
<div class="clearfix">
<label>Show email:</label>
<div class="input">
<input type="radio" name="show_email" value="0"{% if not user.get_profile.show_email %} checked="checked"{% endif %} /> No <input type="radio" name="show_email" value="1"{% if user.get_profile.show_email %} checked="checked"{% endif %} /> Yes
</div>
</div>
<div class="actions">
<input type="submit" class="btn primary" name="submit" value="Submit">&nbsp;<button type="reset" class="btn">Reset</button>
</div>
</fieldset>
</form>
</div>
<div class="span4">
<p>Configure if you want logged-in users to be able to see your email I guess. That's all I have for now.</p>
</div>
</div>
80 changes: 80 additions & 0 deletions templates/ucp/profile.html
@@ -0,0 +1,80 @@
<div class="row">
<div class="span12">
<form method="post" action="">
<fieldset>
{% csrf_token %}
<legend>Edit profile information</legend>
{% if success %}
<div class="clearfix">
<div class="input">
<div class="alert-message block-message success">
<p>Successfully updated profile.</p>
</div>
</div>
</div>
{% endif %}
<div class="clearfix">
<label for="textarea">Bio:</label>
<div class="input">
<textarea class="xxlarge" id="ucp_bio" name="ucp_bio" rows="2">{{ user.get_profile.bio }}</textarea>
<span class="help-block">
A short description of yourself. Limit it to 300 characters or so. Markdown is not parsed.
</span>
</div>
</div>
<div class="clearfix">
<label for="ucp_major">Major:</label>
<div class="input">
<input class="xlarge" id="ucp_major" name="ucp_major" size="30" type="text" value="{{ user.get_profile.major }}" />
</div>
</div>
<div class="clearfix">
<label for="ucp_website">Website:</label>
<div class="input">
<input class="xlarge" id="ucp_website" name="ucp_website" size="30" type="text" value="{{ user.get_profile.website }}" />
</div>
</div>
<div class="clearfix">
<label for="ucp_twitter">Twitter username:</label>
<div class="input">
<input class="xlarge" id="ucp_twitter" name="ucp_twitter" size="30" type="text" value="{{ user.get_profile.twitter }}" />
</div>
</div>
<div class="clearfix">
<label for="ucp_github">Github username:</label>
<div class="input">
<input class="xlarge" id="ucp_github" name="ucp_github" size="30" type="text" value="{{ user.get_profile.github }}" />
</div>
</div>
<div class="clearfix">
<label for="ucp_facebook">Facebook username:</label>
<div class="input">
<input class="xlarge" id="ucp_facebook" name="ucp_facebook" size="30" type="text" value="{{ user.get_profile.facebook }}" />
</div>
</div>
<div class="clearfix">
<label for="ucp_gplus">Google plus ID:</label>
<div class="input">
<input class="xlarge" id="ucp_gplus" name="ucp_gplus" size="30" type="text" value="{{ user.get_profile.gplus }}" />
</div>
</div>
<div class="actions">
<input type="submit" class="btn primary" name="submit" value="Submit">&nbsp;<button type="reset" class="btn">Reset</button>
</div>
</fieldset>
</form>
</div>
<div class="span4">
<p>All fields are optional.</p>

<ul>
<li>Edit your bio</li>
<li>Edit your major</li>
<li>Link to website</li>
<li>Twitter</li>
<li>Github</li>
<li>Facebook</li>
<li>Google plus</li>
</ul>
</div>
</div>
1 change: 1 addition & 0 deletions urls.py
Expand Up @@ -16,6 +16,7 @@
url(r'^faculty/(?P<faculty>\w+)$', 'views.courses.faculty_overview'),
url(r'^department/(?P<department>\w{4})$', 'views.courses.department_overview'),
url(r'^user/(?P<username>\w+)$', 'views.main.profile'),
url(r'^ucp/?(?P<mode>\w*)$', 'views.main.ucp'),

# Registration stuff
url(r'^register$', 'views.main.register'),
Expand Down
34 changes: 34 additions & 0 deletions views/main.py
Expand Up @@ -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)

0 comments on commit bdaf7da

Please sign in to comment.