← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~huwshimi/maas/first-user into lp:maas

 

Huw Wilkins has proposed merging lp:~huwshimi/maas/first-user into lp:maas.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~huwshimi/maas/first-user/+merge/98589

This branch changes the way the message is displayed on the login page when there are no users.

Instead of displaying a session message the message is now a part of the template (either show the message or the login form).

There are a few design changes etc. for the display of the message.
-- 
https://code.launchpad.net/~huwshimi/maas/first-user/+merge/98589
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~huwshimi/maas/first-user into lp:maas.
=== modified file 'src/maasserver/static/css/base.css'
--- src/maasserver/static/css/base.css	2012-02-22 04:16:32 +0000
+++ src/maasserver/static/css/base.css	2012-03-21 09:20:33 +0000
@@ -10,3 +10,8 @@
     border-collapse: collapse;
     border-spacing: 0;
     }
+pre {
+    background-color: #f2f2f2;
+    padding: 5px 5px 5px 3px;
+    display: inline-block;
+    }

=== modified file 'src/maasserver/static/css/layout.css'
--- src/maasserver/static/css/layout.css	2012-03-02 03:33:00 +0000
+++ src/maasserver/static/css/layout.css	2012-03-21 09:20:33 +0000
@@ -126,10 +126,15 @@
 /******************************************************************************
     Content modifier: login
 */
+.login .center-page-wrapper {
+    width: 440px;
+    }
+.login.no-users .center-page-wrapper {
+    width: 670px;
+    }
 .login #content {
     padding: 30px 40px;
-    width: 360px;
-    margin: 100px auto 0 auto;
+    margin-top: 100px;
     -webkit-box-shadow: 0 0 15px 0 rgba(0,0,0,1);
     box-shadow: 0 0 15px 0 rgba(0,0,0,1);
     }
@@ -140,7 +145,6 @@
     margin-bottom: 20px;
     }
 .login #footer {
-    width: 440px;
     margin: 0 auto;
     }
 

=== modified file 'src/maasserver/static/css/modifiers.css'
--- src/maasserver/static/css/modifiers.css	2012-03-05 05:52:32 +0000
+++ src/maasserver/static/css/modifiers.css	2012-03-21 09:20:33 +0000
@@ -22,3 +22,10 @@
     vertical-align: text-bottom;
     margin-right: 3px;
     }
+/* Spacing */
+.space-top-small {
+    margin-top: 10px;
+    }
+.space-right-large {
+    margin-right: 40px;
+    }

=== added file 'src/maasserver/static/img/pictogram_no_users.png'
Binary files src/maasserver/static/img/pictogram_no_users.png	1970-01-01 00:00:00 +0000 and src/maasserver/static/img/pictogram_no_users.png	2012-03-21 09:20:33 +0000 differ
=== modified file 'src/maasserver/templates/registration/login.html'
--- src/maasserver/templates/registration/login.html	2012-03-19 12:23:46 +0000
+++ src/maasserver/templates/registration/login.html	2012-03-21 09:20:33 +0000
@@ -1,21 +1,30 @@
 {% extends "maasserver/base.html" %}
 
 {% block title %}Login{% endblock %}
-{% block layout-modifiers %}modal-content login{% endblock %}
+{% block layout-modifiers %}modal-content login {% if no_users %}no-users{% endif %}{% endblock %}
 
 {% block head %}
-  <script type="text/javascript">
-  <!--
-  YUI().use('node', function (Y) {
-    Y.on('load', function() {
-      Y.one('input[type=text]').focus();
+  {% if not no_users %}
+    <script type="text/javascript">
+    <!--
+    YUI().use('node', function (Y) {
+      Y.on('load', function() {
+        Y.one('input[type=text]').focus();
+      });
     });
-  });
-  // -->
-  </script>
+    // -->
+    </script>
+  {% endif %}
 {% endblock %}
 
 {% block content %}
+  {% if no_users %}
+      <img src="{{ STATIC_URL }}img/pictogram_no_users.png" alt="No users pictogram" class="left space-right-large" />
+      <h2>No admin user has been created yet</h2>
+      <p>Run the following command from the console to create an admin user:</p>
+      <pre>{{ create_command }} createsuperuser</pre>
+      <a href="{% url 'login' %}" class="button right space-top-small">login</a>
+  {% else %}
   <h2>Login to {% include "maasserver/site_title.html" %}</h2>
   {% if form.errors %}
     <p class="form-errors">Your username and password didn't match. Please try again.</p>
@@ -30,6 +39,7 @@
       <li class="form-submit"><input type="submit" value="Login" /></li>
     </ul>
   </form>
+  {% endif %}
 {% endblock %}
 
 {% block footer-copyright %}{% endblock %}

=== modified file 'src/maasserver/tests/test_views.py'
--- src/maasserver/tests/test_views.py	2012-03-19 13:13:06 +0000
+++ src/maasserver/tests/test_views.py	2012-03-21 09:20:33 +0000
@@ -84,29 +84,21 @@
 
 class TestLogin(TestCase):
 
-    def test_login_contains_input_tags(self):
+    def test_login_contains_input_tags_if_user(self):
+        factory.make_user()
         response = self.client.get('/accounts/login/')
         doc = fromstring(response.content)
         self.assertEqual(1, len(doc.cssselect('input#id_username')))
         self.assertEqual(1, len(doc.cssselect('input#id_password')))
+        self.assertFalse(response.context['no_users'])
+        self.assertEqual(None, response.context['create_command'])
 
     def test_login_displays_createsuperuser_message_if_no_user(self):
         path = factory.getRandomString()
         self.patch(settings, 'MAAS_CLI', path)
         response = self.client.get('/accounts/login/')
-        self.assertEqual(
-            [
-                "No admin user has been created yet. "
-                "Run the following command from the console to create an "
-                "admin user:"
-                "<pre>%s createsuperuser</pre>" % path
-            ],
-            [message.message for message in response.context['messages']])
-
-    def test_login_does_not_display_createsuperuser_message_if_user(self):
-        factory.make_user()
-        response = self.client.get('/accounts/login/')
-        self.assertEqual(0, len(response.context['messages']))
+        self.assertTrue(response.context['no_users'])
+        self.assertEqual(path, response.context['create_command'])
 
 
 class TestSnippets(LoggedInTestCase):

=== modified file 'src/maasserver/views.py'
--- src/maasserver/views.py	2012-03-19 13:13:06 +0000
+++ src/maasserver/views.py	2012-03-21 09:20:33 +0000
@@ -70,14 +70,11 @@
 
 
 def login(request):
+    extra_context = {'no_users': False, 'create_command': None}
     if UserProfile.objects.all_users().count() == 0:
-        message = mark_safe(
-            "No admin user has been created yet. "
-            "Run the following command from the console to create an "
-            "admin user:"
-            "<pre>%s createsuperuser</pre>" % django_settings.MAAS_CLI)
-        messages.error(request, message)
-    return dj_login(request)
+        extra_context['no_users'] = True
+        extra_context['create_command'] = django_settings.MAAS_CLI
+    return dj_login(request, extra_context=extra_context)
 
 
 def logout(request):