Added blocks to miner, url, views and template (start work)
This commit is contained in:
parent
e89dd7c12d
commit
57a9cee9ba
|
@ -0,0 +1,75 @@
|
||||||
|
# -*- 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 'Block'
|
||||||
|
db.create_table(u'database_block', (
|
||||||
|
(u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
|
||||||
|
('internal_name', self.gf('django.db.models.fields.CharField')(max_length=128)),
|
||||||
|
('main_texture', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['database.Texture'], null=True)),
|
||||||
|
('data_value', self.gf('django.db.models.fields.IntegerField')()),
|
||||||
|
))
|
||||||
|
db.send_create_signal(u'database', ['Block'])
|
||||||
|
|
||||||
|
|
||||||
|
def backwards(self, orm):
|
||||||
|
# Deleting model 'Block'
|
||||||
|
db.delete_table(u'database_block')
|
||||||
|
|
||||||
|
|
||||||
|
models = {
|
||||||
|
u'database.block': {
|
||||||
|
'Meta': {'object_name': 'Block'},
|
||||||
|
'data_value': ('django.db.models.fields.IntegerField', [], {}),
|
||||||
|
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||||
|
'internal_name': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
|
||||||
|
'main_texture': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['database.Texture']", 'null': 'True'})
|
||||||
|
},
|
||||||
|
u'database.item': {
|
||||||
|
'Meta': {'object_name': 'Item'},
|
||||||
|
'data_value': ('django.db.models.fields.IntegerField', [], {}),
|
||||||
|
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||||
|
'internal_name': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
|
||||||
|
'main_texture': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['database.Texture']", 'null': 'True'})
|
||||||
|
},
|
||||||
|
'database.jarfile': {
|
||||||
|
'Meta': {'object_name': 'JarFile'},
|
||||||
|
'description': ('django.db.models.fields.CharField', [], {'default': "'client'", 'max_length': '256'}),
|
||||||
|
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||||
|
'url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
|
||||||
|
'version': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['database.Version']"})
|
||||||
|
},
|
||||||
|
'database.mod': {
|
||||||
|
'Meta': {'ordering': "['name']", 'object_name': 'Mod'},
|
||||||
|
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||||
|
'name': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
|
||||||
|
'url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'})
|
||||||
|
},
|
||||||
|
u'database.texture': {
|
||||||
|
'Meta': {'object_name': 'Texture'},
|
||||||
|
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||||
|
'image': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
|
||||||
|
'name': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
|
||||||
|
'type': ('django.db.models.fields.CharField', [], {'default': "'items'", 'max_length': '16'})
|
||||||
|
},
|
||||||
|
'database.version': {
|
||||||
|
'Meta': {'ordering': "['date']", 'object_name': 'Version'},
|
||||||
|
'changelog': ('django.db.models.fields.TextField', [], {}),
|
||||||
|
'date': ('django.db.models.fields.DateField', [], {}),
|
||||||
|
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||||
|
'mod': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['database.Mod']"}),
|
||||||
|
'name': ('django.db.models.fields.CharField', [], {'max_length': '128', 'blank': 'True'}),
|
||||||
|
'snapshot': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||||
|
'status': ('django.db.models.fields.CharField', [], {'default': "'release'", 'max_length': '10', 'blank': 'True'}),
|
||||||
|
'url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
|
||||||
|
'version_number': ('django.db.models.fields.CharField', [], {'default': "'0.1.0'", 'max_length': '256'})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
complete_apps = ['database']
|
|
@ -175,3 +175,30 @@ class ItemAdmin(admin.ModelAdmin):
|
||||||
main_texture_html.allow_tags = True
|
main_texture_html.allow_tags = True
|
||||||
|
|
||||||
admin.site.register(Item, ItemAdmin)
|
admin.site.register(Item, ItemAdmin)
|
||||||
|
|
||||||
|
|
||||||
|
###
|
||||||
|
# BLOCK
|
||||||
|
###
|
||||||
|
class Block(models.Model):
|
||||||
|
internal_name = models.CharField(max_length=128)
|
||||||
|
main_texture = models.ForeignKey('Texture', null=True)
|
||||||
|
data_value = models.IntegerField()
|
||||||
|
|
||||||
|
|
||||||
|
class BlockAdmin(admin.ModelAdmin):
|
||||||
|
list_display = ('internal_name', 'data_value', 'main_texture_html')
|
||||||
|
list_display_links = ('internal_name', )
|
||||||
|
#list_filter = ('type', )
|
||||||
|
search_fields = ('internal_name', 'data_value', )
|
||||||
|
|
||||||
|
def main_texture_html(self, obj):
|
||||||
|
if obj.main_texture:
|
||||||
|
return(
|
||||||
|
'<img src="/static/textures/%s" height="32" />' % \
|
||||||
|
obj.main_texture.get_image(2)
|
||||||
|
)
|
||||||
|
main_texture_html.short_description = 'Image'
|
||||||
|
main_texture_html.allow_tags = True
|
||||||
|
|
||||||
|
admin.site.register(Block, BlockAdmin)
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
{% extends "layout.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h1>Blocks</h1>
|
||||||
|
<hr />
|
||||||
|
<table class="table table-condensed table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th width="20" nowrap="nowrap"><div class="text-center">Data value</div></th>
|
||||||
|
<th nowrap="nowrap"><div class="text-center">Texture</div></th>
|
||||||
|
<th><div class="text-center">Name</div></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for item in page.object_list %}
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<div class="text-center">{{ item.data_value }}</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div class="text-center">
|
||||||
|
{% if item.main_texture %}
|
||||||
|
<img src="/static/textures/{{ item.main_texture.get_image(2) }}" />
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ item.internal_name }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<div class="pagination pagination-centered">
|
||||||
|
<ul>
|
||||||
|
{% for p in range(1, paginator.num_pages+1) %}
|
||||||
|
<li {% if p == page_number %}class="active"{% endif %}>
|
||||||
|
<a href="{{ url('blocks_list') }}?page={{ p }}">{{ p }}</a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
|
@ -15,7 +15,7 @@
|
||||||
{% for item in page.object_list %}
|
{% for item in page.object_list %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<div class="text-center">{{ item.data_value }}</div>
|
<div class="text-center">{{ item.data_value + 256 }}</div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
|
|
|
@ -57,6 +57,9 @@ Thank you!
|
||||||
<li class="{% if section == 'home' %}active{% endif %}">
|
<li class="{% if section == 'home' %}active{% endif %}">
|
||||||
<a href="{{ url('homepage') }}">Home</a>
|
<a href="{{ url('homepage') }}">Home</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="{% if section == 'blocks' %}active{% endif %}">
|
||||||
|
<a href="{{ url('blocks_list') }}">Blocks</a>
|
||||||
|
</li>
|
||||||
<li class="{% if section == 'items' %}active{% endif %}">
|
<li class="{% if section == 'items' %}active{% endif %}">
|
||||||
<a href="{{ url('items_list') }}">Items</a>
|
<a href="{{ url('items_list') }}">Items</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from django.shortcuts import render_to_response
|
from django.shortcuts import render_to_response
|
||||||
from database.models import Version, Item
|
from database.models import Version, Item, Block
|
||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
from django.template import RequestContext
|
from django.template import RequestContext
|
||||||
|
|
||||||
|
@ -68,6 +68,29 @@ def items(request):
|
||||||
context = RequestContext(request, data)
|
context = RequestContext(request, data)
|
||||||
return render_to_response('items.html', context_instance=context)
|
return render_to_response('items.html', context_instance=context)
|
||||||
|
|
||||||
|
|
||||||
|
def blocks(request):
|
||||||
|
section = 'blocks'
|
||||||
|
|
||||||
|
items = Block.objects.all().order_by('data_value')
|
||||||
|
paginator = Paginator(items, 50)
|
||||||
|
page_number = 1
|
||||||
|
|
||||||
|
if 'page' in request.GET:
|
||||||
|
page_number = int(request.GET['page'])
|
||||||
|
|
||||||
|
page = paginator.page(page_number)
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'section': section,
|
||||||
|
'page': page,
|
||||||
|
'page_number': page_number,
|
||||||
|
'paginator': paginator,
|
||||||
|
}
|
||||||
|
context = RequestContext(request, data)
|
||||||
|
return render_to_response('blocks.html', context_instance=context)
|
||||||
|
|
||||||
|
|
||||||
def about(request):
|
def about(request):
|
||||||
context = RequestContext(request, {'section': 'about'})
|
context = RequestContext(request, {'section': 'about'})
|
||||||
return render_to_response('about.html', context_instance=context)
|
return render_to_response('about.html', context_instance=context)
|
||||||
|
|
|
@ -38,6 +38,9 @@ urlpatterns = patterns('',
|
||||||
# Items
|
# Items
|
||||||
url(r'^items/', 'database.views.items', name='items_list'),
|
url(r'^items/', 'database.views.items', name='items_list'),
|
||||||
|
|
||||||
|
# Items
|
||||||
|
url(r'^blocks/', 'database.views.blocks', name='blocks_list'),
|
||||||
|
|
||||||
# Robots
|
# Robots
|
||||||
(r'^robots\.txt$', lambda r: HttpResponse("", mimetype="text/plain")),
|
(r'^robots\.txt$', lambda r: HttpResponse("", mimetype="text/plain")),
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,10 @@ from objects import GameBlock
|
||||||
|
|
||||||
|
|
||||||
print("=> Phase: blocks")
|
print("=> Phase: blocks")
|
||||||
|
if conf.SAVE:
|
||||||
|
sys.path.append('../../minecraftcodex')
|
||||||
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'local_settings'
|
||||||
|
from database.models import Block, Texture
|
||||||
|
|
||||||
###
|
###
|
||||||
# GLOBALS
|
# GLOBALS
|
||||||
|
@ -85,6 +88,26 @@ for java_file in conf.BLOCKS_FILES:
|
||||||
|
|
||||||
BLOCKS.append(obj)
|
BLOCKS.append(obj)
|
||||||
|
|
||||||
|
if conf.SAVE:
|
||||||
|
for item in BLOCKS:
|
||||||
|
try:
|
||||||
|
obj = Block.objects.get(
|
||||||
|
internal_name=item.name,
|
||||||
|
data_value=item.id
|
||||||
|
)
|
||||||
|
except Block.DoesNotExist:
|
||||||
|
obj = Block(
|
||||||
|
internal_name=item.name,
|
||||||
|
data_value=item.id
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
texture = Texture.objects.get(name__exact=obj.internal_name)
|
||||||
|
obj.main_texture = texture
|
||||||
|
except Exception as error:
|
||||||
|
print(error)
|
||||||
|
pass
|
||||||
|
obj.save()
|
||||||
|
|
||||||
# Print the miner summary and compile the new old data
|
# Print the miner summary and compile the new old data
|
||||||
print(' => Summary')
|
print(' => Summary')
|
||||||
new_old_data = {}
|
new_old_data = {}
|
||||||
|
|
|
@ -25,7 +25,7 @@ class GameItem(object):
|
||||||
##
|
##
|
||||||
class GameBlock(object):
|
class GameBlock(object):
|
||||||
def __init__(self, game_id, *args):
|
def __init__(self, game_id, *args):
|
||||||
self.id = int(game_id)
|
self.id = int(game_id)# + 256
|
||||||
|
|
||||||
def __str__(self, *args):
|
def __str__(self, *args):
|
||||||
return "<Block(%d: '%s')>" % (
|
return "<Block(%d: '%s')>" % (
|
||||||
|
|
Loading…
Reference in New Issue