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

Binary file not shown.

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, on_delete=models.SET_NULL,
related_name='children') 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): class Sample(CommonInfo):
""" """
@@ -57,7 +65,7 @@ class Mineral(Sample):
lustre = models.CharField(max_length=100, blank=True) lustre = models.CharField(max_length=100, blank=True)
colour = models.CharField(max_length=100, blank=True) colour = models.CharField(max_length=100, blank=True)
streak = 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) crystallography = models.CharField(max_length=100, blank=True)
identifying_features = models.CharField(max_length=1000, blank=True) identifying_features = models.CharField(max_length=1000, blank=True)
occurance = models.CharField(max_length=1000, blank=True) occurance = models.CharField(max_length=1000, blank=True)

View File

@@ -74,6 +74,13 @@ function load(){
resizeCanvas(); resizeCanvas();
var sampleFilename = '{{ sample.model_filename|escapejs }}'; var sampleFilename = '{{ sample.model_filename|escapejs }}';
if (sampleFilename.trim() == "")
{
document.getElementById("progress").innerHTML = "No model defined!";
return;
}
request = new XMLHttpRequest(); request = new XMLHttpRequest();
request.open("GET", '{{ MEDIA_URL }}' + sampleFilename, true); request.open("GET", '{{ MEDIA_URL }}' + sampleFilename, true);
request.overrideMimeType("text/plain; charset=x-user-defined"); request.overrideMimeType("text/plain; charset=x-user-defined");

View File

@@ -1,13 +1,13 @@
<li><label class="tree-toggle nav-header">{{ category.name }}</label> <li><label class="tree-toggle nav-header">{{ category.name }}</label>
<ul class="nav nav-list tree"> <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" %} {% with category=child template_name="three_d_viewer/treenode.html" %}
<ul style="list-style: none;"> <ul style="list-style: none;">
{% include template_name %} {% include template_name %}
</ul> </ul>
{%endwith%} {%endwith%}
{% endfor %} {% 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> <li><a href="{% url 'three_d_viewer:detail' sample.id %}">{{ sample.name }}</a></li>
{% endfor %} {% endfor %}
</ul> </ul>