Skip to content
Snippets Groups Projects
Commit 6a917e09 authored by Christian Dresen's avatar Christian Dresen
Browse files

[WarpAPI] Implemented API compliant to the specs 0.13, 0.12, 0.11, 0.9, 0.8. Closed #32

parent ee6e5785
No related branches found
No related tags found
No related merge requests found
from django.contrib import admin
from warpapi.models import *
# Register your models here.
@admin.register(Information)
class InformationAdmin(admin.ModelAdmin):
pass
# -*- coding: utf-8 -*-
# Generated by Django 1.9 on 2016-10-12 00:34
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Information',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('key', models.CharField(max_length=100)),
('value', models.CharField(max_length=250)),
],
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.9 on 2016-10-12 00:39
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('warpapi', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='information',
name='category',
field=models.CharField(default='', max_length=100),
preserve_default=False,
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.9 on 2016-10-12 00:58
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('warpapi', '0002_information_category'),
]
operations = [
migrations.AlterField(
model_name='information',
name='category',
field=models.CharField(max_length=100, null=True),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.9 on 2016-10-12 00:58
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('warpapi', '0003_auto_20161012_0058'),
]
operations = [
migrations.AlterField(
model_name='information',
name='value',
field=models.CharField(max_length=250, null=True),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.9 on 2016-10-12 00:59
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('warpapi', '0004_auto_20161012_0058'),
]
operations = [
migrations.AlterField(
model_name='information',
name='category',
field=models.CharField(blank=True, max_length=100, null=True),
),
migrations.AlterField(
model_name='information',
name='value',
field=models.CharField(blank=True, max_length=250, null=True),
),
]
from __future__ import unicode_literals
from django.db import models
class Information(models.Model):
key = models.CharField(max_length=100)
value = models.CharField(max_length=250, null=True, blank=True)
category = models.CharField(max_length=100, null=True, blank=True)
def __str__(self):
if self.category:
return "["+self.category+"] "+ str(self.key) + ": " + str(self.value)
else:
return str(self.key) + ": " + str(self.value)
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework import status
from warpapi.models import Information
@api_view(['GET'])
def main(request):
if request.method == 'GET':
test = {"test":"value"}
return Response(test)
return Response()
ret= {}
information = Information.objects.all()
for info in information:
if info.category:
if info.category not in ret:
ret[info.category]={}
if info.value:
try:
ret[info.category][info.key] = float(info.value)
except:
ret[info.category][info.key] = info.value
else:
ret[info.category] = {info.key}
else:
ret[info.key] = info.value
ret["open"] = False
ret["state"] = {"open": False, "icon": { "open": str(ret["icon"]["open"]), "closed": str(ret["icon"]["closed"])}}
return Response(ret)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment