This commit is contained in:
Vitaly committed 2023-09-05 14:00:40 +03:00
commit 4716effcf7
309 files changed
+153369

No files matched your search

@@ -0,0 +1,7 @@
from services.redis_key import *
import asyncio
class AssignmentBuildier:
async def assignmentlist(arr):
wa = [REdSetter.updateKeyReturnChecker(REdSetterSettings('data:assignment',x["id"],'work_assignment')) for x in arr]
res = await asyncio.gather(*wa)
return res
@@ -0,0 +1,30 @@
from orm.models import *
from orm.schema import *
from services.wsservice import *
class AssignmentQuery:
async def assignment(id):
assignment: Assignment = await Assignment.objects.select_related(["status","parent","responsible",'author']).fields(
["responsible__id","id","name","datestart","dateend", "parent__name","difficult",
"responsible__username","responsible__sn","responsible__givenName","longname",
"author__id","author__username","author__sn","author__givenName",
"description","comment","timeneeded","author__id","status","getstarted","parent__id"]
).get(id=id)
return querytoPydantic(AssignmentinWork, assignment)
async def assignments_in_work(work):
assignments = await Assignment.objects.filter(parent=work).fields(["id","name"]).all()
return [querytoPydantic(Assignment.get_pydantic(include={"id"}), a) for a in assignments]
async def assignment_status_update(id,status):
res = await Assignment.objects.get(id=id)
res.status= status
res.lastchanged = datetime.now()
if status==2:
if res.getstarted is None:
res.getstarted = datetime.now()
return await res.update()
@@ -0,0 +1,108 @@
import json
from orm.models import *
from services.wsservice import *
from orm.schema import *
from conf.sessions import get_redis_pool
from aioredis.client import PubSub, Redis
import asyncio
# cюда гену
class ChatFuncs:
async def get_my_chatList(settings):
chat = await Chat.objects.select_related(['users']).get(id=settings.id)
chat = querytoPydantic(Chatschema, chat)
mesg = await ChatMessage.objects.select_related(['sender']).filter(chat=settings.id).order_by("-id").limit(10).all()
tenmes = []
for x in mesg:
tenmes.append(querytoPydantic(LastChatMessage, x))
tenmes.reverse()
chat['lastmessage']=tenmes
return chat
async def updatechatsnapshot(settings):
redis= await get_redis_pool()
message, users = await asyncio.gather(redis.hget(f"{settings.code}/{settings.id}", 'lastmessage'), redis.hget(f"{settings.code}/{settings.id}", 'users'))
users=json.loads(users)
for x in users:
if x['id']!=settings.other['mes']['sender']['id']:
unreaded = await redis.hget(f"data:user/{x['id']}", 'unreadedmessages')
unreaded = json.loads(unreaded) if unreaded not in ["null",None] else []
unreaded.append(settings.other['mes'])
await redis.hset(f"data:user/{x['id']}", 'unreadedmessages',json.dumps(unreaded, indent=4, sort_keys=True, default=str))
message = json.loads(message)
message.append(settings.other['mes'])
if len(message)>10:
message.pop(0)
await redis.close()
return message
async def leavechat(settings):
redis= await get_redis_pool()
users = await redis.hget(f"{settings.code}/{settings.id}", 'users')
await redis.close()
users = json.loads(users)
users.pop(next((i for i, x in enumerate(users) if x["id"] == settings.other['user']['id']), None))
return users
async def addchat(settings):
redis= await get_redis_pool()
users = await redis.hget(f"{settings.code}/{settings.id}", 'users')
await redis.close()
users = json.loads(users)
users.append(querytoPydantic(ChatUserschema, settings.other['user']))
return users
async def ireadIt(settings):
redis= await get_redis_pool()
print(f"{settings.code}/{settings.id}")
old = await redis.hget(f"{settings.code}/{settings.id}", 'unreadedmessages')
await redis.close()
old= json.loads(old)
i=0
while i< len(old):
if old[i]['chat']['id']== settings.other['chatroom']:
old.pop(i)
else:
i+=1
return old
async def updateunreaded(settings):
redis= await get_redis_pool()
try:
msgs = await redis.hget(f"{settings.code}/{settings.id}", 'unreadedmessages')
msgs = json.loads(msgs)
except Exception:
msgs=[]
indx = next((i for i, x in enumerate(msgs) if x["id"] == settings.other['messid']), None)
if indx is not None:
msgs.pop()
return msgs
async def updatechatusers(settings):
# print("dfsssssssddddddddddddddddddddddddddddd")
# print(settings.other['users'])
# redis= await get_redis_pool()
# msgs = await redis.hset(f"{settings.code}/{settings.id}", settings.other['key'], json.dumps(settings.other['users'], indent=4, sort_keys=True, default=str))
return settings.other['users']
@@ -0,0 +1,22 @@
from orm.models import *
from orm.schema import *
from services.wsservice import *
class FileListGetter:
async def files_in_work(workid):
files = await Projectfile.objects.select_related("sender").filter(work = workid).all()
wf=[querytoPydantic(Filegetter, x) for x in files]
return wf
async def files_in_task(id):
files = await Projectfile.objects.select_related("sender").filter(task = id).all()
wf=[querytoPydantic(Filegetter, x) for x in files]
return wf
async def files_in_project(id):
files = await Projectfile.objects.select_related("sender").filter(project = id).all()
wf=[querytoPydantic(Filegetter, x) for x in files]
print("s")
return wf
@@ -0,0 +1,24 @@
from services.redis_key import *
import asyncio
async def emptyidct():
asyncio.sleep(0)
return {}
async def emptyarr():
asyncio.sleep(0)
return []
async def asincuser(arr)->list:
return [{"role":x["role"],"percent":x["percent"], "user": await REdSetter.updateKeyReturnChecker(REdSetterSettings('users:user',x['user']['id'],'getuser'))} for x in arr]
class ProjectBuildier:
async def build_proj_persons(nudeproj):
nudeproj['users']=await asincuser( nudeproj['users'])
return nudeproj
@@ -0,0 +1,32 @@
from orm.models import *
from orm.schema import *
from services.wsservice import *
class Projectquery:
def __init__(self) -> None:
pass
@classmethod
async def ProjectBaseFieldsQuery(self,id):
"""Берем только проект (без информации о пользователях - только их ид и роль)"""
a = await Project.objects.select_related( ["status","ptype","project_task"]).get(id=id)
a=querytoPydantic(ProjectGet,a)
a['users'] = await self.get_nudeprojectusers(id)
return a
@classmethod
async def get_nudeprojectusers(self,projectid):
usersq = await ProjectUser.objects.select_related(["role"]).filter(project=projectid).all()
users = [querytoPydantic(ProjectUserSchema,x) for x in usersq]
return users
@classmethod
async def project_status_update(id, status):
work = await Project.objects.get(id=id)
work.status = status
return await work.update()
Whitespace-only changes.
@@ -0,0 +1,21 @@
from orm.models import *
from orm.schema import *
from services.wsservice import *
class Taskquery:
async def project_tasks(id):
task: Task = await Task.objects.select_related(["status","parent","responsible",'task_work','parent']).fields(
["task_work__id","longname",
"task_work__id",
"task_work__name",
"status","status__name","parent__id","responsible__id","responsible__username",
"responsible__sn","responsible__givenName","dateend","datestart","description","name","comment", 'difficult' ]
).get(id=id)
return querytoPydantic(Task4ProjectGet, task)
async def task_status_update(user, id, status):
work = await Task.objects.get(id=id)
work.status = status
return await work.update()
@@ -0,0 +1,13 @@
from orm.models import *
from orm.schema import *
from services.wsservice import *
class Userquery:
async def getuser(id):
user: User = await User.objects.select_related(["otdel", "rank","position","organization","department"]).fields(
["telephoneNumber", "phone","email","otdel","department", "organization", "position", "avatar","physicalDeliveryOfficeName",
"id", "sn", "givenName", "fullname", "position","username"
]).get(id=id)
return querytoPydantic(UserFullInfo, user)
@@ -0,0 +1,9 @@
from services.redis_key import *
import asyncio
class WorkBuildier:
async def worklist(arr):
wa = [REdSetter.updateKeyReturnChecker(REdSetterSettings('data:work',x["id"],'task_work')) for x in arr]
res = await asyncio.gather(*wa)
return res
@@ -0,0 +1,24 @@
from orm.models import *
from orm.schema import *
from services.wsservice import *
class Workquery:
async def task_work(id) -> dict:
work= await Work.objects.select_related(["status","parent","responsible","work_assignment"]).order_by("work_assignment__dateend").fields(["responsible__id","responsible__username",
"responsible__sn","responsible__givenName","id","parent","name","status", "datestart","dateend","comment","difficult","longname", 'description',
"work_assignment__name", "work_assignment__id","work_assignment__dateend"]).get(id=id)
return querytoPydantic(Work4project, work)
async def getstatus(id):
status = await TaskStatus.objects.get(id=id)
return querytoPydantic(TaskStatus.get_pydantic(include={'id','name'}),status)
async def work_status_update(user, id, status):
work = await Work.objects.get(id=id)
work.status = status
return await work.update()