placeholder code
parent
ab677b43fb
commit
4097567fcc
|
@ -1,2 +1,4 @@
|
|||
# ItemOrientedSurvey
|
||||
A django module for presenting a survey linked to a model object
|
||||
|
||||
Just a placeholder for now.
|
|
@ -0,0 +1,8 @@
|
|||
from django.contrib import admin
|
||||
from .models import Landing
|
||||
|
||||
# new in dj1.7
|
||||
# @admin.register(Landing)
|
||||
class LandingAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
import string
|
||||
from django.core.management.base import BaseCommand
|
||||
from ...models import Landing
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "make survey nonces with the specified label"
|
||||
args = "<how_many> <label>"
|
||||
|
||||
|
||||
def handle(self, how_many=1, label="no label yet", **options):
|
||||
how_many=int(how_many)
|
||||
while how_many>0:
|
||||
landing = Landing.objects.create(label=label)
|
||||
print landing.nonce
|
||||
how_many -= 1
|
|
@ -0,0 +1,45 @@
|
|||
# -*- 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 model 'Landing'
|
||||
db.create_table('survey_landing', (
|
||||
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
|
||||
('nonce', self.gf('django.db.models.fields.CharField')(max_length=32, null=True)),
|
||||
('content_type', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['contenttypes.ContentType'], null=True)),
|
||||
('object_id', self.gf('django.db.models.fields.PositiveIntegerField')(null=True)),
|
||||
('label', self.gf('django.db.models.fields.CharField')(max_length=64, null=True)),
|
||||
))
|
||||
db.send_create_signal('survey', ['Landing'])
|
||||
|
||||
|
||||
def backwards(self, orm):
|
||||
# Deleting model 'Landing'
|
||||
db.delete_table('survey_landing')
|
||||
|
||||
|
||||
models = {
|
||||
'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'})
|
||||
},
|
||||
'survey.landing': {
|
||||
'Meta': {'object_name': 'Landing'},
|
||||
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']", 'null': 'True'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'label': ('django.db.models.fields.CharField', [], {'max_length': '64', 'null': 'True'}),
|
||||
'nonce': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True'}),
|
||||
'object_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True'})
|
||||
}
|
||||
}
|
||||
|
||||
complete_apps = ['survey']
|
|
@ -0,0 +1,30 @@
|
|||
import hashlib
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from django.conf import settings
|
||||
from django.contrib.contenttypes.generic import GenericForeignKey
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.db import models
|
||||
from django.db.models.signals import post_save
|
||||
|
||||
class Landing(models.Model):
|
||||
# defines an entry point to a Feedback session
|
||||
nonce = models.CharField(max_length=32, null=True,blank=True)
|
||||
content_type = models.ForeignKey(ContentType, null=True,blank=True)
|
||||
object_id = models.PositiveIntegerField(null=True,blank=True)
|
||||
content_object = GenericForeignKey('content_type', 'object_id')
|
||||
label = models.CharField(max_length=64, blank=True)
|
||||
|
||||
def _hash(self):
|
||||
return uuid.uuid4().hex
|
||||
|
||||
def __str__(self):
|
||||
return self.label
|
||||
|
||||
def config_landing(sender, instance, created, **kwargs):
|
||||
if created:
|
||||
instance.nonce=instance._hash()
|
||||
instance.save()
|
||||
|
||||
post_save.connect(config_landing,sender=Landing)
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
{% extends 'basedocumentation.html' %}
|
||||
{% load url from future %}
|
||||
|
||||
{% block title %}Tell us Stuff!{% endblock %}
|
||||
|
||||
{% block doccontent %}
|
||||
|
||||
<h2>Tell us stuff!</h2>
|
||||
<p>We are excited that this is Open Access book and really hope that it will be shared around, read by lots of people all over the world, and used in lots of exciting new ways. We would love to hear about you and how you are using it - please would you share your story with us using this link: (it will only take about 3 minutes - and you could just get a free book as well ….)</p>
|
||||
<p>But comeback again, our survey for {{landing.label}} isn't ready yet.</p>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
from django.conf.urls.defaults import *
|
||||
from .views import SurveyView
|
||||
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url(r'^landing/(?P<nonce>\w+)/$', SurveyView.as_view(), name="landing"),
|
||||
)
|
|
@ -0,0 +1,20 @@
|
|||
import logging
|
||||
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.views.generic.base import TemplateView
|
||||
|
||||
from .models import Landing
|
||||
|
||||
|
||||
|
||||
class SurveyView(TemplateView):
|
||||
template_name = "survey/generic.html"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(SurveyView, self).get_context_data(**kwargs)
|
||||
|
||||
nonce = self.kwargs['nonce']
|
||||
landing = get_object_or_404(Landing, nonce=nonce)
|
||||
context["landing"] = landing
|
||||
|
||||
return context
|
Loading…
Reference in New Issue