Permalink
Browse files

Add page to view all currently active snippets.

  • Loading branch information...
1 parent 2ff5ad1 commit 97a924f279a2af9e9c5eef7aaf21d474649ef1b9 @Osmose Osmose committed May 30, 2012
@@ -0,0 +1,77 @@
+{% load i18n %}
+{% load getattribute %}
+
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <title>{% trans 'about:home Snippets' %}</title>
+
+ <link rel="stylesheet" href="{{ MEDIA_URL }}css/bootstrap.min.css">
+ <link rel="stylesheet" href="{{ MEDIA_URL }}css/show_all_snippets.css">
+ </head>
+ <body>
+ <div class="navbar">
+ <div class="navbar-inner">
+ <div class="container">
+ <a href="#" class="brand">{% trans 'about:home Snippets' %}</a>
+ </div>
+ </div>
+ </div>
+
+ <div class="container-fluid">
+ <div class="row-fluid">
+ <div class="span12">
+ <table class="table table-striped table-bordered">
+ <tbody>
+ {% for snippet in snippets %}
+ <tr>
+ <td class="preview">
+ <div class="snippet-preview">
+ {{ snippet.body|safe }}
+ </div>
+ </td>
+ <td>
+ <h2>{% trans 'Code' %}</h2>
+ <pre class="pre-scrollable">{{ snippet.body }}</pre>
+
+ <h2>{% trans 'Client Match Rules' %}</h2>
+ <ul>
+ {% for rule in snippet.client_match_rules.all %}
+ <li>
+ {{ rule.description }}
+ <ul>
+ <li>
+ {% if rule.exclude %}
+ {% trans 'Exclusion Rule' %}
+ {% else %}
+ {% trans 'Inclusion Rule' %}
+ {% endif %}
+ </li>
+ {% for field in fields %}
+ {% with rule|getattribute:field as value %}
+ {% if value != '' and value != None %}
+ <li>
+ {% blocktrans %}
+ <strong>{{ field }}</strong>: <code>{{ value }}</code>
+ {% endblocktrans %}
+ </li>
+ {% endif %}
+ {% endwith %}
+ {% endfor %}
+ </ul>
+ </li>
+ {% endfor %}
+ </ul>
+ </td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ </div>
+ </div>
+ </div>
+
+
+ </body>
+</html>
@@ -0,0 +1,20 @@
+import re
+from django import template
+from django.conf import settings
+
+numeric_test = re.compile("^\d+$")
+register = template.Library()
+
+def getattribute(value, arg):
+ """Gets an attribute of an object dynamically from a string name"""
+
+ if hasattr(value, str(arg)):
+ return getattr(value, arg)
+ elif hasattr(value, 'has_key') and value.has_key(arg):
+ return value[arg]
+ elif numeric_test.match(str(arg)) and len(value) > int(arg):
+ return value[int(arg)]
+ else:
+ return settings.TEMPLATE_STRING_IF_INVALID
+
+register.filter('getattribute', getattribute)
@@ -19,5 +19,6 @@
url(r'^base64encode$', 'base64_encode', name='base64_encode'),
url(r'^admin/bulk_date_change$', 'admin_bulk_date_change',
name='admin_bulk_date_change'),
+ url(r'^show_all_snippets$', 'show_all_snippets', name='show_all_snippets'),
url(r'^$', 'index', name='index'),
)
View
@@ -115,3 +115,16 @@ def admin_bulk_date_change(request, **kwargs):
return render_to_response('adminBulkDateChange.html',
{'form': form},
context_instance=RequestContext(request))
+
+
+def show_all_snippets(request):
+ """
+ Show a list of all public snippets and their relevant client match rules.
+ """
+ snippets = Snippet.objects.filter(disabled=False, preview=False)
+ fields = ('startpage_version', 'name', 'version', 'appbuildid',
+ 'build_target', 'locale', 'channel', 'os_version',
+ 'distribution', 'distribution_version')
+ return render_to_response('show_all_snippets.html',
+ {'snippets': snippets, 'fields': fields},
+ context_instance=RequestContext(request))

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,47 @@
+/* PREVIEW */
+.snippet-preview {
+ padding: 14px;
+ width: 600px;
+ background-image: -moz-linear-gradient(rgba(255,255,255,.8), rgba(255,255,255,.1));
+ background-color: rgb(250,250,250);
+ border-radius: 4px;
+ box-shadow: 0 1px 0 rgba(255,255,255,.8) inset,
+ 0 -2px 0 rgba(0,0,0,.1) inset,
+ 0 0 10px rgba(255,255,255,.5) inset,
+ 0 0 0 1px rgba(0,0,0,.1),
+ 0 2px 4px rgba(0,0,0,.2);
+ color: rgb(60,60,60);
+ font-size: 13px;
+ cursor: pointer;
+ display: inline-block;
+ text-align: center;
+ min-height: 30px;
+ margin: 10px 0;
+}
+
+.snippet-preview:hover {
+ background-color: rgb(255,255,255);
+ box-shadow: 0 1px 0 rgba(255,255,255,.8) inset,
+ 0 -2px 0 rgba(0,0,0,.1) inset,
+ 0 0 10px rgba(255,255,255,.5) inset,
+ 0 0 5px rgba(0,0,0,.1),
+ 0 0 0 1px rgba(0,0,0,.1),
+ 0 2px 4px rgba(0,0,0,.2);
+}
+
+.snippet-preview:hover:active {
+ background-color: rgb(210,210,210);
+ box-shadow: 0 2px 3px rgba(0,0,0,.3) inset,
+ 0 1px 0 rgba(255,255,255,.5);
+}
+
+.snippet-preview p {
+ margin: 10px 0px;
+ padding: 0px;
+ font-size: 13px;
+}
+
+.snippet-preview img.icon {
+ margin: -0.75em 1em 0 0;
+ float: left;
+}
@@ -1,82 +1,82 @@
#snippet-editor {
- margin-left: 7.2em;
- padding-left: 30px;
+ margin-left: 7.2em;
+ padding-left: 30px;
}
#snippet-basic-inputs label {
- width: auto;
- float: none;
+ width: auto;
+ float: none;
}
#snippet-basic-inputs input,
#snippet-basic-inputs textarea {
- width: 624px;
+ width: 624px;
}
#snippet-basic-inputs textarea {
- height: 150px;
+ height: 150px;
}
#snippet-basic:after {
- content: ".";
- clear: both;
- display: block;
- height: 0;
- visibility: hidden;
+ content: ".";
+ clear: both;
+ display: block;
+ height: 0;
+ visibility: hidden;
}
#snippet-advanced textarea {
- height: 200px;
- width: 628px;
+ height: 200px;
+ width: 628px;
}
/* TABS */
#snippet-editor ul {
- margin: 0;
- padding: 0;
+ margin: 0;
+ padding: 0;
}
#snippet-editor ul li {
- background: #CCCCCC;
- border: 1px solid #999999;
- border-bottom: none;
- display: inline-block;
+ background: #CCCCCC;
+ border: 1px solid #999999;
+ border-bottom: none;
+ display: inline-block;
}
#snippet-editor ul li.active {
- background: #FFFFFF;
+ background: #FFFFFF;
}
#snippet-editor ul li a {
- display: block;
- padding: 5px;
- outline: none;
+ display: block;
+ padding: 5px;
+ outline: none;
}
#snippet-editor .panel-container {
- border: 1px solid #999999;
- padding: 10px;
+ border: 1px solid #999999;
+ padding: 10px;
}
/* PREVIEW */
#snippet-preview {
- padding: 14px;
- width: 600px;
- background-image: -moz-linear-gradient(rgba(255,255,255,.8), rgba(255,255,255,.1));
- background-color: rgb(250,250,250);
- border-radius: 4px;
- box-shadow: 0 1px 0 rgba(255,255,255,.8) inset,
+ padding: 14px;
+ width: 600px;
+ background-image: -moz-linear-gradient(rgba(255,255,255,.8), rgba(255,255,255,.1));
+ background-color: rgb(250,250,250);
+ border-radius: 4px;
+ box-shadow: 0 1px 0 rgba(255,255,255,.8) inset,
0 -2px 0 rgba(0,0,0,.1) inset,
0 0 10px rgba(255,255,255,.5) inset,
0 0 0 1px rgba(0,0,0,.1),
0 2px 4px rgba(0,0,0,.2);
- color: rgb(60,60,60);
- font-size: 13px;
- cursor: pointer;
- display: inline-block;
- text-align: center;
- min-height: 30px;
- margin: 10px 0;
+ color: rgb(60,60,60);
+ font-size: 13px;
+ cursor: pointer;
+ display: inline-block;
+ text-align: center;
+ min-height: 30px;
+ margin: 10px 0;
}
#snippet-preview:hover {
@@ -96,12 +96,12 @@
}
#snippet-preview p {
- margin: 10px 0px;
- padding: 0px;
- font-size: 13px;
+ margin: 10px 0px;
+ padding: 0px;
+ font-size: 13px;
}
#snippet-preview img.icon {
- margin: -0.75em 1em 0 0;
- float: left;
-}
+ margin: -0.75em 1em 0 0;
+ float: left;
+}

0 comments on commit 97a924f

Please sign in to comment.