Juuso lupaa pushata developiin ens kerralla

This commit is contained in:
okalintu
2016-09-13 12:23:44 +03:00
13 changed files with 176 additions and 12 deletions
@@ -0,0 +1,46 @@
from django.core.management.base import BaseCommand, CommandError
from django.db.models import Max
from django.conf import settings
from datetime import datetime, timedelta
from pytz import utc
from paramiko.client import SSHClient, AutoAddPolicy, RSAKey
from infoscreen.models import ABBJob
import qrcode
class Command(BaseCommand):
help = 'import new abbjobs from oldish sikweb'
def add_arguments(self, parser):
parser.add_argument('keypath')
def handle(self, *args, **options):
last_id = ABBJob.objects.aggregate(Max('sw_id'))['sw_id__max'] or 0
client = SSHClient()
client.set_missing_host_key_policy(AutoAddPolicy())
key = RSAKey.from_private_key_file(options.get("keypath"))
client.connect("otax.ayy.fi", username="sik", pkey=key)
stdin, stdout, stderr = client.exec_command("./abbjobexport.sh {}".format(last_id))
errors = stderr.read()
if len(errors) > 0:
print(errors)
client.close()
return
data = stdout.read().decode("latin1").strip().split("\n") # shame on latin1 otax!!!
for row in data:
if not row:
continue
cols = row.split('\t',maxsplit=2)
qr_url = gen_qr(cols[0])
created = datetime.strptime(cols[1], "%Y-%m-%d %H:%M:%S").replace(tzinfo=utc) # todo parse to right timezone
ABBJob.objects.create(
sw_id=int(cols[0]),
created=created,
title=cols[2],
QR=qr_url)
def gen_qr(sw_id):
img = qrcode.make("http://sahkoinsinoorikilta.fi/news/{}".format(sw_id))
imgname = "abbjobs_{}.png".format(sw_id)
imgurl = "{}qr/{}".format(settings.MEDIA_URL,imgname)
img.save("{}/qr/{}".format(settings.MEDIA_ROOT,imgname))
return imgurl
+27
View File
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9 on 2016-08-31 17:54
from __future__ import unicode_literals
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='ABBJob',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('sw_id', models.IntegerField(default=-1)),
('title', models.CharField(max_length=255)),
('QR', models.CharField(default='', max_length=255)),
('created', models.DateTimeField(default=datetime.datetime.now)),
],
),
]
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9 on 2016-08-31 17:57
from __future__ import unicode_literals
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('infoscreen', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='abbjob',
name='created',
field=models.DateTimeField(default=django.utils.timezone.now),
),
]
+12 -1
View File
@@ -1,3 +1,14 @@
from django.db import models
from django.utils import timezone
# Create your models here.
class ABBJob(models.Model):
sw_id = models.IntegerField(default=-1)
title = models.CharField(max_length=255)
QR = models.CharField(max_length=255, default="")
created = models.DateTimeField(default=timezone.now)
def get_dict(self):
return {
"title": self.title,
"QR": self.QR,
}
+17 -1
View File
@@ -18,4 +18,20 @@
display: block;
margin-left: auto;
margin-right: auto;
}
}
.swap-animation.ng-enter, .swap-animation.ng-leave {
transition:0.5s linear all;
}
.swap-animation.ng-enter {
opacity:0;
}
.swap-animation.ng-enter-active {
opacity:1;
}
.swap-animation.ng-leave {
opacity:1;
}
.swap-animation.ng-leave-active {
opacity:0;
}
+11
View File
@@ -0,0 +1,11 @@
<div ng-controller="ABBController">
<div class="row" style="max-height:300px">
<div class="col-xs-4 col-xs-offset-1" style="padding-top:30px;padding-bottom:30px"><img src="/static/img/ABB_logo.png"></div>
<div class="col-xs-7" style="font-size:140px;padding-top:40px">TYÖPAIKAT</div>
</div>
<div class="row" ng-repeat="job in jobs" style="height:280px;;border:2px solid black;color:#33333">
<div class="col-xs-7 col-xs-offset-1" style="font-size:72px;padding-top:30px">{{ job.title }}</div>
<div class="col-xs-3"><img ng-src="{{ job.QR }}" style="height:250px;"></div>
</div>
</div>
Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

+16 -8
View File
@@ -1,25 +1,33 @@
var app = angular.module('infoApp', []);
var app = angular.module('infoApp', ['ngAnimate']);
app.controller('infoscreen_main', function($scope, $http,$timeout){
var index = -1;
app.controller('infoscreen_main', function($scope,$timeout){
$scope.index = -1;
var templates = [
{
template: "/static/html/test1.html?img=siklogo",
onload: function(){$scope.imagepath = "/static/img/siklogo.jpg";}
},{
template: "/static/html/test1.html?img=teekkaribileet",
onload: function(){$scope.imagepath = "/static/img/teekkaribileet.jpg";}
template: "/static/html/abb.html"
},{
template: "/static/html/test1.html?img=kaukkarit",
onload: function(){$scope.imagepath = "/static/img/kaukkarit.jpg";}
},{
template: "/static/html/test1.html?img=fujitsu",
onload: function(){$scope.imagepath = "/static/img/fujitsu.png";}
},
];
$scope.next = function(){
index = (index + 1) % templates.length;
$scope.active = templates[index];
$timeout($scope.next,5000);
$scope.index = ($scope.index + 1) % templates.length;
$scope.active = templates[$scope.index];
$timeout($scope.next,15000);
}
$scope.next()
});
app.controller('ABBController', function($scope, $http){
$scope.jobs = [];
$http.get("/infoscreen/abbjobs").then(function(response){
$scope.jobs = response.data;
})
});
+5 -2
View File
@@ -7,6 +7,7 @@
<title>Infoscreen</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-route.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-animate.js"></script>
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
@@ -15,8 +16,10 @@
<script src="/static/js/infoscreen_controllers.js"></script>
</head>
<body>
<div ng-controller="infoscreen_main" >
<div id="infocontent" ng-include="active.template" onload="active.onload()"></div>
<div class="container ng-scope" ng-controller="infoscreen_main" >
<div ng-animate-swap="index" class="cell swap-animation">
<div id="infocontent" ng-include="active.template" onload="active.onload()"></div>
</div>
</div>
</body>
</html>
+15
View File
@@ -1,4 +1,19 @@
from django.shortcuts import render
from django.http import HttpResponse
from django.views.decorators.http import require_http_methods
from infoscreen.models import ABBJob
from django.utils import timezone
from datetime import datetime, timedelta
import json
def index(request , *args, **kwargs):
return render(request, 'infoscreen_index.html',{})
# send abb jobs which have been created less than month ago
@require_http_methods(["GET"])
def abb_job_list(request, *args, **kwargs):
limit = timezone.now() - timedelta(days=30)
jobs = ABBJob.objects.filter(created__gt=limit)
joblist = list(map(lambda j:j.get_dict(), jobs))
return HttpResponse(json.dumps(joblist))