Working on render with data.
parent
d71b960ecf
commit
35c093835e
|
@ -146,7 +146,7 @@
|
|||
e.stopPropagation();
|
||||
},
|
||||
test: function() {
|
||||
console.log(this.model.attributes);
|
||||
this.render();
|
||||
}
|
||||
});
|
||||
SniptListView = Backbone.View.extend({
|
||||
|
@ -165,26 +165,37 @@
|
|||
|
||||
var $el = $(this);
|
||||
var $h1 = $('header h1 a', $el);
|
||||
var $pub = $('div.public', $el);
|
||||
var is_public = $pub.text() === 'True' ? true : false;
|
||||
var tag_lis = $('section.tags li', $el);
|
||||
var tags = [];
|
||||
|
||||
for (var i=0; i < tag_lis.length; i++) {
|
||||
var $tag = $('a', tag_lis.eq(i));
|
||||
tags[i] = {
|
||||
name: $tag.text(),
|
||||
absolute_url: $tag.attr('href')
|
||||
};
|
||||
}
|
||||
|
||||
var data = {
|
||||
absolute_url: $h1.attr('href'),
|
||||
code: '',
|
||||
created: '',
|
||||
description: '',
|
||||
embed_url: '',
|
||||
code: $('div.raw', $el).text(),
|
||||
created: $('li.created', $el).attr('title'),
|
||||
embed_url: $('div.embed-url', $el).text(),
|
||||
id: parseInt($el.attr('id').replace('snipt-', ''), 0),
|
||||
key: '',
|
||||
lexer: '',
|
||||
line_count: 0,
|
||||
modified: '',
|
||||
pub: false,
|
||||
resource_uri: '',
|
||||
slug: '',
|
||||
stylized: '',
|
||||
tags: [],
|
||||
tags_list: '',
|
||||
key: $('div.key', $el).text(),
|
||||
lexer: $('div.lexer', $el).text(),
|
||||
line_count: parseInt($('div.line-count', $el).text(), 0),
|
||||
modified: $('div.modified', $el).text(),
|
||||
pub: is_public,
|
||||
resource_uri: $('div.resource-uri', $el).text(),
|
||||
slug: $('div.slug', $el).text(),
|
||||
stylized: $('div.stylized', $el).text(),
|
||||
tags: tags,
|
||||
tags_list: $('div.tags-list', $el).text(),
|
||||
title: $h1.text(),
|
||||
user: ''
|
||||
user: $('div.user', $el).text()
|
||||
};
|
||||
|
||||
var view = new SniptView({
|
||||
|
|
|
@ -96,17 +96,12 @@ def snipts():
|
|||
key = row[8]
|
||||
slug = row[9]
|
||||
|
||||
if len(title) > 255:
|
||||
description = title
|
||||
title = 'Unknown (original title was too long)'
|
||||
else:
|
||||
description = ''
|
||||
title = title[:255]
|
||||
|
||||
snipt = Snipt(
|
||||
id=snipt_id,
|
||||
code=code,
|
||||
title=title,
|
||||
description=description,
|
||||
slug=slug,
|
||||
lexer=lexer,
|
||||
key=key,
|
||||
|
|
|
@ -54,7 +54,7 @@ class PublicSniptResource(ModelResource):
|
|||
class Meta:
|
||||
queryset = Snipt.objects.filter(public=True).order_by('-created')
|
||||
resource_name = 'snipt'
|
||||
fields = ['title', 'description', 'slug', 'lexer', 'code', 'line_count',
|
||||
fields = ['title', 'slug', 'lexer', 'code', 'line_count',
|
||||
'stylized', 'created', 'modified',]
|
||||
include_absolute_url = True
|
||||
allowed_methods = ['get']
|
||||
|
@ -129,7 +129,7 @@ class PrivateSniptResource(ModelResource):
|
|||
class Meta:
|
||||
queryset = Snipt.objects.all().order_by('-created')
|
||||
resource_name = 'snipt'
|
||||
fields = ['title', 'description', 'slug', 'lexer', 'code', 'line_count',
|
||||
fields = ['title', 'slug', 'lexer', 'code', 'line_count',
|
||||
'stylized', 'key', 'public', 'created', 'modified',]
|
||||
validation = Validation()
|
||||
include_absolute_url = True
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
# encoding: 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):
|
||||
|
||||
# Deleting field 'Snipt.description'
|
||||
db.delete_column('snipts_snipt', 'description')
|
||||
|
||||
|
||||
def backwards(self, orm):
|
||||
|
||||
# Adding field 'Snipt.description'
|
||||
db.add_column('snipts_snipt', 'description', self.gf('django.db.models.fields.TextField')(null=True, blank=True), keep_default=False)
|
||||
|
||||
|
||||
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', [], {}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'modified': ('django.db.models.fields.DateTimeField', [], {}),
|
||||
'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'},
|
||||
'code': ('django.db.models.fields.TextField', [], {}),
|
||||
'created': ('django.db.models.fields.DateTimeField', [], {}),
|
||||
'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', [], {}),
|
||||
'public': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'slug': ('django.db.models.fields.SlugField', [], {'db_index': 'True', 'max_length': '255', 'blank': 'True'}),
|
||||
'stylized': ('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'})
|
||||
},
|
||||
'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', 'db_index': 'True'})
|
||||
},
|
||||
'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']
|
|
@ -4,6 +4,7 @@ from django.conf import settings
|
|||
from django.db import models
|
||||
|
||||
from taggit.managers import TaggableManager
|
||||
from taggit.utils import edit_string_for_tags
|
||||
|
||||
from pygments import highlight
|
||||
from pygments.lexers import get_lexer_by_name
|
||||
|
@ -22,7 +23,6 @@ class Snipt(models.Model):
|
|||
user = models.ForeignKey(User, blank=True, null=True)
|
||||
|
||||
title = models.CharField(max_length=255)
|
||||
description = models.TextField(blank=True, null=True)
|
||||
slug = models.SlugField(max_length=255, blank=True)
|
||||
tags = TaggableManager()
|
||||
|
||||
|
@ -78,6 +78,10 @@ class Snipt(models.Model):
|
|||
def sorted_tags(self):
|
||||
return self.tags.all().order_by('name')
|
||||
|
||||
@property
|
||||
def tags_list(self):
|
||||
return edit_string_for_tags(self.tags.all())
|
||||
|
||||
@property
|
||||
def lexer_name(self):
|
||||
return get_lexer_by_name(self.lexer).name
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% load humanize %}
|
||||
|
||||
<article id="snipt-{{ snipt.pk }}" class="snipt {% if not snipt.public %}private-snipt{% endif %} {% if snipt.line_count > 8 and not detail %}expandable{% endif %} {% if snipt.user == request.user %}editable{% endif %}">
|
||||
<div class="number">#{{ snipt.id }}</div>
|
||||
<div class="number">#{{ snipt.pk }}</div>
|
||||
<div class="group">
|
||||
<div class="container">
|
||||
<header>
|
||||
|
@ -55,8 +55,8 @@
|
|||
<footer>
|
||||
<ul class="attrs">
|
||||
<li class="author"><a href="{{ snipt.user.get_absolute_url }}">{{ snipt.user.username }}</a></li>
|
||||
<li class="created">{{ snipt.created|naturalday }}</li>
|
||||
<li class="comments"><a href="{{ snipt.get_full_absolute_url }}#disqus_thread" data-disqus-identifier="{{ snipt.id }}"></a></li>
|
||||
<li class="created" title="{{ snipt.created|date:"Y-m-d\TH:i:s" }}">{{ snipt.created|naturalday }}</li>
|
||||
<li class="comments"><a href="{{ snipt.get_full_absolute_url }}#disqus_thread" data-disqus-identifier="{{ snipt.pk }}"></a></li>
|
||||
</ul>
|
||||
</footer>
|
||||
<div class="modal hide copy-modal">
|
||||
|
@ -73,7 +73,22 @@
|
|||
<h3>Embed snipt <span>“{{ snipt.title }}”</span></h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<textarea><script type="text/javascript">{{ snipt.get_embed_url }}</script></textarea>
|
||||
<textarea><script type="text/javascript">{{ snipt.get_embed_url }}</script></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hide embed-url">{{ snipt.get_embed_url }}</div>
|
||||
<div class="hide key">{{ snipt.key }}</div>
|
||||
<div class="hide lexer">{{ snipt.lexer }}</div>
|
||||
<div class="hide line-count">{{ snipt.line_count }}</div>
|
||||
<div class="hide modified">{{ snipt.modified|date:"Y-m-d\TH:i:s" }}</div>
|
||||
<div class="hide public">{{ snipt.public }}</div>
|
||||
{% if snipt.user == request.user %}
|
||||
<div class="hide resource-uri">/api/private/snipt/{{ snipt.pk }}/</div>
|
||||
{% else %}
|
||||
<div class="hide resource-uri">/api/public/snipt/{{ snipt.pk }}/</div>
|
||||
{% endif %}
|
||||
<div class="hide slug">{{ snipt.slug }}</div>
|
||||
<div class="hide stylized">{{ snipt.stylized }}</div>
|
||||
<div class="hide tags-list">{{ snipt.tags_list }}</div>
|
||||
<div class="hide user">{{ snipt.user.username }}</div>
|
||||
</article>
|
||||
|
|
|
@ -238,7 +238,7 @@
|
|||
<div class="container">
|
||||
<header>
|
||||
<h2></h2>
|
||||
<h1><a href="{{url}}">{{title}}</a></h1>
|
||||
<h1><a href="{{absolute_url}}">{{title}}</a></h1>
|
||||
</header>
|
||||
<section class="code autumn">
|
||||
</section>
|
||||
|
|
Loading…
Reference in New Issue