removed obsolete abbjobs model

(same content is now server by old webs json-api)
This commit is contained in:
okalintu
2016-12-10 19:13:12 +02:00
parent e67ef5e4ed
commit a021043385
4 changed files with 1 additions and 72 deletions
@@ -1,46 +0,0 @@
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
-15
View File
@@ -193,21 +193,6 @@ class Rotation(models.Model):
def __str__(self):
return self.name
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,
}
def __str__(self):
return self.title
class ImageUploadForm(forms.Form):
'''
Form used to handle imageuploads to
+1 -9
View File
@@ -6,7 +6,7 @@ from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.decorators import permission_required
from django.utils import timezone
from infoscreen.models import ABBJob, Rotation, InfoItem, InfoInstance
from infoscreen.models import Rotation, InfoItem, InfoInstance
from infoscreen.models import ABBInfoItem, ExternalImageInfoItem, ImageInfoItem, SossoInfoItem
from infoscreen.models import ImageUploadForm
@@ -27,14 +27,6 @@ def default(request,*args,**kwargs):
first = 0
return index(request,first ,*args, **kwargs)
# 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=60)
jobs = ABBJob.objects.filter(created__gt=limit)
joblist = list(map(lambda j:j.get_dict(), jobs))
return HttpResponse(json.dumps(joblist))
@require_http_methods(["GET"])
def rotation(request, idx, *args, **kwargs):
try: