Skip to content

Commit

Permalink
Add preview index with module autodiscovery.
Browse files Browse the repository at this point in the history
Reviewers: jeff, dcramer

Reviewed By: dcramer

Differential Revision: http://phabricator.local.disqus.net/D4488
  • Loading branch information
tkaemming committed Jan 2, 2013
1 parent 849df95 commit 81ba02f
Show file tree
Hide file tree
Showing 17 changed files with 359 additions and 177 deletions.
1 change: 0 additions & 1 deletion mailviews/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
__version__ = (0, 3, 3)
56 changes: 56 additions & 0 deletions mailviews/previews.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import logging

from django.conf import settings
from django.core.urlresolvers import reverse
from django.utils.importlib import import_module
from django.utils.module_loading import module_has_submodule

from mailviews.utils import unimplemented


logger = logging.getLogger(__name__)

registry = {}


class Preview(object):
message_view = property(unimplemented) # must be implemented by subclasses
description = None
verbose_name = None

def __str__(self):
return self.verbose_name or self.message_view.__name__

@property
def module(self):
return '%s' % self.message_view.__module__

@property
def identifier(self):
return self.message_view.__name__

@property
def url(self):
return reverse('mailviews-preview-detail', kwargs={
'module': self.module,
'identifier': self.identifier
})

def get_message_view(self, request):
return self.message_view()


def register(preview):
logger.debug('Registering %s...', preview)
preview = preview()
registry.setdefault(preview.module, {})[preview.identifier] = preview


def autodiscover():
for application in settings.INSTALLED_APPS:
module = import_module(application)
try:
import_module('%s.emails' % application)
except ImportError:
if module_has_submodule(module, 'emails'):
raise
41 changes: 34 additions & 7 deletions mailviews/static/mailviews/css/mailviews.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,35 @@ body {
padding-top: 60px;
}

section {
border-bottom: 1px solid #ddd;
padding-bottom: 20px;
margin-bottom: 20px;
}

section:last-child {
border-bottom: 0;
padding-bottom: 0;
}

/* List */

#message-list table th,
#message-list table td {
border: 0;
}

#message-list th {
width: 220px;
}

#message-list .description {
font-size: 12px;
color: #777;
}

/* Details */

#html iframe,
#html textarea {
border: 0;
Expand All @@ -14,13 +43,11 @@ body {
padding: 0;
}

section {
border-bottom: 1px solid #ddd;
padding-bottom: 20px;
margin-bottom: 20px;
#headers th,
#headers td {
border: 0;
}

section.last {
border-bottom: 0;
padding-bottom: 0;
#headers th {
width: 120px;
}
33 changes: 33 additions & 0 deletions mailviews/templates/mailviews/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!doctype html>
<html lang="en">
<head>

{% load mailviews %}

<link rel="stylesheet" type="text/css" href="{% mailviews_static 'mailviews/css/bootstrap.css' %}" />
<link rel="stylesheet" type="text/css" href="{% mailviews_static 'mailviews/css/mailviews.css' %}" />

<script type="text/javascript" src="{% mailviews_static 'mailviews/javascript/jquery.js' %}"></script>
<script type="text/javascript" src="{% mailviews_static 'mailviews/javascript/bootstrap-tab.js' %}"></script>

</head>
<body>

<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="{% url mailviews-preview-list %}">Message Preview</a>
{% block navigation %}{% endblock %}
</div>
</div>
</div>

<div class="container {% block container-class %}{% endblock %}">

{% block content %}
{% endblock %}

</div>

</body>
</html>
106 changes: 0 additions & 106 deletions mailviews/templates/mailviews/message.html

This file was deleted.

92 changes: 92 additions & 0 deletions mailviews/templates/mailviews/previews/detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{% extends "mailviews/base.html" %}

{% block container-class %}preview detail{% endblock %}

{% block navigation %}

<div class="nav-collapse collapse">
<ul class="nav">
{% if html %}
<li><a href="#html">HTML</a></li>
{% endif %}
<li><a href="#body-plain">Text</a></li>
<li><a href="#raw">Raw</a></li>
</ul>
</div>

{% endblock %}

{% block content %}

<div class="page-header">
<h2>
{{ preview }}
<small>{{ preview.module }}</small>
</h2>
</div>

<header>

<div id="headers">

<table class="table table-condensed">
{% for name, value in headers.items %}
<tr class="{{ name|slugify }}">
<th>{{ name }}</th>
<td>{{ value }}</td>
</tr>
{% endfor %}
</table>

</div>

</header>

{% if html %}

<div id="html">

<h3>HTML</h3>

<ul class="nav nav-tabs">
<li class="active"><a href="#body-html" data-toggle="tab">Preview</a></li>
<li><a href="#html-raw" data-toggle="tab">Source</a></li>
</ul>

<div class="tab-content">

<section id="body-html" class="tab-pane active">
<iframe src="data:text/html;base64,{{ escaped_html }}" frameborder="0" allowtransparency="true"></iframe>
</section>

<section id="html-raw" class="tab-pane">
<textarea>{{ html|escape }}</textarea>
</section>

</div>

</div>

{% endif %}

<section id="body-plain">

<h3>Text</h3>

{% if body %}
{{ body|linebreaks }}
{% else %}
<p class="alert">This message doesn't contain any text content.</p>
{% endif %}

</section>

<section id="raw" class="last">

<h3>Raw</h3>

<pre>{{ raw }}</pre>

</section>

{% endblock %}
26 changes: 26 additions & 0 deletions mailviews/templates/mailviews/previews/list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% extends "mailviews/base.html" %}

{% block container-class %}preview list{% endblock %}

{% block content %}

<section id="message-list">

{% for module, previews in registry.items %}

<h2><small>{{ module }}</small></h2>

<table class="table">
{% for preview in previews.values %}
<tr>
<th><a href="{{ preview.url }}">{{ preview }}</a></th>
<td class="description">{{ preview.description }}</td>
</tr>
{% endfor %}
</table>

{% endfor %}

</div>

{% endblock %}
Loading

0 comments on commit 81ba02f

Please sign in to comment.