Fixed merge conflict at urls.py
This commit is contained in:
@@ -1,3 +1,9 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from infoscreen.models import Rotation, InfoItem, InfoInstance, InfoOption
|
||||||
|
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
|
|
||||||
|
admin.site.register(Rotation)
|
||||||
|
admin.site.register(InfoItem)
|
||||||
|
admin.site.register(InfoInstance)
|
||||||
|
admin.site.register(InfoOption)
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.9 on 2016-09-14 15:43
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('infoscreen', '0002_auto_20160831_1757'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='InfoInstance',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('duration', models.FloatField(default=15.0)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='InfoItem',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=255)),
|
||||||
|
('template_url', models.CharField(max_length=512)),
|
||||||
|
('expire_date', models.DateTimeField()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='InfoOption',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('key', models.CharField(max_length=255)),
|
||||||
|
('value', models.CharField(max_length=255)),
|
||||||
|
('item', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='options', to='infoscreen.InfoItem')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Rotation',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=255)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='infoinstance',
|
||||||
|
name='item',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='infoscreen.InfoItem'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='infoinstance',
|
||||||
|
name='rotation',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='instances', to='infoscreen.Rotation'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.9 on 2016-09-14 17:47
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('infoscreen', '0003_auto_20160914_1543'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='infoitem',
|
||||||
|
name='expire_date',
|
||||||
|
field=models.DateTimeField(blank=True, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -1,6 +1,64 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
|
class InfoItem(models.Model):
|
||||||
|
name = models.CharField(max_length=255)
|
||||||
|
template_url = models.CharField(max_length=512)
|
||||||
|
expire_date = models.DateTimeField(blank=True,null=True) # None means never expiring item
|
||||||
|
|
||||||
|
def get_dict(self):
|
||||||
|
# fetch options
|
||||||
|
opts = {}
|
||||||
|
for o in self.options.all():
|
||||||
|
opts[o.key] = o.value
|
||||||
|
# parse dict
|
||||||
|
return {
|
||||||
|
'name': self.name,
|
||||||
|
'template_url': self.template_url,
|
||||||
|
'options': opts
|
||||||
|
}
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
class InfoInstance(models.Model):
|
||||||
|
rotation = models.ForeignKey('Rotation', related_name='instances')
|
||||||
|
item = models.ForeignKey('InfoItem')
|
||||||
|
duration = models.FloatField(default=15.0) # seconds
|
||||||
|
|
||||||
|
def get_dict(self):
|
||||||
|
return {
|
||||||
|
'item': self.item.get_dict(),
|
||||||
|
'duration': self.duration,
|
||||||
|
}
|
||||||
|
def __str__(self):
|
||||||
|
return "{}: {} ({}s)".format(self.rotation.name, self.item.name, self.duration)
|
||||||
|
|
||||||
|
class InfoOption(models.Model):
|
||||||
|
class __meta__:
|
||||||
|
unique_together = ("item", "key")
|
||||||
|
|
||||||
|
item = models.ForeignKey('InfoItem', related_name='options')
|
||||||
|
key = models.CharField(max_length=255)
|
||||||
|
value = models.CharField(max_length=255)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return "{}: {} -> {}".format(self.item.name, self.key, self.value)
|
||||||
|
|
||||||
|
class Rotation(models.Model):
|
||||||
|
name = models.CharField(max_length=255)
|
||||||
|
|
||||||
|
def get_dict(self):
|
||||||
|
# exclude expired items from rotation (note: using filter would exclude items with no expide_date)
|
||||||
|
instances = self.instances.exclude(item__expire_date__lt=timezone.now())
|
||||||
|
instance_list = list(map(lambda i:i.get_dict(), instances))
|
||||||
|
|
||||||
|
return {
|
||||||
|
'name': self.name,
|
||||||
|
'instances': instance_list,
|
||||||
|
}
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
class ABBJob(models.Model):
|
class ABBJob(models.Model):
|
||||||
sw_id = models.IntegerField(default=-1)
|
sw_id = models.IntegerField(default=-1)
|
||||||
title = models.CharField(max_length=255)
|
title = models.CharField(max_length=255)
|
||||||
@@ -12,3 +70,6 @@ class ABBJob(models.Model):
|
|||||||
"title": self.title,
|
"title": self.title,
|
||||||
"QR": self.QR,
|
"QR": self.QR,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.title
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
<img ng-src="{{ img }}" class="fit"/>
|
||||||
@@ -1 +0,0 @@
|
|||||||
<img ng-src="{{imagepath}}" class="fit"/>
|
|
||||||
@@ -1,32 +1,35 @@
|
|||||||
var app = angular.module('infoApp', ['ngAnimate']);
|
var app = angular.module('infoApp', ['ngAnimate', 'ngRoute']);
|
||||||
|
|
||||||
|
app.controller('infoscreen_main', function($scope,$http,$timeout){
|
||||||
|
var templates = [];
|
||||||
app.controller('infoscreen_main', function($scope,$timeout){
|
$scope.init = function(rot){
|
||||||
$scope.index = -1;
|
$scope.rotation = rot;
|
||||||
var templates = [
|
get_rotation();
|
||||||
{
|
}
|
||||||
template: "/static/html/test1.html?img=otatarha",
|
var get_rotation = function(){
|
||||||
onload: function(){$scope.imagepath = "/static/img/otaajot16fb.png";}
|
$scope.index = -1;
|
||||||
},{
|
$http.get('/infoscreen/rotation/'+$scope.rotation).then(function(response){
|
||||||
template: "/static/html/abb.html"
|
templates = response.data.instances;
|
||||||
},{
|
$scope.next();
|
||||||
template: "/static/html/test1.html?img=otaolut",
|
});
|
||||||
onload: function(){$scope.imagepath = "/static/img/otaolutbanner.jpg";}
|
}
|
||||||
},{
|
|
||||||
template: "/static/html/test1.html?img=asw",
|
$scope.next = function(){
|
||||||
onload: function(){$scope.imagepath = "/static/img/asw.png";}
|
$scope.index++;
|
||||||
},{
|
if ($scope.index >= templates.length){
|
||||||
template: "/static/html/test1.html?img=fujitsu",
|
return get_rotation();
|
||||||
onload: function(){$scope.imagepath = "/static/img/fujitsu.png";}
|
}
|
||||||
},
|
var temp = templates[$scope.index];
|
||||||
];
|
$scope.active = {
|
||||||
$scope.next = function(){
|
template: temp.item.template_url,
|
||||||
$scope.index = ($scope.index + 1) % templates.length;
|
onload: function(){
|
||||||
$scope.active = templates[$scope.index];
|
for (key in temp.item.options){
|
||||||
$timeout($scope.next,15000);
|
$scope[key] = temp.item.options[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
$timeout($scope.next, temp.duration * 1000);
|
||||||
}
|
}
|
||||||
$scope.next()
|
|
||||||
});
|
});
|
||||||
app.controller('ABBController', function($scope, $http){
|
app.controller('ABBController', function($scope, $http){
|
||||||
$scope.jobs = [];
|
$scope.jobs = [];
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
<script src="/static/js/infoscreen_controllers.js"></script>
|
<script src="/static/js/infoscreen_controllers.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container ng-scope" ng-controller="infoscreen_main" >
|
<div class="container ng-scope" ng-controller="infoscreen_main" ng-init="init({{ rotation }})">
|
||||||
<div ng-animate-swap="index" class="cell swap-animation">
|
<div ng-animate-swap="index" class="cell swap-animation">
|
||||||
<div id="infocontent" ng-include="active.template" onload="active.onload()"></div>
|
<div id="infocontent" ng-include="active.template" onload="active.onload()"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+20
-3
@@ -1,14 +1,20 @@
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.views.decorators.http import require_http_methods
|
from django.views.decorators.http import require_http_methods
|
||||||
from infoscreen.models import ABBJob
|
from infoscreen.models import ABBJob, Rotation
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import json
|
import json
|
||||||
|
|
||||||
def index(request , *args, **kwargs):
|
def index(request,idx, *args, **kwargs):
|
||||||
return render(request, 'infoscreen_index.html',{})
|
return render(request, 'infoscreen_index.html',{'rotation':idx})
|
||||||
|
|
||||||
|
def default(request,*args,**kwargs):
|
||||||
|
try:
|
||||||
|
first = Rotation.objects.all()[0].id
|
||||||
|
except:
|
||||||
|
first = 0
|
||||||
|
return index(request,first ,*args, **kwargs)
|
||||||
|
|
||||||
# send abb jobs which have been created less than month ago
|
# send abb jobs which have been created less than month ago
|
||||||
@require_http_methods(["GET"])
|
@require_http_methods(["GET"])
|
||||||
@@ -17,3 +23,14 @@ def abb_job_list(request, *args, **kwargs):
|
|||||||
jobs = ABBJob.objects.filter(created__gt=limit)
|
jobs = ABBJob.objects.filter(created__gt=limit)
|
||||||
joblist = list(map(lambda j:j.get_dict(), jobs))
|
joblist = list(map(lambda j:j.get_dict(), jobs))
|
||||||
return HttpResponse(json.dumps(joblist))
|
return HttpResponse(json.dumps(joblist))
|
||||||
|
|
||||||
|
@require_http_methods(["GET"])
|
||||||
|
def rotation(request, idx, *args, **kwargs):
|
||||||
|
try:
|
||||||
|
rotation = Rotation.objects.get(pk=idx)
|
||||||
|
except Rotation.DoesNotExist:
|
||||||
|
resp = HttpResponse('{"error": "Rotation not found"}')
|
||||||
|
resp.status_code = 404
|
||||||
|
return resp
|
||||||
|
|
||||||
|
return HttpResponse(json.dumps(rotation.get_dict()))
|
||||||
|
|||||||
+5
-1
@@ -31,7 +31,9 @@ from members.views import new_member_request
|
|||||||
from members.views import member_requests
|
from members.views import member_requests
|
||||||
#infoscreen
|
#infoscreen
|
||||||
from infoscreen.views import index as infoindex
|
from infoscreen.views import index as infoindex
|
||||||
|
from infoscreen.views import default as infodefault
|
||||||
from infoscreen.views import abb_job_list
|
from infoscreen.views import abb_job_list
|
||||||
|
from infoscreen.views import rotation
|
||||||
#application
|
#application
|
||||||
from members.views import applicationindex
|
from members.views import applicationindex
|
||||||
|
|
||||||
@@ -53,8 +55,10 @@ urlpatterns = [
|
|||||||
url(r'^members/api/request$', new_member_request),
|
url(r'^members/api/request$', new_member_request),
|
||||||
url(r'^members/api/request/(?P<idx>\d+)$', handle_mem_request),
|
url(r'^members/api/request/(?P<idx>\d+)$', handle_mem_request),
|
||||||
#infoscreen
|
#infoscreen
|
||||||
url(r'^infoscreen/$', infoindex),
|
url(r'^infoscreen/$', infodefault),
|
||||||
|
url(r'^infoscreen/(?P<idx>\d+)$', infoindex),
|
||||||
url(r'^infoscreen/abbjobs$', abb_job_list),
|
url(r'^infoscreen/abbjobs$', abb_job_list),
|
||||||
|
url(r'^infoscreen/rotation/(?P<idx>\d+)$', rotation),
|
||||||
#application
|
#application
|
||||||
url(r'^application/$', applicationindex),
|
url(r'^application/$', applicationindex),
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user