Commits

Matthew Marshall committed 5b7923c

Added tos and profile pages. (and more styling chagnes.

Comments (0)

Files changed (8)

+from freehg.repos.models import Repo
+from django.contrib.auth.models import User
+from django.shortcuts import get_object_or_404, render_to_response
+from django.template import RequestContext
+from django.contrib.auth.decorators import login_required
+from django.http import HttpResponseRedirect
+from django import newforms as forms
+
+@login_required
+def profile(request):
+    user = request.user
+    if request.method == 'POST':
+        form = ChangeProfileForm(request.POST)
+        if form.is_valid():
+            form.update_user(user)
+            user.save()
+            user.message_set.create(message="Profile updated.")
+            return HttpResponseRedirect("/accounts/profile/")
+    else:
+        form = ChangeProfileForm(dict(
+                first_name=user.first_name,
+                last_name=user.last_name,
+                email=user.email))
+    return render_to_response('profile.html', dict(form=form),
+            context_instance=RequestContext(request))
+
+
+
+class ChangeProfileForm(forms.Form):
+    first_name = forms.CharField(max_length=30, required=False)
+    last_name = forms.CharField(max_length=30, required=False)
+    email = forms.EmailField(required=False)
+
+    def update_user(self, user):
+        user.first_name = self.cleaned_data['first_name']
+        user.last_name = self.cleaned_data['last_name']
+        user.email = self.cleaned_data['email']
+
 from django.contrib.auth.models import User
 from django.contrib.auth import authenticate
 
-required_dict = {'class': 'required'}
 username_re = re.compile(r'^\w+$')
 
 class NewRepoForm(forms.Form):
                 long_name=self.cleaned_data['long_name'],
                 description=self.cleaned_data['description'])
 
+required_dict = {'class': 'required text short'}
+
 class NewAccountForm(forms.Form):
-    username = forms.CharField(max_length=30,
-                               widget=forms.TextInput(attrs=required_dict),
-                               label=u'Username')
-    password1 = forms.CharField(widget=forms.PasswordInput(attrs=required_dict),
-                                label=u'Password')
-    password2 = forms.CharField(widget=forms.PasswordInput(attrs=required_dict),
-                                label=u'Password (again)')
-    tos = forms.BooleanField(widget=forms.CheckboxInput(attrs=required_dict),
-                        label=u'I have read and agree to the Terms of Service')
+    username = forms.CharField(max_length=30, label=u'Username',
+            widget=forms.TextInput(attrs={'class': 'required text short'}))
+    password1 = forms.CharField(label=u'Password',
+            widget=forms.PasswordInput(attrs={'class': 'required text short'}))
+    password2 = forms.CharField(label=u'Password (again)',
+            widget=forms.PasswordInput(attrs={'class': 'required text short'}),
+            help_text="What if you made a typo?")
+    tos = forms.BooleanField()
 
     def clean_username(self):
         """

templates/base.html

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html>
 <head>
-<title>{% block title %}{% endblock %} - FreeHG.org</title>
+<title>{% block title %}{% endblock %} - freeHg.org</title>
 {% comment %} <link rel="stylesheet" href="/static/style.css" type="text/css" /> {% endcomment %}
 <link rel="stylesheet" href="/static/blueprint/screen.css" type="text/css" media="screen, projection" />
 <link rel="stylesheet" href="/static/blueprint/print.css" type="text/css" media="print" />
 padding-left:2em;}
 
 #login-info {float:right;}
-#header h1 {float:left;}
 
 div.align-form label {float:left;min-width:120px;}
 div.align-form input {}
 div.align-form p, div.align-form ul.errorlist {clear:both;}
-/* div.align-form p {padding-bottom:18px;} */
+
+.help-text {color:#666666;font-style:italic;}
+fieldset {border:0px;}
+
+input.short {width:220px;padding:5px;}
+textarea {height:100px;}
+.form-row p {margin:0pt 0pt 1em;}
 </style>
 
 </head>
 <body>
 <div class="container">
     <div id="header" class="span-24">
-        <h1><a href="http://freehg.org">FreeHG.org</a></h1>
+        <div class="span-14">
+            <h1 style="margin-bottom:5px;"><a style="text-decoration:none;" href="http://freehg.org">freeHg.org</a></h1>
+            <h5>Quick and easy hosting for <a href="http://selenic.com/mercurial/">Mercurial</a></h5>
+        </div>
 
         <div id="login-info">
             {% if user.is_authenticated %}
-                You are logged in as <span id=#username><a href="/u/{{user.username}}">{{user.username}}</a></span>. (<a href="/accounts/logout/">Logout</a>)
+                You are logged in as <span id=#username>{{user.username}}</span>. (<a href="/accounts/profile/">Profile</a> | <a href="/accounts/change_password/">Change Password</a> | <a href="/accounts/logout/">Logout</a>)
             {% else %}
                 (<a href="/accounts/login/">Login</a>)
             {% endif %}

templates/frontpage.html

 
 <form action='.' method='post'>
 
-<div class="span-16 last append-8">
-
-    Repository url will be: <pre>http://freehg.org/u/{% if user.username %}{{user.username}}{%else%}<span id="url-user" class="notgiven">&lt;username&gt;</span>{%endif%}/<span id="url-repo" class="notgiven">&lt;reponame&gt;</span></pre>
+<div class="span-14 border">
 
     <fieldset>
+    <legend>Create a repository:</legend>
     {% for field in repo_form %}
             <div class="form-row {%if field.field.required %}required{%endif%} {%if field.errors%}errors{%endif%}">
                 {% if field.errors %}{{field.errors}}{% endif %}
                 <p>
-                {{field.label_tag}}<br />
-                {{field}}</p>
+                    {{field.label_tag}}<br />
+                    {% if field.help_text %}
+                        <span class="help-text">({{field.help_text}})</span><br />
+                    {%endif%}
+                    {{field}}
+                    {% ifequal field.name "reponame" %}
+                        <br />Repository url will be: <code>http://freehg.org/u/{% if user.username %}{{user.username}}{%else%}<span id="url-user" class="notgiven">&lt;username&gt;</span>{%endif%}/<span id="url-repo" class="notgiven">&lt;reponame&gt;</span></code>
+                    {%endifequal%}
+                </p>
             </div>
     {% endfor %}
 
         <input type='submit' name='createrepo' value='Create repository for {{user.username}}' />
     {% endif %}
     </fieldset>
-</div>
 
-{% if not user.is_authenticated %}
-<div class="span-8">
-    <h3>Login:</h3>
-    <fieldset>
-    {% for field in login_form %}
-        <div class="form-row {%if field.field.required %}required{%endif%} {%if field.errors%}errors{%endif%}">
-            {% if field.errors %}{{field.errors}}{% endif %}
-            <p>
-            {{field.label_tag}}<br />
-            {{field}}</p>
-        </div>
-    {% endfor %}
-    <input type='submit' name='login' value='Login' />
-    </fieldset>
-</div>
-<div class="span-8 last">
-    <h3>... or create a new account:</h3>
-    <fieldset>
-    {% for field in new_account_form %}
-        {% ifnotequal field.name "tos" %}
+    {% if not user.is_authenticated %}
+    <div class="span-7 border">
+        <fieldset>
+        <legend>Login:</legend>
+        {% for field in login_form %}
             <div class="form-row {%if field.field.required %}required{%endif%} {%if field.errors%}errors{%endif%}">
                 {% if field.errors %}{{field.errors}}{% endif %}
                 <p>
                 {{field.label_tag}}<br />
                 {{field}}</p>
             </div>
-        {% endifnotequal %}
-    {% endfor %}
-    <div class="form-row required">
-        {% if new_account_form.tos.errors %}{{new_account_form.tos.errors}}{% endif %}
-        <p>{{new_account_form.tos}}{{new_account_form.tos.label_tag}}</p>
+        {% endfor %}
+        <input type='submit' name='login' value='Login' />
+        </fieldset>
     </div>
-    <input type='submit' name='newaccount'  value='Create new account' />
-    </fieldset>
+    <div class="span-7 last">
+        <fieldset>
+        <legend>... or create an account:</legend>
+        {% for field in new_account_form %}
+            {% ifnotequal field.name "tos" %}
+                <div class="form-row {%if field.field.required %}required{%endif%} {%if field.errors%}errors{%endif%}">
+                    {% if field.errors %}{{field.errors}}{% endif %}
+                    <p>
+                    {{field.label_tag}}<br />
+                    {{field}}</p>
+                </div>
+            {% endifnotequal %}
+        {% endfor %}
+        <div class="form-row required">
+            {% if new_account_form.tos.errors %}{{new_account_form.tos.errors}}{% endif %}
+            <p>{{new_account_form.tos}} I agree to the <a href="/tos/">Terms of Service</a>.</p>
+        </div>
+        <input type='submit' name='newaccount'  value='Create new account' />
+        </fieldset>
+    </div>
+</div>
+
+<div class="span-8 last">
+<h3>What is this site?</h3>
+<p>
+<a href="http://selenic.com/mercurial/">
+</p>
 </div>
 {% endif %}
 </form>

templates/profile.html

 </dl>
 </div>
 
-<div id="change-profile" class=" span-8 align-form">
+<div id="change-profile" class=" span-8 align-form box">
 <form method="post" target=".">
-<fieldset>
-<legend>Update Profile</legend>
 {{form.as_p}}
 <input type="submit" value="Update Profile"/>
 </form>

templates/registration/logged_out.html

 
 <p>You have been logged out. Thanks for using FreeHG.org :)</p>
 
-<p><a href="../">{% trans 'Back to the homepage.' %}</a></p>
+<p><a href="/">{% trans 'Back to the homepage.' %}</a></p>
 
 {% endblock %}

templates/tos.html

+{% extends "base.html" %}
+
+{% block title %}Terms of Service{% endblock %}
+
+{% block content %}
+
+<h2>Terms of Service</h2>
+
+<div class="span-10">
+    <p>You may only upload content to freeHg.org that you own or are given permission to distribute by the owner.</p>
+    <p>Content in the repositories hosted by freeHg.org is the responsibility of it's respective owner.</p>
+    <p>freeHg.org is not responsible for any damages that arise from using the service.</p>
+
+    <pre>
+THE SERVICE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR WEBMASTERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SERVICE.
+</pre>
+</div>
+
+{% endblock %}
 from django.conf.urls.defaults import *
 
+from django.views.generic.simple import direct_to_template
+
 urlpatterns = patterns('',
     # Example:
     #(r'^freehg/', include('freehg.foo.urls')),
     (r'^accounts/change_password/done/$',
             'django.contrib.auth.views.password_change_done'),
 
+    (r'^tos/', direct_to_template, {'template':'tos.html'}),
+
     # Uncomment this for admin:
     (r'^admin/', include('django.contrib.admin.urls')),
 )