This commit is contained in:
Ricky Rosario 2015-03-18 15:27:36 -04:00
Родитель 2cb7b3bd95
Коммит 9dc1e723ec
19 изменённых файлов: 392 добавлений и 218 удалений

Просмотреть файл

@ -1,12 +1,12 @@
"""Feeds for badge"""
import datetime
import hashlib
import json
import urllib
from django.contrib.syndication.views import Feed, FeedDoesNotExist
from django.utils.feedgenerator import (SyndicationFeed, Rss201rev2Feed,
Atom1Feed, get_tag_uri)
import django.utils.simplejson as json
from django.shortcuts import get_object_or_404
from django.contrib.auth.models import User

Просмотреть файл

@ -1,10 +1,10 @@
import django
import hashlib
import urllib
import urlparse
from django.conf import settings
from django.contrib.auth.models import SiteProfileNotAvailable
from django.core.exceptions import ObjectDoesNotExist
from django.utils.html import conditional_escape
@ -21,6 +21,13 @@ from jingo import register, env
from .models import (Badge, Award, Nomination, Progress,
BadgeAwardNotAllowedException)
if django.VERSION < (1, 7, 0):
from django.contrib.auth.models import SiteProfileNotAvailable
if django.VERSION >= (1, 7, 0):
class SiteProfileNotAvailable(Exception):
pass
@register.function
def user_avatar(user, secure=False, size=256, rating='pg', default=''):

Просмотреть файл

@ -1,161 +1,137 @@
# encoding: utf-8
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding model 'Badge'
db.create_table('badger_badge', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('title', self.gf('django.db.models.fields.CharField')(unique=True, max_length=255)),
('slug', self.gf('django.db.models.fields.SlugField')(unique=True, max_length=50, db_index=True)),
('description', self.gf('django.db.models.fields.TextField')(blank=True)),
('image', self.gf('django.db.models.fields.files.ImageField')(max_length=100, null=True, blank=True)),
('unique', self.gf('django.db.models.fields.BooleanField')(default=False)),
('creator', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'], null=True, blank=True)),
('created', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
('modified', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)),
))
db.send_create_signal('badger', ['Badge'])
# Adding unique constraint on 'Badge', fields ['title', 'slug']
db.create_unique('badger_badge', ['title', 'slug'])
# Adding M2M table for field prerequisites on 'Badge'
db.create_table('badger_badge_prerequisites', (
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
('from_badge', models.ForeignKey(orm['badger.badge'], null=False)),
('to_badge', models.ForeignKey(orm['badger.badge'], null=False))
))
db.create_unique('badger_badge_prerequisites', ['from_badge_id', 'to_badge_id'])
# Adding model 'Award'
db.create_table('badger_award', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('badge', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['badger.Badge'])),
('image', self.gf('django.db.models.fields.files.ImageField')(max_length=100, null=True, blank=True)),
('user', self.gf('django.db.models.fields.related.ForeignKey')(related_name='award_user', to=orm['auth.User'])),
('creator', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='award_creator', null=True, to=orm['auth.User'])),
('hidden', self.gf('django.db.models.fields.BooleanField')(default=False)),
('created', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
('modified', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)),
))
db.send_create_signal('badger', ['Award'])
# Adding model 'Progress'
db.create_table('badger_progress', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('badge', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['badger.Badge'])),
('user', self.gf('django.db.models.fields.related.ForeignKey')(related_name='progress_user', to=orm['auth.User'])),
('percent', self.gf('django.db.models.fields.FloatField')(default=0)),
('counter', self.gf('django.db.models.fields.FloatField')(default=0, null=True, blank=True)),
('notes', self.gf('badger.models.JSONField')(null=True, blank=True)),
('created', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
('modified', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)),
))
db.send_create_signal('badger', ['Progress'])
# Adding unique constraint on 'Progress', fields ['badge', 'user']
db.create_unique('badger_progress', ['badge_id', 'user_id'])
from django.db import models, migrations
import badger.models
from django.conf import settings
import django.core.files.storage
def backwards(self, orm):
# Removing unique constraint on 'Progress', fields ['badge', 'user']
db.delete_unique('badger_progress', ['badge_id', 'user_id'])
class Migration(migrations.Migration):
# Removing unique constraint on 'Badge', fields ['title', 'slug']
db.delete_unique('badger_badge', ['title', 'slug'])
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
# Deleting model 'Badge'
db.delete_table('badger_badge')
# Removing M2M table for field prerequisites on 'Badge'
db.delete_table('badger_badge_prerequisites')
# Deleting model 'Award'
db.delete_table('badger_award')
# Deleting model 'Progress'
db.delete_table('badger_progress')
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': '255'}),
'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'})
},
'badger.award': {
'Meta': {'object_name': 'Award'},
'badge': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['badger.Badge']"}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'creator': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'award_creator'", 'null': 'True', 'to': "orm['auth.User']"}),
'hidden': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'image': ('django.db.models.fields.files.ImageField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'award_user'", 'to': "orm['auth.User']"})
},
'badger.badge': {
'Meta': {'unique_together': "(('title', 'slug'),)", 'object_name': 'Badge'},
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'creator': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'image': ('django.db.models.fields.files.ImageField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'prerequisites': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['badger.Badge']", 'null': 'True', 'blank': 'True'}),
'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '50', 'db_index': 'True'}),
'title': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
'unique': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
},
'badger.progress': {
'Meta': {'unique_together': "(('badge', 'user'),)", 'object_name': 'Progress'},
'badge': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['badger.Badge']"}),
'counter': ('django.db.models.fields.FloatField', [], {'default': '0', 'null': 'True', 'blank': 'True'}),
'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'}),
'notes': ('badger.models.JSONField', [], {'null': 'True', 'blank': 'True'}),
'percent': ('django.db.models.fields.FloatField', [], {'default': '0'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'progress_user'", 'to': "orm['auth.User']"})
},
'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'})
}
}
complete_apps = ['badger']
operations = [
migrations.CreateModel(
name='Award',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('description', models.TextField(help_text=b'Explanation and evidence for the badge award', blank=True)),
('image', models.ImageField(storage=django.core.files.storage.FileSystemStorage(base_url=b'uploads/', location=b'uploads'), null=True, upload_to=badger.models.UploadTo(b'image', b'png'), blank=True)),
('claim_code', models.CharField(default=b'', help_text=b'Code used to claim this award', max_length=32, db_index=True, blank=True)),
('hidden', models.BooleanField(default=False)),
('created', models.DateTimeField(auto_now_add=True)),
('modified', models.DateTimeField(auto_now=True)),
],
options={
'ordering': ['-modified', '-created'],
},
bases=(models.Model,),
),
migrations.CreateModel(
name='Badge',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('title', models.CharField(help_text=b'Short, descriptive title', unique=True, max_length=255)),
('slug', models.SlugField(help_text=b'Very short name, for use in URLs and links', unique=True)),
('description', models.TextField(help_text=b'Longer description of the badge and its criteria', blank=True)),
('image', models.ImageField(help_text=b'Upload an image to represent the badge', storage=django.core.files.storage.FileSystemStorage(base_url=b'uploads/', location=b'uploads'), null=True, upload_to=badger.models.UploadTo(b'image', b'png'), blank=True)),
('unique', models.BooleanField(default=True, help_text=b'Should awards of this badge be limited to one-per-person?')),
('nominations_accepted', models.BooleanField(default=True, help_text=b'Should this badge accept nominations from other users?')),
('nominations_autoapproved', models.BooleanField(default=False, help_text=b'Should all nominations be automatically approved?')),
('created', models.DateTimeField(auto_now_add=True)),
('modified', models.DateTimeField(auto_now=True)),
('creator', models.ForeignKey(blank=True, to=settings.AUTH_USER_MODEL, null=True)),
('prerequisites', models.ManyToManyField(help_text=b'When all of the selected badges have been awarded, this badge will be automatically awarded.', to='badger.Badge', null=True, blank=True)),
],
options={
'ordering': ['-modified', '-created'],
'permissions': (('manage_deferredawards', 'Can manage deferred awards for this badge'),),
},
bases=(models.Model,),
),
migrations.CreateModel(
name='DeferredAward',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('description', models.TextField(blank=True)),
('reusable', models.BooleanField(default=False)),
('email', models.EmailField(db_index=True, max_length=75, null=True, blank=True)),
('claim_code', models.CharField(default=badger.models.make_random_code, unique=True, max_length=32, db_index=True)),
('claim_group', models.CharField(db_index=True, max_length=32, null=True, blank=True)),
('created', models.DateTimeField(auto_now_add=True)),
('modified', models.DateTimeField(auto_now=True)),
('badge', models.ForeignKey(to='badger.Badge')),
('creator', models.ForeignKey(blank=True, to=settings.AUTH_USER_MODEL, null=True)),
],
options={
'ordering': ['-modified', '-created'],
'permissions': (('grant_deferredaward', 'Can grant deferred award to an email address'),),
},
bases=(models.Model,),
),
migrations.CreateModel(
name='Nomination',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('accepted', models.BooleanField(default=False)),
('rejected_reason', models.TextField(blank=True)),
('created', models.DateTimeField(auto_now_add=True)),
('modified', models.DateTimeField(auto_now=True)),
('approver', models.ForeignKey(related_name='nomination_approver', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
('award', models.ForeignKey(blank=True, to='badger.Award', null=True)),
('badge', models.ForeignKey(to='badger.Badge')),
('creator', models.ForeignKey(related_name='nomination_creator', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
('nominee', models.ForeignKey(related_name='nomination_nominee', to=settings.AUTH_USER_MODEL)),
('rejected_by', models.ForeignKey(related_name='nomination_rejected_by', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='Progress',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('percent', models.FloatField(default=0)),
('counter', models.FloatField(default=0, null=True, blank=True)),
('notes', badger.models.JSONField(null=True, blank=True)),
('created', models.DateTimeField(auto_now_add=True)),
('modified', models.DateTimeField(auto_now=True)),
('badge', models.ForeignKey(to='badger.Badge')),
('user', models.ForeignKey(related_name='progress_user', to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name_plural': 'Progresses',
},
bases=(models.Model,),
),
migrations.AlterUniqueTogether(
name='progress',
unique_together=set([('badge', 'user')]),
),
migrations.AlterUniqueTogether(
name='badge',
unique_together=set([('title', 'slug')]),
),
migrations.AddField(
model_name='award',
name='badge',
field=models.ForeignKey(to='badger.Badge'),
preserve_default=True,
),
migrations.AddField(
model_name='award',
name='creator',
field=models.ForeignKey(related_name='award_creator', blank=True, to=settings.AUTH_USER_MODEL, null=True),
preserve_default=True,
),
migrations.AddField(
model_name='award',
name='user',
field=models.ForeignKey(related_name='award_user', to=settings.AUTH_USER_MODEL),
preserve_default=True,
),
]

Просмотреть файл

@ -1,18 +1,17 @@
import logging
import re
import random
import hashlib
from datetime import datetime, timedelta, tzinfo
from time import time, gmtime, strftime
import json
import logging
import os.path
import random
import re
from datetime import datetime, timedelta, tzinfo
from os.path import dirname
from time import time, gmtime, strftime
from urlparse import urljoin
import django
from django.conf import settings
from django.core.serializers.json import DjangoJSONEncoder
from django.db import models
from django.db.models import signals, Q, Count, Max
from django.db.models.fields.files import FieldFile, ImageFieldFile
@ -23,17 +22,9 @@ from django.core.files.base import ContentFile
from django.contrib.auth.models import User, AnonymousUser
from django.contrib.sites.models import Site
from django.contrib.contenttypes.models import ContentType
from django.template import Context, TemplateDoesNotExist
from django.template.loader import render_to_string
from django.core.serializers.json import DjangoJSONEncoder
try:
import django.utils.simplejson as json
except ImportError: # Django 1.5 no longer bundles simplejson
import json
# HACK: Django 1.2 is missing receiver and user_logged_in
try:
from django.dispatch import receiver
@ -208,18 +199,45 @@ def get_permissions_for(self, user):
return perms
def mk_upload_to(field_fn, ext, tmpl=MK_UPLOAD_TMPL):
"""upload_to builder for file upload fields"""
def upload_to(instance, filename):
base, slug = instance.get_upload_meta()
slug_hash = (hashlib.md5(slug.encode('utf-8', 'ignore'))
.hexdigest())
return tmpl % dict(now=int(time()), rand=random.randint(0, 1000),
slug=slug[:50], base=base, field_fn=field_fn,
pk=instance.pk,
hash=slug_hash, h1=slug_hash[0], h2=slug_hash[1],
ext=ext)
return upload_to
if django.VERSION < (1, 7, 0):
def mk_upload_to(field_fn, ext, tmpl=MK_UPLOAD_TMPL):
"""upload_to builder for file upload fields"""
def upload_to(instance, filename):
base, slug = instance.get_upload_meta()
slug_hash = (hashlib.md5(slug.encode('utf-8', 'ignore'))
.hexdigest())
return tmpl % dict(now=int(time()), rand=random.randint(0, 1000),
slug=slug[:50], base=base, field_fn=field_fn,
pk=instance.pk,
hash=slug_hash, h1=slug_hash[0], h2=slug_hash[1],
ext=ext)
return upload_to
UploadTo = mk_upload_to
if django.VERSION >= (1, 7, 0):
# We need to do this in django 1.7 because migrations serialize the fields.
# See https://code.djangoproject.com/ticket/22999
from django.utils.deconstruct import deconstructible
@deconstructible
class UploadTo(object):
"""upload_to builder for file upload fields"""
def __init__(self, field_fn, ext, tmpl=MK_UPLOAD_TMPL):
self.field_fn = field_fn
self.ext = ext
self.tmpl = tmpl
def __call__(self, instance, filename):
base, slug = instance.get_upload_meta()
slug_hash = (hashlib.md5(slug.encode('utf-8', 'ignore'))
.hexdigest())
return self.tmpl % dict(now=int(time()), rand=random.randint(0, 1000),
slug=slug[:50], base=base, field_fn=self.field_fn,
pk=instance.pk,
hash=slug_hash, h1=slug_hash[0], h2=slug_hash[1],
ext=self.ext)
class JSONField(models.TextField):
@ -407,7 +425,7 @@ class Badge(models.Model):
description = models.TextField(blank=True,
help_text='Longer description of the badge and its criteria')
image = models.ImageField(blank=True, null=True,
storage=BADGE_UPLOADS_FS, upload_to=mk_upload_to('image', 'png'),
storage=BADGE_UPLOADS_FS, upload_to=UploadTo('image', 'png'),
help_text='Upload an image to represent the badge')
prerequisites = models.ManyToManyField('self', symmetrical=False,
blank=True, null=True,
@ -699,7 +717,7 @@ class Award(models.Model):
badge = models.ForeignKey(Badge)
image = models.ImageField(blank=True, null=True,
storage=BADGE_UPLOADS_FS,
upload_to=mk_upload_to('image', 'png'))
upload_to=UploadTo('image', 'png'))
claim_code = models.CharField(max_length=32, blank=True,
default='', unique=False, db_index=True,
help_text='Code used to claim this award')

Просмотреть файл

@ -0,0 +1,161 @@
# 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):
# Adding model 'Badge'
db.create_table('badger_badge', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('title', self.gf('django.db.models.fields.CharField')(unique=True, max_length=255)),
('slug', self.gf('django.db.models.fields.SlugField')(unique=True, max_length=50, db_index=True)),
('description', self.gf('django.db.models.fields.TextField')(blank=True)),
('image', self.gf('django.db.models.fields.files.ImageField')(max_length=100, null=True, blank=True)),
('unique', self.gf('django.db.models.fields.BooleanField')(default=False)),
('creator', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'], null=True, blank=True)),
('created', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
('modified', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)),
))
db.send_create_signal('badger', ['Badge'])
# Adding unique constraint on 'Badge', fields ['title', 'slug']
db.create_unique('badger_badge', ['title', 'slug'])
# Adding M2M table for field prerequisites on 'Badge'
db.create_table('badger_badge_prerequisites', (
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
('from_badge', models.ForeignKey(orm['badger.badge'], null=False)),
('to_badge', models.ForeignKey(orm['badger.badge'], null=False))
))
db.create_unique('badger_badge_prerequisites', ['from_badge_id', 'to_badge_id'])
# Adding model 'Award'
db.create_table('badger_award', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('badge', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['badger.Badge'])),
('image', self.gf('django.db.models.fields.files.ImageField')(max_length=100, null=True, blank=True)),
('user', self.gf('django.db.models.fields.related.ForeignKey')(related_name='award_user', to=orm['auth.User'])),
('creator', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='award_creator', null=True, to=orm['auth.User'])),
('hidden', self.gf('django.db.models.fields.BooleanField')(default=False)),
('created', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
('modified', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)),
))
db.send_create_signal('badger', ['Award'])
# Adding model 'Progress'
db.create_table('badger_progress', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('badge', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['badger.Badge'])),
('user', self.gf('django.db.models.fields.related.ForeignKey')(related_name='progress_user', to=orm['auth.User'])),
('percent', self.gf('django.db.models.fields.FloatField')(default=0)),
('counter', self.gf('django.db.models.fields.FloatField')(default=0, null=True, blank=True)),
('notes', self.gf('badger.models.JSONField')(null=True, blank=True)),
('created', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
('modified', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)),
))
db.send_create_signal('badger', ['Progress'])
# Adding unique constraint on 'Progress', fields ['badge', 'user']
db.create_unique('badger_progress', ['badge_id', 'user_id'])
def backwards(self, orm):
# Removing unique constraint on 'Progress', fields ['badge', 'user']
db.delete_unique('badger_progress', ['badge_id', 'user_id'])
# Removing unique constraint on 'Badge', fields ['title', 'slug']
db.delete_unique('badger_badge', ['title', 'slug'])
# Deleting model 'Badge'
db.delete_table('badger_badge')
# Removing M2M table for field prerequisites on 'Badge'
db.delete_table('badger_badge_prerequisites')
# Deleting model 'Award'
db.delete_table('badger_award')
# Deleting model 'Progress'
db.delete_table('badger_progress')
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': '255'}),
'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'})
},
'badger.award': {
'Meta': {'object_name': 'Award'},
'badge': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['badger.Badge']"}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'creator': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'award_creator'", 'null': 'True', 'to': "orm['auth.User']"}),
'hidden': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'image': ('django.db.models.fields.files.ImageField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'award_user'", 'to': "orm['auth.User']"})
},
'badger.badge': {
'Meta': {'unique_together': "(('title', 'slug'),)", 'object_name': 'Badge'},
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'creator': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'image': ('django.db.models.fields.files.ImageField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'prerequisites': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['badger.Badge']", 'null': 'True', 'blank': 'True'}),
'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '50', 'db_index': 'True'}),
'title': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
'unique': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
},
'badger.progress': {
'Meta': {'unique_together': "(('badge', 'user'),)", 'object_name': 'Progress'},
'badge': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['badger.Badge']"}),
'counter': ('django.db.models.fields.FloatField', [], {'default': '0', 'null': 'True', 'blank': 'True'}),
'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'}),
'notes': ('badger.models.JSONField', [], {'null': 'True', 'blank': 'True'}),
'percent': ('django.db.models.fields.FloatField', [], {'default': '0'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'progress_user'", 'to': "orm['auth.User']"})
},
'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'})
}
}
complete_apps = ['badger']

Просмотреть файл

Просмотреть файл

@ -1,11 +1,10 @@
# django
import django
from django import template
from django.conf import settings
from django.shortcuts import get_object_or_404
from badger.models import Award, Badge
from django.contrib.auth.models import SiteProfileNotAvailable
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
@ -14,6 +13,13 @@ import urllib
from django.utils.translation import ugettext_lazy as _
if django.VERSION < (1, 7, 0):
from django.contrib.auth.models import SiteProfileNotAvailable
if django.VERSION >= (1, 7, 0):
class SiteProfileNotAvailable(Exception):
pass
register = template.Library()

Просмотреть файл

@ -1,15 +1,14 @@
import json
import logging
import time
from nose.tools import assert_equal, with_setup, assert_false, eq_, ok_
from nose.plugins.attrib import attr
from django.http import HttpRequest, HttpResponse
from django.utils import simplejson as json
from django.test.client import Client
from django.core.urlresolvers import reverse
from django.contrib.auth.models import AnonymousUser
from django.core.urlresolvers import reverse
from django.http import HttpRequest, HttpResponse
from django.test.client import Client
from . import BadgerTestCase

Просмотреть файл

@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
from os.path import dirname
import json
import logging
import time
from os.path import dirname
try:
from PIL import Image
@ -14,7 +15,6 @@ from django.core.management import call_command
from django.db.models import loading
from django.core.files.base import ContentFile
from django.http import HttpRequest
from django.utils import simplejson as json
from django.test.client import Client
from django.core import mail

Просмотреть файл

@ -1,22 +1,18 @@
import logging
import hashlib
import json
import logging
from django.conf import settings
from django.http import HttpRequest
from django.test.client import Client
from django.utils import simplejson
from django.utils.translation import get_language
from django.contrib.auth.models import User
from pyquery import PyQuery as pq
from django.http import HttpRequest
from django.template.defaultfilters import slugify
from django.test.client import Client
from django.utils.translation import get_language
from nose.tools import assert_equal, with_setup, assert_false, eq_, ok_
from nose.plugins.attrib import attr
from pyquery import PyQuery as pq
from django.template.defaultfilters import slugify
try:
from funfactory.urlresolvers import (get_url_prefix, Prefixer, reverse,
@ -66,7 +62,7 @@ class BadgerViewsTest(BadgerTestCase):
url = reverse('badger.detail_json', args=(badge.slug, ))
r = self.client.get(url, follow=True)
data = simplejson.loads(r.content)
data = json.loads(r.content)
eq_(badge.title, data['name'])
eq_(badge.description, data['description'])
eq_('http://testserver%s' % badge.get_absolute_url(),
@ -94,7 +90,7 @@ class BadgerViewsTest(BadgerTestCase):
url = reverse('badger.award_detail_json', args=(b1.slug, award.pk,))
r = self.client.get(url, follow=True)
data = simplejson.loads(r.content)
data = json.loads(r.content)
hash_salt = (hashlib.md5('%s-%s' % (award.badge.pk, award.pk))
.hexdigest())

Просмотреть файл

@ -1,13 +1,10 @@
import json
import logging
import random
from django.conf import settings
from django.http import (HttpResponseRedirect, HttpResponse,
HttpResponseForbidden, HttpResponseNotFound, Http404)
from django.utils import simplejson
from django.shortcuts import get_object_or_404, render_to_response
from django.template import RequestContext
from django.template.defaultfilters import slugify
@ -139,7 +136,7 @@ def detail(request, slug, format="html"):
if format == 'json':
data = badge.as_obi_serialization(request)
resp = HttpResponse(simplejson.dumps(data))
resp = HttpResponse(json.dumps(data))
resp['Content-Type'] = 'application/json'
return resp
else:
@ -289,7 +286,7 @@ def award_detail(request, slug, id, format="html"):
return HttpResponseForbidden('Award detail forbidden')
if format == 'json':
data = simplejson.dumps(award.as_obi_assertion(request))
data = json.dumps(award.as_obi_assertion(request))
resp = HttpResponse(data)
resp['Content-Type'] = 'application/json'
return resp

Просмотреть файл

@ -1,4 +1,6 @@
# Django settings for badger_example project.
import django
DEBUG = True
TEMPLATE_DEBUG = DEBUG
@ -122,12 +124,14 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'django.contrib.admin',
'south',
'django_nose', # has to come after south for good test-fu
'badger_example',
'badger',
]
if django.VERSION[:2] < (1, 7):
INSTALLED_APPS = INSTALLED_APPS + ['south']
MESSAGE_STORAGE = 'django.contrib.messages.storage.cookie.CookieStorage'
LOGGING = {
@ -152,3 +156,7 @@ LOGGING = {
}
BADGER_TEMPLATE_BASE = 'badger'
ABSOLUTE_URL_OVERRIDES = {
'auth.user': lambda u: u'/users/{0}'.format(u.username)
}

Просмотреть файл

@ -38,3 +38,9 @@ basepython = python2.7
commands = pip install "Django>=1.6,<1.6.99"
pip install -r requirements/dev.txt
{envpython} manage.py test -v2 badger
[testenv:py27_dj17]
basepython = python2.7
commands = pip install "Django>=1.7,<1.7.99"
pip install -r requirements/dev.txt
{envpython} manage.py test -v2 badger