Fix for long snipts in list view.
parent
12f06a781d
commit
14b65acab4
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -795,7 +795,7 @@ article.snipt {
|
|||
margin: 20px 0 !important;
|
||||
}
|
||||
}
|
||||
a.expand {
|
||||
a.expand, a.view-full {
|
||||
background: #FFF url('/static/images/expand.png') 15px 18px no-repeat;
|
||||
border-top: 1px solid #F1F1EE;
|
||||
bottom: 0;
|
||||
|
@ -825,6 +825,9 @@ article.snipt {
|
|||
outline: none;
|
||||
}
|
||||
}
|
||||
a.view-full {
|
||||
background: #FFF url('/static/images/view-full.png') 15px 17px no-repeat;
|
||||
}
|
||||
textarea.raw {
|
||||
display: none;
|
||||
}
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
|
@ -0,0 +1,103 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
from south.db import db
|
||||
from south.v2 import SchemaMigration
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Migration(SchemaMigration):
|
||||
|
||||
def forwards(self, orm):
|
||||
# Adding field 'Snipt.stylized_min'
|
||||
db.add_column('snipts_snipt', 'stylized_min',
|
||||
self.gf('django.db.models.fields.TextField')(null=True, blank=True),
|
||||
keep_default=False)
|
||||
|
||||
|
||||
def backwards(self, orm):
|
||||
# Deleting field 'Snipt.stylized_min'
|
||||
db.delete_column('snipts_snipt', 'stylized_min')
|
||||
|
||||
|
||||
models = {
|
||||
'auth.group': {
|
||||
'Meta': {'object_name': 'Group'},
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
|
||||
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
|
||||
},
|
||||
'auth.permission': {
|
||||
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
|
||||
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
|
||||
},
|
||||
'auth.user': {
|
||||
'Meta': {'object_name': 'User'},
|
||||
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
|
||||
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
|
||||
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
|
||||
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
|
||||
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
|
||||
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
|
||||
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
|
||||
},
|
||||
'contenttypes.contenttype': {
|
||||
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
|
||||
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
|
||||
},
|
||||
'snipts.favorite': {
|
||||
'Meta': {'object_name': 'Favorite'},
|
||||
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
|
||||
'snipt': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['snipts.Snipt']"}),
|
||||
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"})
|
||||
},
|
||||
'snipts.snipt': {
|
||||
'Meta': {'object_name': 'Snipt'},
|
||||
'blog_post': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'code': ('django.db.models.fields.TextField', [], {}),
|
||||
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'custom_slug': ('django.db.models.fields.SlugField', [], {'max_length': '255', 'blank': 'True'}),
|
||||
'embedded': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'key': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
|
||||
'lexer': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
|
||||
'line_count': ('django.db.models.fields.IntegerField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}),
|
||||
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
|
||||
'public': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'publish_date': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'slug': ('django.db.models.fields.SlugField', [], {'max_length': '255', 'blank': 'True'}),
|
||||
'stylized': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'stylized_min': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
|
||||
'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
|
||||
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
|
||||
'views': ('django.db.models.fields.IntegerField', [], {'default': '0'})
|
||||
},
|
||||
'taggit.tag': {
|
||||
'Meta': {'object_name': 'Tag'},
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '100'})
|
||||
},
|
||||
'taggit.taggeditem': {
|
||||
'Meta': {'object_name': 'TaggedItem'},
|
||||
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'taggit_taggeditem_tagged_items'", 'to': "orm['contenttypes.ContentType']"}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'object_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True'}),
|
||||
'tag': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'taggit_taggeditem_items'", 'to': "orm['taggit.Tag']"})
|
||||
}
|
||||
}
|
||||
|
||||
complete_apps = ['snipts']
|
|
@ -31,6 +31,7 @@ class Snipt(models.Model):
|
|||
lexer = models.CharField(max_length=50)
|
||||
code = models.TextField()
|
||||
stylized = models.TextField(blank=True, null=True)
|
||||
stylized_min = models.TextField(blank=True, null=True)
|
||||
embedded = models.TextField(blank=True, null=True)
|
||||
line_count = models.IntegerField(blank=True, null=True, default=None)
|
||||
|
||||
|
@ -112,6 +113,16 @@ class Snipt(models.Model):
|
|||
def favs(self):
|
||||
return Favorite.objects.filter(snipt=self).count()
|
||||
|
||||
def get_stylized_min(self):
|
||||
if self.stylized_min is None:
|
||||
if self.lexer == 'markdown':
|
||||
self.stylized_min = markdown(self.code[:1000], 'default')
|
||||
else:
|
||||
self.stylized_min = highlight(self.code[:1000],
|
||||
get_lexer_by_name(self.lexer, encoding='UTF-8'),
|
||||
HtmlFormatter(linenos='table', linenospecial=1, lineanchors='line'))
|
||||
return self.stylized_min
|
||||
|
||||
def get_absolute_url(self):
|
||||
|
||||
if self.blog_post:
|
||||
|
|
|
@ -2,7 +2,27 @@
|
|||
|
||||
{% snipt_is_favorited_by_user as 'is_favorited' %}
|
||||
|
||||
<article id="snipt-{{ snipt.pk }}" class="snipt {% if 'snipt-expand' in snipt.tags_list and snipt.blog_post %}snipt-expand {% endif %}{% if snipt.blog_post %}blog-post {% endif %}{% if not snipt.public %} private-snipt{% endif %}{% if snipt.line_count > 8 and not detail and 'snipt-expand' not in snipt.tags_list %} expandable{% endif %}{% if snipt.user == request.user %} editable{% endif %}{% if is_favorited %} favorited" data-favorite-id="{{ is_favorited }}"{% else %}"{% endif %}>
|
||||
<article id="snipt-{{ snipt.pk }}" class="snipt
|
||||
{% if 'snipt-expand' in snipt.tags_list and snipt.blog_post %}
|
||||
snipt-expand
|
||||
{% endif %}
|
||||
{% if snipt.blog_post %}
|
||||
blog-post
|
||||
{% endif %}
|
||||
{% if not snipt.public %}
|
||||
private-snipt
|
||||
{% endif %}
|
||||
{% if snipt.line_count > 8 and not detail and 'snipt-expand' not in snipt.tags_list %}
|
||||
expandable
|
||||
{% endif %}
|
||||
{% if snipt.user == request.user %}
|
||||
editable
|
||||
{% endif %}
|
||||
{% if is_favorited %}
|
||||
favorited" data-favorite-id="{{ is_favorited }}"
|
||||
{% else %}
|
||||
"
|
||||
{% endif %}>
|
||||
<div class="number">#{{ snipt.pk }}</div>
|
||||
<div class="group">
|
||||
<div class="container">
|
||||
|
@ -16,7 +36,11 @@
|
|||
<section class="code {% if request.GET.style %}{{ request.GET.style }}{% else %}autumn{% endif %}">
|
||||
{% if snipt.lexer == 'markdown' %}
|
||||
<div class="markdown">
|
||||
{{ snipt.stylized|safe }}
|
||||
{% if snipt.line_count > 300 and not detail %}
|
||||
{{ snipt.get_stylized_min|safe }}
|
||||
{% else %}
|
||||
{{ snipt.stylized|safe }}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% else %}
|
||||
{% if 'linenos' not in snipt.stylized %}
|
||||
|
@ -37,15 +61,30 @@
|
|||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
{{ snipt.stylized|safe }}
|
||||
{% if snipt.line_count > 300 and not detail %}
|
||||
{{ snipt.get_stylized_min|safe }}
|
||||
{% else %}
|
||||
{{ snipt.stylized|safe }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if snipt.line_count > 8 and not detail and 'snipt-expand' not in snipt.tags_list %}
|
||||
<a href="#" class="expand">
|
||||
<span class="expand">Expand</span>
|
||||
<span class="collapse">Collapse</span>
|
||||
<span class="lines">({{ snipt.line_count }} lines)</span>
|
||||
</a>
|
||||
{% if snipt.line_count > 300 %}
|
||||
<a href="{{ snipt.get_absolute_url }}" class="view-full">
|
||||
<span class="expand">
|
||||
View full
|
||||
</span>
|
||||
<span class="lines">({{ snipt.line_count }} lines) -- large snipt</span>
|
||||
</a>
|
||||
{% else %}
|
||||
<a href="#" class="expand">
|
||||
<span class="expand">
|
||||
Expand
|
||||
</span>
|
||||
<span class="collapse">Collapse</span>
|
||||
<span class="lines">({{ snipt.line_count }} lines)</span>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<textarea class="raw">{{ snipt.code }}</textarea>
|
||||
</section>
|
||||
|
|
Loading…
Reference in New Issue