-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add preview index with module autodiscovery.
Reviewers: jeff, dcramer Reviewed By: dcramer Differential Revision: http://phabricator.local.disqus.net/D4488
- Loading branch information
Showing
17 changed files
with
359 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
__version__ = (0, 3, 3) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
Oops, something went wrong.