Anbindung TM NC
This commit is contained in:
parent
b249bb0dba
commit
eee39eca75
|
|
@ -27,4 +27,6 @@ urlpatterns = [
|
|||
path('logout/<str:uid>', views.apilogout, name="api-logout"),
|
||||
path('uschanged/<str:uid>/<str:sid>', views.userChangedInNc, name="api-userchanged"),
|
||||
path('deletefile/<slug:fid>/<slug:secretkey>', views.deleteNCFile, name="api-deletencfile"),
|
||||
path('tm/startday/<slug:uid>/<slug:secretkey>', views.startWorkDay, name="api-startday"),
|
||||
path('tm/gettime/<slug:uid>/<slug:secretkey>', views.getTime, name="api-gettime"),
|
||||
]
|
||||
99
api/views.py
99
api/views.py
|
|
@ -18,7 +18,10 @@ from django.contrib.sessions.models import Session
|
|||
from timemanagement.models import Absence
|
||||
from django.conf import settings
|
||||
from digitaleagentur.utils import *
|
||||
from timemanagement.models import Workday, FreeDays, Absence
|
||||
from standards.models import Standards, NCFile
|
||||
from users.models import AgencyGroup, Agency, AgencyNetwork, AgencyNetworkPreperation, UserTime, UserYearAbsenceInfo, AgencyBills
|
||||
from standards.templatetags import *
|
||||
|
||||
class GetUserId(APIView):
|
||||
#permission_classes = (IsAuthenticated,) # <-- And here
|
||||
|
|
@ -44,7 +47,6 @@ def getSingleStandard(request, pk):
|
|||
@api_view(['POST', ])
|
||||
#@permission_classes((IsAuthenticated,))
|
||||
def logoutByToken(request):
|
||||
print(request)
|
||||
request.user.auth_token.delete()
|
||||
return Response(status=status.HTTP_200_OK)
|
||||
|
||||
|
|
@ -255,6 +257,15 @@ def NCAddUser(request):
|
|||
|
||||
return JsonResponse({"status" : "NO AUTH"})
|
||||
|
||||
@api_view(['GET'],)
|
||||
def getTMInfos(request, uid, secretkey):
|
||||
if request.method == "GET":
|
||||
print("HI! asdsadassad")
|
||||
|
||||
return JsonResponse({"status" : "DATA " + uid + " " + secretkey})
|
||||
|
||||
return JsonResponse({"status" : "NO AUTH"})
|
||||
|
||||
from requests.auth import HTTPBasicAuth
|
||||
'''
|
||||
Anlegen des Gruppenordners der Agentur in NC
|
||||
|
|
@ -455,3 +466,89 @@ def deleteNCFile(request, fid, secretkey):
|
|||
return JsonResponse({"status" : "NO AUTH"})
|
||||
else:
|
||||
return JsonResponse({"status" : "NO AUTH"})
|
||||
|
||||
# APIs for TIMEMANAGEMENT
|
||||
@api_view(['GET'], )
|
||||
def startWorkDay(request, uid, secretkey):
|
||||
print("kasjdkajhsdkjhasdjksha")
|
||||
if request.method == "GET" and secretkey == '87zuhjk87GHJ546tzgvhas76aaskbdhr45edfVHAKia87s6gbAVGFGSR3451627gBHAKJBN':
|
||||
print("START A DAY!")
|
||||
return HttpResponse(1)
|
||||
else:
|
||||
return JsonResponse({"status" : "FALSE"})
|
||||
|
||||
# APIs for TIMEMANAGEMENT
|
||||
import os
|
||||
from django.conf import settings
|
||||
from django.utils import timezone
|
||||
from datetime import date
|
||||
import datetime
|
||||
# Ladet das aktuelle Gleitzeitkonto
|
||||
'''
|
||||
|
||||
Es werden nur Tage berücksichtigt, die in der Vergangenheit liegen!
|
||||
|
||||
'''
|
||||
def format_timedelta(td):
|
||||
hours, remainder = divmod(td.total_seconds(), 3600)
|
||||
minutes, seconds = divmod(remainder, 60)
|
||||
hours, minutes, seconds = int(hours), int(minutes), int(seconds)
|
||||
if hours < 10:
|
||||
hours = '0%s' % int(hours)
|
||||
if minutes < 10:
|
||||
minutes = '0%s' % minutes
|
||||
if seconds < 10:
|
||||
seconds = '0%s' % seconds
|
||||
return '%s:%s:%s' % (hours, minutes, seconds)
|
||||
|
||||
def loadaccounttime(user):
|
||||
status = 0
|
||||
today = date.today()
|
||||
workdays = Workday.objects.filter(user=user, start__lt=today, delflag = False).exclude(end=None)
|
||||
|
||||
finalaccounttimesum = datetime.timedelta(minutes=0) + datetime.timedelta(hours=UserTime.objects.get(user=user).startcount)
|
||||
|
||||
|
||||
for workday in workdays:
|
||||
# Zeit, die der Mitarbeiter gearbeitet haben MUSS
|
||||
|
||||
sum_break = 0
|
||||
|
||||
if(len(workday.breaks.all()) > 0):
|
||||
|
||||
for ele in workday.breaks.all():
|
||||
if ele.end != None and ele.start != None:
|
||||
sum_break += (ele.end - ele.start).seconds
|
||||
|
||||
finalsum = ((workday.end - workday.start).seconds - sum_break)
|
||||
hastowork = datetime.timedelta(hours=workday.target)
|
||||
final_info = (int(finalsum) - int(hastowork.total_seconds()))/60
|
||||
|
||||
if(final_info >= 0.0):
|
||||
finalaccounttimesum += datetime.timedelta(minutes=final_info)
|
||||
else:
|
||||
final_info = final_info * -1
|
||||
finalaccounttimesum -= datetime.timedelta(minutes=final_info)
|
||||
|
||||
# Gesamtgleitzeit einmal schick darstellen mit rot und grün
|
||||
# Wenn GLeitzeit NEGATIV ist
|
||||
if(finalaccounttimesum.total_seconds() < 0):
|
||||
status = 1
|
||||
final_info_data = format_timedelta(datetime.timedelta(seconds=finalaccounttimesum.total_seconds()*(-1)))
|
||||
else:
|
||||
status = 0
|
||||
final_info_data = format_timedelta(datetime.timedelta(seconds=finalaccounttimesum.total_seconds()))
|
||||
|
||||
final_info_data_neu = final_info_data.split(":")[0] + ":" + final_info_data.split(":")[1]
|
||||
|
||||
#final_info = str(final_info_data[0]) + ":" + str(final_info_data[1])
|
||||
return [final_info_data_neu, status]
|
||||
|
||||
|
||||
|
||||
@api_view(['GET'], )
|
||||
def getTime(request, uid, secretkey):
|
||||
if request.method == "GET" and secretkey == '87zuhjk87GHJ546tzgvhas76aaskbdhr45edfVHAKia87s6gbAVGFGSR3451627gBHAKJBN':
|
||||
return HttpResponse(loadaccounttime(User.objects.filter(username=uid).first())[0])
|
||||
else:
|
||||
return JsonResponse({"status" : "FALSE"})
|
||||
Binary file not shown.
|
|
@ -86,7 +86,8 @@ Gleitzeitkonto:
|
|||
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
console.log("COOKIES VON DJANGO");
|
||||
console.log(document.cookie);
|
||||
|
||||
|
||||
window.setInterval(function(){
|
||||
|
|
|
|||
|
|
@ -20,5 +20,5 @@ urlpatterns = [
|
|||
path('abs/<int:activemonth>/<int:activeyear>', AbsenceManagmenet, name='tma-management'),
|
||||
path('ajax/', TimeAjax, name='tm-ajax'),
|
||||
path('abs/update/<int:pk>/', AbsenceUpdate, name='tma-update'),
|
||||
path('abs/getncdd/', GetRealtimeDropDown, name='tma-getrealtimedd'),
|
||||
path('abs/getncdd/<slug:uid>', GetRealtimeDropDown, name='tma-getrealtimedd'),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -23,8 +23,12 @@ from django.template.loader import render_to_string
|
|||
from django.core.mail import send_mail
|
||||
from digitaleagentur.utils import *
|
||||
|
||||
|
||||
def GetRealtimeDropDown(request):
|
||||
# LÖSCHEN?
|
||||
from django.contrib.auth import login
|
||||
def GetRealtimeDropDown(request, uid):
|
||||
user = User.objects.get(username=uid)
|
||||
if(getNCLoggedUserBySession(user.profile.nc_sid) == uid):
|
||||
login(request, user)
|
||||
return render(request, 'timemanagement/realtime_dropdown_nc_iframe.html', {})
|
||||
|
||||
# Load freedays
|
||||
|
|
|
|||
Loading…
Reference in New Issue