Added details for minerals and fixed use of the active flag

This commit is contained in:
2014-01-21 15:32:35 +10:00
parent ad5ad01307
commit 4ffca36884
5 changed files with 96 additions and 14 deletions

View File

@@ -0,0 +1,67 @@
# -*- 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):
# Changing field 'Mineral.habit'
db.alter_column(u'three_d_viewer_mineral', 'habit', self.gf('django.db.models.fields.CharField')(max_length=1000))
def backwards(self, orm):
# Changing field 'Mineral.habit'
db.alter_column(u'three_d_viewer_mineral', 'habit', self.gf('django.db.models.fields.CharField')(max_length=100))
models = {
u'three_d_viewer.answer': {
'Meta': {'object_name': 'Answer'},
'correct': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'question': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'answers'", 'to': u"orm['three_d_viewer.Question']"}),
'text': ('django.db.models.fields.CharField', [], {'max_length': '2000'})
},
u'three_d_viewer.category': {
'Meta': {'object_name': 'Category'},
'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'on_delete': 'models.SET_NULL', 'to': u"orm['three_d_viewer.Category']"})
},
u'three_d_viewer.mineral': {
'Meta': {'object_name': 'Mineral', '_ormbases': [u'three_d_viewer.Sample']},
'chemical_formula': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}),
'cleavage_fracture': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}),
'colour': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}),
'crystallography': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}),
'habit': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'blank': 'True'}),
'hardness': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '3', 'decimal_places': '2', 'blank': 'True'}),
'identifying_features': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'blank': 'True'}),
'lustre': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'}),
'occurance': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'blank': 'True'}),
u'sample_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': u"orm['three_d_viewer.Sample']", 'unique': 'True', 'primary_key': 'True'}),
'specific_gravity': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '4', 'decimal_places': '2', 'blank': 'True'}),
'streak': ('django.db.models.fields.CharField', [], {'max_length': '100', 'blank': 'True'})
},
u'three_d_viewer.question': {
'Meta': {'object_name': 'Question'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'sample': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'questions'", 'to': u"orm['three_d_viewer.Sample']"}),
'text': ('django.db.models.fields.CharField', [], {'max_length': '2000'})
},
u'three_d_viewer.sample': {
'Meta': {'object_name': 'Sample'},
'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'description': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '2000', 'null': 'True', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model_filename': ('django.db.models.fields.CharField', [], {'max_length': '1000'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'samples'", 'null': 'True', 'on_delete': 'models.SET_NULL', 'to': u"orm['three_d_viewer.Category']"})
}
}
complete_apps = ['three_d_viewer']

View File

@@ -32,6 +32,14 @@ class Category(CommonInfo):
on_delete=models.SET_NULL,
related_name='children')
@property
def active_children(self):
return self.children.filter(active=True)
@property
def active_samples(self):
return self.samples.filter(active=True)
class Sample(CommonInfo):
"""
@@ -57,12 +65,12 @@ class Mineral(Sample):
lustre = models.CharField(max_length=100, blank=True)
colour = models.CharField(max_length=100, blank=True)
streak = models.CharField(max_length=100, blank=True)
habit = models.CharField(max_length=100, blank=True)
habit = models.CharField(max_length=1000, blank=True)
crystallography = models.CharField(max_length=100, blank=True)
identifying_features = models.CharField(max_length=1000, blank=True)
occurance = models.CharField(max_length=1000, blank=True)
class Question(models.Model):
"""
The definition of a multiple choice question, associated with a Sample

View File

@@ -72,8 +72,15 @@ function formatNumber(numero, decimales){
function load(){
window.addEventListener('resize', resizeCanvas, false);
resizeCanvas();
var sampleFilename = '{{ sample.model_filename|escapejs }}';
if (sampleFilename.trim() == "")
{
document.getElementById("progress").innerHTML = "No model defined!";
return;
}
request = new XMLHttpRequest();
request.open("GET", '{{ MEDIA_URL }}' + sampleFilename, true);
request.overrideMimeType("text/plain; charset=x-user-defined");
@@ -113,7 +120,7 @@ function webGLStart(){
var canvas = document.getElementById("canvas");
canvas.oncontextmenu = function() { return false; } // supress the context menu in the canvas
initGL(canvas);
initBoundingBox();
initOffsets();
@@ -347,15 +354,15 @@ function handleMouseMove(event){
var newY = event.clientY;
var deltaX = newX - lastMouseX;
var deltaY = newY - lastMouseY;
switch (event.which) {
case 1: // left mouse
var newRotationMatrix = mat4.create();
mat4.identity(newRotationMatrix);
mat4.rotate(newRotationMatrix, degToRad(deltaX / 5), [0, 1, 0]);
mat4.rotate(newRotationMatrix, degToRad(deltaY / 5), [1, 0, 0]);
mat4.multiply(newRotationMatrix, rotationMatrix, rotationMatrix);
@@ -369,8 +376,8 @@ function handleMouseMove(event){
console.log('moving ' + deltaX + ', ' + deltaY)
break;
}
}
lastMouseX = newX
lastMouseY = newY;
}
@@ -379,13 +386,13 @@ function handleMouseMove(event){
function resizeCanvas() {
var canvas = document.getElementById("canvas") ;
var parent = document.getElementById("contentdiv");
var canvasWidth1 = canvas.width;
var canvasHeight1 = canvas.height;
canvas.width = parent.offsetWidth;
canvas.height = parent.offsetHeight;
if (gl){
/*hmove = canvas.width / 2 - canvasWidth1 / 2
vmove = canvas.height / 2 - canvasHeight1 / 2

View File

@@ -1,13 +1,13 @@
<li><label class="tree-toggle nav-header">{{ category.name }}</label>
<ul class="nav nav-list tree">
{% for child in category.children.all %}
{% for child in category.active_children %}
{% with category=child template_name="three_d_viewer/treenode.html" %}
<ul style="list-style: none;">
{% include template_name %}
</ul>
{%endwith%}
{% endfor %}
{% for sample in category.samples.all %}
{% for sample in category.active_samples %}
<li><a href="{% url 'three_d_viewer:detail' sample.id %}">{{ sample.name }}</a></li>
{% endfor %}
</ul>