used template hooks instead of hardcoding basic_auth functionality into templates
authorRodney Ewing <ewing.rj@gmail.com>
Tue, 9 Jul 2013 00:28:21 +0000 (17:28 -0700)
committerRodney Ewing <ewing.rj@gmail.com>
Fri, 16 Aug 2013 17:28:48 +0000 (10:28 -0700)
mediagoblin/plugins/basic_auth/__init__.py
mediagoblin/plugins/basic_auth/static/js/autofilledin_password.js [moved from mediagoblin/static/js/autofilledin_password.js with 100% similarity]
mediagoblin/plugins/basic_auth/templates/mediagoblin/plugins/basic_auth/edit_link.html [new file with mode: 0644]
mediagoblin/plugins/basic_auth/templates/mediagoblin/plugins/basic_auth/fp_head.html [new file with mode: 0644]
mediagoblin/plugins/basic_auth/templates/mediagoblin/plugins/basic_auth/fp_link.html [new file with mode: 0644]
mediagoblin/plugins/openid/templates/mediagoblin/plugins/openid/login.html
mediagoblin/templates/mediagoblin/auth/login.html
mediagoblin/templates/mediagoblin/edit/edit_account.html

index 913ccba49287fb9bf93853bc5682e28f069f14a5..06059a07eb5acda11b93bc6d446d2f8002944f44 100644 (file)
@@ -13,6 +13,7 @@
 #
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
+from pkg_resources import resource_filename
 import os
 
 from mediagoblin.plugins.basic_auth import forms as auth_forms
@@ -21,6 +22,8 @@ from mediagoblin.auth.tools import create_basic_user
 from mediagoblin.db.models import User
 from mediagoblin.tools import pluginapi
 from sqlalchemy import or_
+from mediagoblin.tools.staticdirect import PluginStatic
+
 
 PLUGIN_DIR = os.path.dirname(__file__)
 
@@ -42,6 +45,11 @@ def setup_plugin():
     pluginapi.register_routes(routes)
     pluginapi.register_template_path(os.path.join(PLUGIN_DIR, 'templates'))
 
+    pluginapi.register_template_hooks(
+        {'edit_link': 'mediagoblin/plugins/basic_auth/edit_link.html',
+         'fp_link': 'mediagoblin/plugins/basic_auth/fp_link.html',
+         'fp_head': 'mediagoblin/plugins/basic_auth/fp_head.html'})
+
 
 def get_user(**kwargs):
     username = kwargs.pop('username', None)
@@ -103,4 +111,7 @@ hooks = {
     'auth_check_password': check_password,
     'auth_fake_login_attempt': auth_tools.fake_login_attempt,
     'template_global_context': append_to_global_context,
+    'static_setup': lambda: PluginStatic(
+        'coreplugin_basic_auth',
+        resource_filename('mediagoblin.plugins.basic_auth', 'static'))
 }
diff --git a/mediagoblin/plugins/basic_auth/templates/mediagoblin/plugins/basic_auth/edit_link.html b/mediagoblin/plugins/basic_auth/templates/mediagoblin/plugins/basic_auth/edit_link.html
new file mode 100644 (file)
index 0000000..9fd09ab
--- /dev/null
@@ -0,0 +1,25 @@
+{#
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2011, 2012 MediaGoblin contributors.  See AUTHORS.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#}
+
+{% block change_pass_link %}
+  <p>
+    <a href="{{ request.urlgen('mediagoblin.plugins.basic_auth.edit.pass') }}">
+      {% trans %}Change your password.{% endtrans %}
+    </a>
+  </p>
+{% endblock %}
diff --git a/mediagoblin/plugins/basic_auth/templates/mediagoblin/plugins/basic_auth/fp_head.html b/mediagoblin/plugins/basic_auth/templates/mediagoblin/plugins/basic_auth/fp_head.html
new file mode 100644 (file)
index 0000000..292dce2
--- /dev/null
@@ -0,0 +1,20 @@
+{#
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2011, 2012 MediaGoblin contributors.  See AUTHORS.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+ You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#}
+
+<script type="text/javascript"
+          src="{{ request.staticdirect('/js/autofilledin_password.js', 'coreplugin_basic_auth') }}"></script>
diff --git a/mediagoblin/plugins/basic_auth/templates/mediagoblin/plugins/basic_auth/fp_link.html b/mediagoblin/plugins/basic_auth/templates/mediagoblin/plugins/basic_auth/fp_link.html
new file mode 100644 (file)
index 0000000..404358d
--- /dev/null
@@ -0,0 +1,25 @@
+{#
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2011, 2012 MediaGoblin contributors.  See AUTHORS.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#}
+
+{% block fp_link %}
+  <p>
+    <a href="{{ request.urlgen('mediagoblin.plugins.basic_auth.forgot_password') }}" id="forgot_password">
+      {% trans %}Forgot your password?{% endtrans %}</a>
+  </p>
+{% endblock %}
+
index 8d74c2b94259d7de758b98751ca1b71d2c04e6f9..193a3b2d234da9e72cf7264b285b1948191b9e6a 100644 (file)
@@ -20,8 +20,8 @@
 {% import "/mediagoblin/utils/wtforms.html" as wtforms_util %}
 
 {% block mediagoblin_head %}
-  <script type="text/javascript"
-          src="{{ request.staticdirect('/js/autofilledin_password.js') }}"></script>
+ {{ super() }}
+ {% template_hook("fp_head") %}
 {% endblock %}
 
 {% block title -%}
index 3329b5d0c9b44784b1b8d1a9c29339364061576d..c394245e2bda7c96ba07ca411d24d56a19edc394 100644 (file)
@@ -20,8 +20,8 @@
 {% import "/mediagoblin/utils/wtforms.html" as wtforms_util %}
 
 {% block mediagoblin_head %}
-  <script type="text/javascript"
-          src="{{ request.staticdirect('/js/autofilledin_password.js') }}"></script>
+  {{ super() }}
+  {% template_hook("fp_head") %}
 {% endblock %}
 
 {% block title -%}
       {% endif %}
       {% template_hook("login_link") %} 
       {{ wtforms_util.render_divs(login_form, True) }}
-      {% if pass_auth %}
-      <p>
-        <a href="{{ request.urlgen('mediagoblin.auth.forgot_password') }}" id="forgot_password">
-        {% trans %}Forgot your password?{% endtrans %}</a>
-      </p>
-      {% endif %}
+      {% template_hook("fp_link") %}
       <div class="form_submit_buttons">
         <input type="submit" value="{% trans %}Log in{% endtrans %}" class="button_form"/>
       </div>
index 51293acbc1a5eb75230e72608f88a63b1ed856f0..069cfd852e1974095216c1272f4f63caec21bd81 100644 (file)
           Changing {{ username }}'s account settings
         {%- endtrans -%}
       </h1>
-      {% if pass_auth is defined %}
-      <p>
-        <a href="{{ request.urlgen('mediagoblin.edit.pass') }}">
-          {% trans %}Change your password.{% endtrans %}
-        </a>
-      </p>
-      {% endif %}
       {% template_hook("edit_link") %} 
       {{ wtforms_util.render_divs(form, True) }}
      <div class="form_submit_buttons">