Basic stats for Pro users.

master
Nick Sergeant 2012-09-17 13:26:54 -04:00
parent 9e40a6af9e
commit 5900c5d55e
9 changed files with 140 additions and 8 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -753,7 +753,7 @@ article.snipt {
}
}
section.code {
height: 200px;
height: 230px;
overflow: hidden;
position: relative;
z-index: 49;
@ -806,7 +806,7 @@ article.snipt {
border: none;
font: normal 12px/16px $Consolas;
margin: 0;
min-height: 190px;
min-height: 220px;
overflow-x: auto;
padding: 5px;
white-space: pre;
@ -1010,8 +1010,8 @@ article.snipt {
}
}
}
section.tags {
padding-top: 15px;
section.meta {
padding-top: 10px;
h2 {
background: transparent url('/static/images/snipt-tags-icon.png') 15px center no-repeat;
@ -1023,6 +1023,8 @@ article.snipt {
margin: 0;
li {
color: #999;
font: normal 12px $Helvetica;
list-style-type: none;
margin: 5px 10px 5px 35px;

View File

@ -205,6 +205,10 @@ class PrivateSniptResource(ModelResource):
bundle.data['tags_list'] = edit_string_for_tags(bundle.obj.tags.all())
bundle.data['full_absolute_url'] = bundle.obj.get_full_absolute_url()
if bundle.data['user'].data['profile']['is_pro']:
bundle.data['views'] = bundle.obj.views
bundle.data['favs'] = bundle.obj.favs()
if bundle.data['publish_date']:
bundle.data['publish_date'] = date(bundle.data['publish_date'], 'M d, Y \\a\\t h:i A')

View File

@ -0,0 +1,102 @@
# -*- 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.views'
db.add_column('snipts_snipt', 'views',
self.gf('django.db.models.fields.IntegerField')(default=0),
keep_default=False)
def backwards(self, orm):
# Deleting field 'Snipt.views'
db.delete_column('snipts_snipt', 'views')
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'}),
'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']

View File

@ -109,6 +109,9 @@ class Snipt(models.Model):
def __unicode__(self):
return self.title
def favs(self):
return Favorite.objects.filter(snipt=self).count()
def get_absolute_url(self):
if self.blog_post:

View File

@ -43,7 +43,7 @@
<a class="copy" href="#">Copy</a>
</li>
</ul>
<section class="tags">
<section class="meta tags">
<h2><%= snipt.tags.length %> tag<% if ((snipt.tags.length > 1) || (snipt.tags.length === 0)) { print('s'); } %></h2>
<ul>
<% for (var i=0; i < snipt.tags.length; i++) { %>
@ -53,6 +53,14 @@
<% } %>
</ul>
</section>
<% if (snipt.user.profile.is_pro) { %>
<section class="meta stats">
<ul>
<li><%= snipt.views %> views</li>
<li><%= snipt.favs %> favs</li>
</ul>
</section>
<% } %>
</aside>
</div>
<footer>

View File

@ -77,7 +77,7 @@
{% endif %}
</ul>
{% if snipt.tags.all %}
<section class="tags">
<section class="meta tags">
<h2>{{ snipt.tags.all|length }} tag{{ snipt.tags.all|pluralize }}</h2>
<ul>
{% for tag in snipt.sorted_tags %}
@ -92,6 +92,16 @@
</ul>
</section>
{% endif %}
{% if request.user.profile.is_pro and snipt.user == request.user %}
<section class="meta stats">
<ul>
<li>{{ snipt.views|intcomma }} view{{ snipt.views|pluralize }}
{% if not snipt.blog_post %}
<li>{{ snipt.favs|intcomma }} fav{{ snipt.favs|pluralize }}
{% endif %}
</ul>
</section>
{% endif %}
</aside>
{% endblock %}
</div>

View File

@ -46,6 +46,9 @@ def detail(request, username, snipt_slug):
if request.GET.get('key') != snipt.key:
raise Http404
snipt.views = snipt.views + 1
snipt.save()
tags = Tag.objects
if user == request.user: