remove model
This commit is contained in:
parent
f2edd2e762
commit
306b07d513
@ -1,6 +1,6 @@
|
||||
from apps.main.models.accident_stops import AccidentStop
|
||||
from apps.main.models.aspiration_unit import AspirationUnit
|
||||
from apps.main.models.scales_control import Position, ScalesControl, ShiftReport
|
||||
from apps.main.models.scales_control import Position
|
||||
from apps.main.models.worktime import FabricWorkTime
|
||||
from django.contrib import admin
|
||||
|
||||
@ -17,18 +17,6 @@ class FabricWorkTimeAdmin(admin.ModelAdmin):
|
||||
]
|
||||
|
||||
|
||||
@admin.register(ScalesControl)
|
||||
class ScalesControlAdmin(admin.ModelAdmin):
|
||||
list_display = ['date_created', 'name', 'value']
|
||||
list_filter = ['time', 'name']
|
||||
ordering = [
|
||||
'-time',
|
||||
]
|
||||
|
||||
def date_created(self, obj):
|
||||
return obj.time.strftime('%x - %X')
|
||||
|
||||
|
||||
@admin.register(AccidentStop)
|
||||
class AccidentStopAdmin(admin.ModelAdmin):
|
||||
list_display = ['time']
|
||||
@ -41,11 +29,6 @@ class PositionAdmin(admin.ModelAdmin):
|
||||
list_display = ['title']
|
||||
|
||||
|
||||
@admin.register(ShiftReport)
|
||||
class ShiftReportAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
|
||||
@admin.register(AspirationUnit)
|
||||
class AspirationUnitAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
from apps.main.services.base_service import DashboardBaseService
|
||||
from django.db import models
|
||||
|
||||
|
||||
@ -47,20 +46,3 @@ class Position(models.Model):
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
|
||||
class ShiftReport(models.Model):
|
||||
time = models.DateTimeField(default=DashboardBaseService.get_current_time)
|
||||
scales_data = models.JSONField(blank=True, null=True)
|
||||
worktime_data = models.JSONField(blank=True, null=True)
|
||||
density_data = models.JSONField(blank=True, null=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'Отчет за смену'
|
||||
verbose_name_plural = 'Отчет за смены'
|
||||
indexes = [
|
||||
models.Index(fields=['time'])
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.time}'
|
||||
|
||||
@ -1,18 +1,14 @@
|
||||
import json
|
||||
import os
|
||||
import traceback
|
||||
from datetime import datetime
|
||||
|
||||
import psycopg2
|
||||
from apps.main.models.scales_control import Position, ShiftReport
|
||||
from apps.main.models.worktime import FabricWorkTime
|
||||
from apps.main.services.base_service import DashboardBaseService
|
||||
from apps.main.services.scales_control.redis_repository import RedisRepository
|
||||
from apps.util.redis_api import RedisService
|
||||
from apps.util.redis_cache import RedisCache
|
||||
from celery import shared_task
|
||||
from django.conf import settings
|
||||
from django.core.serializers.json import DjangoJSONEncoder
|
||||
from psycopg2 import OperationalError
|
||||
from sabron.util import logging
|
||||
from sabron.util.sabronmodule import get_settings
|
||||
@ -212,28 +208,3 @@ def write_scale_control_data_to_redis():
|
||||
except Exception as e:
|
||||
logging.error('CELERY' + traceback.format_exc())
|
||||
return str(e)
|
||||
|
||||
|
||||
@shared_task
|
||||
def create_shift_report():
|
||||
control_conveyor_month = get_settings('conveyor_month')
|
||||
fabric_goal = get_settings('fabric_goal')
|
||||
service = RedisRepository(control_conveyor_month, fabric_goal)
|
||||
positions = Position.objects.order_by('id')
|
||||
average = service.get_scales_value_by_shifts(positions, 'Aver')
|
||||
daily = service.get_scales_value_by_shifts(positions, 'Smena')
|
||||
concentrate = service.get_concentrate_value()
|
||||
if not concentrate:
|
||||
concentrate = {'concentrate': 0,
|
||||
'dropout': 0}
|
||||
scales_data = json.dumps({'daily': daily, 'average': average},
|
||||
sort_keys=True,
|
||||
indent=1,
|
||||
cls=DjangoJSONEncoder
|
||||
)
|
||||
obj = ShiftReport.objects.create(time=DashboardBaseService.get_current_time(),
|
||||
concentrate=concentrate['concentrate'],
|
||||
dropout=concentrate['dropout'],
|
||||
scales_data=scales_data)
|
||||
service.delete_kek_and_breed_values()
|
||||
return str(obj)
|
||||
|
||||
@ -1,15 +1,8 @@
|
||||
from django.contrib import messages
|
||||
from django.shortcuts import render
|
||||
from django.shortcuts import redirect
|
||||
from django.contrib.auth import authenticate
|
||||
from django.contrib.auth import login
|
||||
from django.contrib.auth import logout
|
||||
from django.contrib.auth import authenticate, login, logout
|
||||
from django.http import HttpResponseRedirect
|
||||
|
||||
from django.shortcuts import redirect, render
|
||||
from users.models import Profile
|
||||
|
||||
from apps.util import generalmodule
|
||||
|
||||
|
||||
def user_block(request, user):
|
||||
profile = Profile.objects.filter(user=user).first()
|
||||
@ -30,56 +23,56 @@ def user_api(request, user):
|
||||
|
||||
|
||||
def user_login(request):
|
||||
if request.method == "POST":
|
||||
username = request.POST.get("username")
|
||||
password = request.POST.get("password")
|
||||
if request.method == 'POST':
|
||||
username = request.POST.get('username')
|
||||
password = request.POST.get('password')
|
||||
user = authenticate(username=username, password=password)
|
||||
if user:
|
||||
if user_api(request, user):
|
||||
context = {
|
||||
"error": True,
|
||||
"comment": "API пользователь не имеет доступ к Личному Кабинету",
|
||||
'error': True,
|
||||
'comment': 'API пользователь не имеет доступ к Личному Кабинету',
|
||||
}
|
||||
return render(request, "registration/login.html", context)
|
||||
return render(request, 'registration/login.html', context)
|
||||
|
||||
if user_block(request, user):
|
||||
login(request, user)
|
||||
context = {
|
||||
"user": user,
|
||||
"login": username,
|
||||
"logout": "accounts/logout/",
|
||||
'user': user,
|
||||
'login': username,
|
||||
'logout': 'accounts/logout/',
|
||||
}
|
||||
return HttpResponseRedirect("/", context)
|
||||
return HttpResponseRedirect('/', context)
|
||||
else:
|
||||
context = {
|
||||
"error": True,
|
||||
"login": username,
|
||||
"comment": "Пользователь заблокирован",
|
||||
'error': True,
|
||||
'login': username,
|
||||
'comment': 'Пользователь заблокирован',
|
||||
}
|
||||
return render(request, "registration/login.html", context)
|
||||
return render(request, 'registration/login.html', context)
|
||||
else:
|
||||
context = {
|
||||
"error": True,
|
||||
"login": username,
|
||||
"comment": "Не верный логин или пароль",
|
||||
'error': True,
|
||||
'login': username,
|
||||
'comment': 'Не верный логин или пароль',
|
||||
}
|
||||
return render(request, "registration/login.html", context)
|
||||
return render(request, 'registration/login.html', context)
|
||||
else:
|
||||
if request.user.is_anonymous:
|
||||
context = {
|
||||
"error": False,
|
||||
"comment": "",
|
||||
'error': False,
|
||||
'comment': '',
|
||||
}
|
||||
return render(request, "registration/login.html", context)
|
||||
return render(request, 'registration/login.html', context)
|
||||
|
||||
else:
|
||||
return redirect("/")
|
||||
return redirect('/')
|
||||
|
||||
|
||||
def user_logout(request):
|
||||
logout(request)
|
||||
context = {
|
||||
"user": "",
|
||||
"logout": "accounts/logout/",
|
||||
'user': '',
|
||||
'logout': 'accounts/logout/',
|
||||
}
|
||||
return HttpResponseRedirect("/", context)
|
||||
return HttpResponseRedirect('/', context)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user