Skip to content

Commit

Permalink
code commit
Browse files Browse the repository at this point in the history
  • Loading branch information
timbroder committed Feb 3, 2010
1 parent a165af5 commit 068df37
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
21 changes: 21 additions & 0 deletions adminpreview/admin.py
@@ -0,0 +1,21 @@
class PreviewAdmin(admin.ModelAdmin):
def admin_slide_preview(self, obj):
return "<div class=\"previewslide\" id=\"%s/preview/\">+</div>" % obj.id
admin_slide_preview.allow_tags = True
admin_slide_preview.short_description = 'Preview'

def get_preview(self, request, object_id):
sub = self.queryset(request)[0]
template = "preview/%s.html" % sub.__class__.__name__
return object_detail(request, queryset=self.queryset(request), object_id=object_id, template_name=template.lower())

def get_urls(self):
urls = super(PreviewAdmin, self).get_urls()
my_urls = patterns('',
(r'^(?P<object_id>\d+)/preview/$', self.get_preview),
)
return my_urls + urls

class Media:
js = js = ('js/jquery.js',
'js/jquery.adminpreview.js'
25 changes: 25 additions & 0 deletions adminpreview/templates/preview/article.html
@@ -0,0 +1,25 @@
<tr>
<td colspan="5">
<table>
<tr>
<td>
<img src="{{ object.image.featured.url }}">
</td>
<td>
Abstract:<br/>
{{ object.abstract }}
</td>
<td>
Author: {{ object.author }}<br/>
Published: {{ object.published_date }}<br/>
Category: {{ object.category }}<br/>
<br/>
Tags: {% for tag in object.get_tags %}
{{ tag }}
{% if not forloop.last %}, {% endif %}
{% endfor %}
</td>
</tr>
</table>
</td>
</tr>
4 changes: 4 additions & 0 deletions static/css/admin/base.css
@@ -0,0 +1,4 @@
.previewslide {
cursor:pointer;
cursor:hand;
}
21 changes: 21 additions & 0 deletions static/js/jquery.adminpreview.js
@@ -0,0 +1,21 @@
$(document).ready(function(){
$(".previewslide").click(function(){
$.ajax({
url:$(this).attr('id'),
context: $(this).parent().parent(),
success:function(data){
var $html = $(data);
$('.previewed').each(function(){
$(this).remove();
});

if(!$html.hasClass('previewed')){
$html.addClass('previewed');
}

$html.addClass($(this.context).attr('class'));
$(this.context).after($html);
}
});
});
});

0 comments on commit 068df37

Please sign in to comment.