From 0150bf4f8d3d294da0ad703501eaf886722e243f Mon Sep 17 00:00:00 2001 From: baoliang Date: Sun, 11 Oct 2020 01:42:12 +0800 Subject: [PATCH] add message --- .../__pycache__/startswith.cpython-38.pyc | Bin 0 -> 441 bytes polls/models.py | 13 ++++++++++++- polls/views/__pycache__/task.cpython-38.pyc | Bin 3331 -> 3268 bytes polls/views/task.py | 17 +++++++---------- 4 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 dashboard/templatetags/__pycache__/startswith.cpython-38.pyc diff --git a/dashboard/templatetags/__pycache__/startswith.cpython-38.pyc b/dashboard/templatetags/__pycache__/startswith.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b9bb86ac0c035ae30cd3265423fb30ca79e19977 GIT binary patch literal 441 zcmYjMy-EW?5Z<5UJP*@Z_zDN&hSVa0U?pinnnRGi?3ir0yA8W5F_1=L>pR5KHxYZA zZLNF-D`!u|49qt_%s1c6xYx@F+S}{H%{#`ASnL|d;vC%_BPgP1MQU15N`P+JGbuRm zc}FqDpQyt4NH(~|Vj!-U1DUyFGZyg+wH z2%fBoryFJu*JR7q^qG$E1YFLBmpKoacDlix%>)8>-r7jcS?GAU_eJuf_Cjom?XPPw zc3_<-rKz-Rrea~u946k0L4VK}wJCK4qJd=%O3T_b+8e8JPDwW_jkHSqJ>uomiT__t z7OPe{iDyS3ETb76=1EA@9HoqnpM||EU0P{ZA+<2o&Vvoft*$V(^!Cgh*pHm_v^MIl Of-{O$yZnHqJfq+B#BSaI literal 0 HcmV?d00001 diff --git a/polls/models.py b/polls/models.py index da8f847..28d9b71 100644 --- a/polls/models.py +++ b/polls/models.py @@ -98,6 +98,17 @@ class Task(models.Model): def record(self): return TaskRecord.objects.filter(task=self).count() + def add_task_message(self, user_id): + for group in self.groups.all(): + Message.objects.create( + type=4, send_from_id=user_id, send_to_id=group.id, task=self, content=self.content) + + def add_url_message(self, user_id, title, description, url, image): + for group in self.groups.all(): + Message.objects.create( + type=1, send_from_id=user_id, send_to_id=group.id, task=self, page_title=title, page_description=description, page_image=image, url=url) + + class Meta: ordering = ["-added"] @@ -180,7 +191,7 @@ class Message(models.Model): updated = models.DateTimeField(auto_now=True) class Meta: - ordering = ["-added"] + ordering = ["added"] class GroupRecord(models.Model): diff --git a/polls/views/__pycache__/task.cpython-38.pyc b/polls/views/__pycache__/task.cpython-38.pyc index c9e71044b141201c9bd02e0a7349338bb0bf72ee..fee30e686de025561c0f23eb35a447b58e1cb16e 100644 GIT binary patch delta 1314 zcmZ8h&u<%55cb<2Z{1z5y|Eorr%sv#C~R{`00oKwA%3(~t56CpLb8y|;`f?5IJOyY z4nb=oFjoZ8qlb!1@()m?oH)Y~wO6zU4oFnw00@Z#Ct&7nQlji?KYjDf?7W?s_jWw> zecgY{_uU*`H-G!M_4T$t&3@coxb^b-RC9{uB$vJ@2>;XEn2lNUl(vhabYM5M9f*ko zds=c)78SCZGu!{%W2U;x=A6_XL@<>V!LT{hy#OUOOs&H*nV&nFyyj)OIK%}Z?ICtMUi zGe;-liG+{YJJ!e@d85L}kIRXhcu67g#}?+bcPg~Tp|)$I=D^>S=YmdDN*objqGFQ& zf8M5%$Hk-BY=Q7lF4 zy-oD~WiMV{M#nxiBQ)V0MLtXLG^xfhHMKkI(W-<=ifE9t3bVvbf;sgAZ?Ll3=Z&p- z6jGk8mAa7-tySo642EeyJdTF%x7OuwNXcpxYG1gta{d|=D9?lz2GHrnX^Fx&pnDh{ z2Jkq=%u$Rpfc}k6S7y6_3d{;v&b^A1Du8DYnl2`INr<@9@1^fYaeE!M(Ti@(|dHdHpcYsD3GTplj z9-`NE3+PCscHEDnZpuNn`ygP7ymU;msa1|njnrE1UBoAezDPhv2s{EBBs@Z(lT*q1 z1i~3&`uJTT_Bw%H;W1=kJ{uFw7G5Jbr)J!f^<&M7%g5Z*Qm?w+?SI(`#*SLxUX@`*LiY9>Fn`i@Z*j;S70R2ZF2FFJ1~LRA!F}!EXn`o@t0)Vz0*>uDyga{*v;SzN?h81vMM)_t@FH0r zCpb!~{6AG_)g^n;*-}Z@gz7D~9FcG_@8tz(E|sfXnBfQuTIJDdRFHNN;m@_N`d98A zayPH8ZhqT)@ZF~m?%mt`e0}<_`(HfVxZA&ev%hwyf9Fd7(gtMF9QIL=983^b2o3}- zy};7JieBhGfr8MZvk24Xyu1j_cFPr73#tuIXm7lA=G1vekl!AHu%Gh8sJlfraxFKS zuw>Wq4F@k2aX}knQf@Q!ns#%HiCL={J7A< zoy=L$(q|pl#gsvb971>&nTQYKd$#-WAr##AgRf(SmstXDmFY~D@P4E#ySTiID@JIe zk`>w+a)KpgI31|Q-`zAt+Gzn1qYzY$=TUD{LN>2{(!X|VYwgR28yi5qQDjki9_J`L zE>%uwUemMdLI71TyWI1 z{$tE+gN(R=_c%;hk4r;~yw?BxhY>IwFaGKy80Zr{%Ick&Oa$-84Qe-BxL^j09 I5c4wo4<}Dnp8x;= diff --git a/polls/views/task.py b/polls/views/task.py index 8b8bf0a..80a889c 100644 --- a/polls/views/task.py +++ b/polls/views/task.py @@ -9,7 +9,7 @@ from polls.decorators import polls_login_required from polls.models import Message, Notice, Task, TaskAddition from polls.tasks import process_task from django.core.exceptions import ObjectDoesNotExist -from polls.utils import model_to_dict, queryset_to_list +from polls.utils import model_to_dict, queryset_to_list, parse @csrf_exempt @@ -47,27 +47,24 @@ def create_task(request): groups = request.POST.getlist('groups', []) task = Task.objects.create(created_by=user, content=content) task.add_groups(groups) + task.add_task_message(user.id) url = request.POST.get('url') - print(groups, content, url) + # print(groups, content, url) file = request.FILES.get('file') picture = request.FILES.get('picture') if url: urlAddtion = TaskAddition.objects.create( task=task, category=0, url=url) - + og_title, og_description, og_url, og_image = parse(url) + print(og_title, og_description, og_url, og_image) + task.add_url_message( + user.id, og_title, og_description, og_url, og_image) if file: fileAddtion = TaskAddition.objects.create( task=task, category=1, file=file) if picture: pictureAddtion = TaskAddition.objects.create( task=task, category=2, image=picture) - - for group in groups: - normalMessage = Message.objects.create( - type=4, send_from_id=user.id, send_to_id=group, task=task, content=content) - content = '用户%s发布了任务,请查收消息' % (profile.name,) - Notice.create_normal_notice(user.id, content) - return JsonResponse({'status': 'success'})