From db70dda25317b09e637944cd704bf14c0f9b1a58 Mon Sep 17 00:00:00 2001 From: baoliang Date: Sun, 20 Sep 2020 19:14:54 +0800 Subject: [PATCH 1/2] add unit to userprofile --- NewMediaMonitoring/settings.py | 2 +- dashboard/models.py | 1 + polls/consumers.py | 29 +++---- polls/job.py | 17 ---- polls/models.py | 2 +- polls/tasks.py | 19 +++++ polls/templates/polls/monitor_statistics.html | 78 +++++++++--------- polls/templates/polls/news_detail.html | 17 +--- polls/urls.py | 4 +- polls/utils.py | 26 +++++- polls/views/__init__.py | 4 +- .../views/__pycache__/__init__.cpython-38.pyc | Bin 701 -> 785 bytes .../__pycache__/compartment.cpython-38.pyc | Bin 0 -> 895 bytes polls/views/__pycache__/group.cpython-38.pyc | Bin 0 -> 994 bytes .../views/__pycache__/monitor.cpython-38.pyc | Bin 372 -> 654 bytes polls/views/__pycache__/news.cpython-38.pyc | Bin 859 -> 1189 bytes polls/views/__pycache__/task.cpython-38.pyc | Bin 1940 -> 2227 bytes polls/views/compartment.py | 22 +++++ polls/views/group.py | 24 ++++++ polls/views/monitor.py | 9 +- polls/views/news.py | 21 +++-- polls/views/task.py | 20 +++-- 22 files changed, 195 insertions(+), 100 deletions(-) delete mode 100644 polls/job.py create mode 100644 polls/tasks.py create mode 100644 polls/views/__pycache__/compartment.cpython-38.pyc create mode 100644 polls/views/__pycache__/group.cpython-38.pyc create mode 100644 polls/views/compartment.py create mode 100644 polls/views/group.py diff --git a/NewMediaMonitoring/settings.py b/NewMediaMonitoring/settings.py index c06a45f..d9c7aeb 100644 --- a/NewMediaMonitoring/settings.py +++ b/NewMediaMonitoring/settings.py @@ -90,7 +90,7 @@ CHANNEL_LAYERS = { 'BACKEND': 'channels_redis.core.RedisChannelLayer', 'CONFIG': { "hosts": ["redis://:newmedia2020@210.72.82.249:6379/0"], - "symmetric_encryption_keys": [SECRET_KEY], + # "symmetric_encryption_keys": [SECRET_KEY], }, }, } diff --git a/dashboard/models.py b/dashboard/models.py index 99f2870..e03fc78 100644 --- a/dashboard/models.py +++ b/dashboard/models.py @@ -108,6 +108,7 @@ class Userprofile(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) name = models.CharField('姓名', null=True, blank=True, max_length=256) sex = models.CharField('性别', null=True, blank=True, max_length=256) + unit = models.CharField('单位', null=True, blank=True, max_length=256) department = models.CharField('部门', null=True, blank=True, max_length=256) post = models.CharField('职务', null=True, blank=True, max_length=256) image = models.FileField(upload_to='profile', null=True, blank=True) diff --git a/polls/consumers.py b/polls/consumers.py index be5ea57..6973869 100644 --- a/polls/consumers.py +++ b/polls/consumers.py @@ -6,7 +6,7 @@ from channels.generic.websocket import AsyncWebsocketConsumer class ChatConsumer(AsyncWebsocketConsumer): async def connect(self): self.room_name = self.scope['url_route']['kwargs']['room_name'] - self.room_group_name = 'chat_%s' % self.room_name + self.room_group_name = self.room_name # Join room group await self.channel_layer.group_add( @@ -26,22 +26,23 @@ class ChatConsumer(AsyncWebsocketConsumer): # Receive message from WebSocket async def receive(self, text_data): text_data_json = json.loads(text_data) - message = text_data_json['message'] + print('receive from websock', text_data_json) + # message = text_data_json['message'] - # Send message to room group - await self.channel_layer.group_send( - self.room_group_name, - { - 'type': 'chat_message', - 'message': message - } - ) + # # Send message to room group + # await self.channel_layer.group_send( + # self.room_group_name, + # { + # 'type': 'chat_message', + # 'message': message + # } + # ) # Receive message from room group async def chat_message(self, event): message = event['message'] - + print('receive from room group', event) # Send message to WebSocket - await self.send(text_data=json.dumps({ - 'message': message - })) + # await self.send(text_data=json.dumps({ + # 'message': message + # })) diff --git a/polls/job.py b/polls/job.py deleted file mode 100644 index 182bcc5..0000000 --- a/polls/job.py +++ /dev/null @@ -1,17 +0,0 @@ -from background_task import background -from channels.layers import get_channel_layer -from asgiref.sync import async_to_sync -from polls.models import Message - - -@background(schedule=0) -def process_task(task, user_id): - channel_layer = get_channel_layer() - groups = task.groups - for g in groups: - async_to_sync(channel_layer.group_send)(g.id, { - "type": 0, - "send_from": user_id, - "group_id": g.id, - "content": g.content - }) diff --git a/polls/models.py b/polls/models.py index 41dfd8a..10a9f54 100644 --- a/polls/models.py +++ b/polls/models.py @@ -62,7 +62,7 @@ class Task(models.Model): def add_groups(self, groups): if not len(groups): - groups = Group.objects.filter(status='1') + groups = Group.objects.filter(status='开启') for g in groups: self.groups.add(g) diff --git a/polls/tasks.py b/polls/tasks.py new file mode 100644 index 0000000..415f129 --- /dev/null +++ b/polls/tasks.py @@ -0,0 +1,19 @@ +from background_task import background +from channels.layers import get_channel_layer +from asgiref.sync import async_to_sync +from polls.models import Message + + +@background(schedule=1) +def process_task(task, groups, user_id): + print(groups) + for g in groups: + print(g) + # async_to_sync(channel_layer.group_send)(g['id'], { + # "type": 0, + # "send_from": user_id, + # "group_id": g['id'], + # "content": task['content'] + # }) + channel_layer = get_channel_layer() + async_to_sync(channel_layer.send)('test_channel', {'type': g['id']}) diff --git a/polls/templates/polls/monitor_statistics.html b/polls/templates/polls/monitor_statistics.html index a1af011..4b435bc 100644 --- a/polls/templates/polls/monitor_statistics.html +++ b/polls/templates/polls/monitor_statistics.html @@ -1,12 +1,11 @@ {% extends 'polls/base.html' %} {% load static %} {% block content%} -
-
-
-
-
-
+
+
+
+
+
{% endblock%} @@ -15,38 +14,41 @@ {% endblock %} \ No newline at end of file diff --git a/polls/templates/polls/news_detail.html b/polls/templates/polls/news_detail.html index a5d247f..9529a90 100644 --- a/polls/templates/polls/news_detail.html +++ b/polls/templates/polls/news_detail.html @@ -1,24 +1,15 @@ {% extends 'polls/base.html' %} {% block content%}
-

如何理解伟大抗疫精神,听习近平总书记这样阐释

+

{{ news.title }}

- 来源:中瓣网 - 时间:2020-09-20 14:25:53 + 来源:{{news.source}} + 时间:{{ news.date|date:"Y-m-d" }}
-

- 同困难作斗争,是物质的角力,也是精神的对垒。在抗击新冠肺炎疫情的斗争中,是什么精神力量支撑着我们,创造了人类同疾病斗争史上的英勇壮举? -

- -

- 生命至上、举国同心、舍生忘死、尊重科学、命运与共——今日,在全国抗击新冠肺炎疫情表彰大会上,习近平总书记生动论述伟大抗疫精神。 -

-

- 人无精神则不立,国无精神则不强。唯有精神上站得住、站得稳,一个民族才能在历史洪流中屹立不倒、挺立潮头。什么是伟大抗疫精神?中华民族能够经历无数灾厄仍不断发展壮大的原因是什么? -

+ {{news.content|safe}}
{% endblock%} diff --git a/polls/urls.py b/polls/urls.py index b925811..23fa270 100644 --- a/polls/urls.py +++ b/polls/urls.py @@ -17,8 +17,10 @@ urlpatterns = [ path('medias/create/', views.create_media, name='polls_add_media'), path('medias/list/', views.medias, name='polls_medias'), path('news/list/', views.news_list, name='polls_news'), - path('news/detail/', views.news_detail, name='polls_news_detail'), + path('news/detail//', views.news_detail, name='polls_news_detail'), path('monitor/statistics/', views.monitor_statistics, name='polls_monitor_statistics'), path('tasks/list/', views.tasks, name='polls_tasks_list'), path('tasks/create/', views.create_task, name='polls_tasks_create'), + path('groups/list/', views.groups, name='polls_groups_list'), + path('compartments/list/', views.compartments, name='polls_compartments_list'), ] diff --git a/polls/utils.py b/polls/utils.py index 4a4dc03..792a453 100644 --- a/polls/utils.py +++ b/polls/utils.py @@ -7,6 +7,7 @@ from channels.db import database_sync_to_async from .exceptions import ClientError from django.conf import settings from polls.models import FileMessage, ImageMessage, NormalMessage, URLMessage +from itertools import chain def sent_sms_code(phone, code): @@ -107,13 +108,36 @@ def build_message(type, user_id, group_id, task_id, payload): elif type == 2: ImageMessage.objects.create(send_from__id=user_id, send_to__id=group_id, - task__id=task_id, title=payload.title, image=payload.image) + task__id=task_id, title=payload.title, image=payload.image) else: NormalMessage.objects.create(send_from__id=user_id, send_to__id=group_id, category=0, task__id=task_id, content=payload.content) +def model_to_dict(instance, fields): + opts = instance._meta + data = {} + for f in chain(opts.concrete_fields, opts.private_fields, opts.many_to_many): + if not getattr(f, 'editable', False): + continue + if fields and f.name not in fields: + continue + if f.name == 'id': + data[f.name] = str(f.value_from_object(instance)) + else: + data[f.name] = f.value_from_object(instance) + return data + + +def queryset_to_list(q, fields): + l = [] + for row in q: + r = model_to_dict(row, fields) + l.append(r) + return l + + if __name__ == '__main__': # sent_sms_code('13993199566') og_title, og_description, og_url, og_image = parse( diff --git a/polls/views/__init__.py b/polls/views/__init__.py index 92f365b..1e14dc2 100644 --- a/polls/views/__init__.py +++ b/polls/views/__init__.py @@ -3,4 +3,6 @@ from .notice import notices, read_notice from .media import medias, create_media from .news import news_list, news_detail from .monitor import monitor_statistics -from .task import tasks, create_task \ No newline at end of file +from .task import tasks, create_task +from .group import groups +from .compartment import compartments \ No newline at end of file diff --git a/polls/views/__pycache__/__init__.cpython-38.pyc b/polls/views/__pycache__/__init__.cpython-38.pyc index a9977bb29b4fd4bc96daf854643db6bd32a4b4ef..0173a40d23882b2916dba44a790eb19cbe243717 100644 GIT binary patch delta 157 zcmdnXI+2Yxl$V!_0SIOprp2$C$Scb@WukVCEJF%=jzq3xlq4fV3PTDJ|I(vQ2-2ifFuti0ISp{zyJUM delta 73 zcmbQpwwIMRl$V!_0SGLwq{L@U03)-Xro`lrj4hli8H%KU V%8H~W&tXdD18LD=6aYgWMgV(g4;}yj diff --git a/polls/views/__pycache__/compartment.cpython-38.pyc b/polls/views/__pycache__/compartment.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b6566dd656c7d111694effd6417f1666b44c41d6 GIT binary patch literal 895 zcmYjPy>1jS5VpPlcb8KNL;;jE+uTMes3HU+fJ70YK$?}%X>UEb?8#nlY+nM>UKQHB z0Yy^sIJ9o5cm*oPn-jWOdG;H7H1o~R+1}oWpd3fb`7cJuZ*S~Mh{h{C<|8UjI2ALEgc>0Ot*&mEba_V9Y zEeDNg`dULZuN8;+;lben-b_9i)t-XsRBHh3ac%VZ9KM3=ESirxC4`v^wQSnChRb!M zf!EXr-b##rU&k9f#-i%Uiri67IlE^YYS}7Sg+1lLE#0ss*#td1CSQ&=p^a|HChEgg z+($e-B8U=1(STA!@qjW!6j5+D>Z5z?&E<1D=1Cv$^atY^AKfynb$sHY&ev5=UK}3$ zmz?SZDY?);xv;GyxJbYi2$z_3U4t<>bFs0NT^pB3w5uh&!@@&TokKox!TYzLU9beJ z10N_+ixt$?xcIyg7PJd_Q(K+lo6fxQ1AoXFS6zpF*S=NHSFt!|b70$yBQ*e`7 zNwlrR8zi8?tOWw9{Lno9N%Rv8@b|PhGoVeesFY}`c3E^<4NM9@$U>?`BcN#ES^{q> zsoKUW-FQDgz~ZWbYg6nbn|0sxV+`y`8xKe@rBfQxl*V+l{U&tqImyRvpRX{hnwblw zZN0We<3f{ipI7E$p(@R15?d_HLz~81?+a_Yp#kpM_GTb5<4`MIAwx6s`=%p|<@N`v lJ8#-7Kt literal 0 HcmV?d00001 diff --git a/polls/views/__pycache__/group.cpython-38.pyc b/polls/views/__pycache__/group.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e1b3ec6325792b8cf18f82c6bbe03f4105860df5 GIT binary patch literal 994 zcmYjPOK%e~5VrT3$EHM4g+K!Cxn!%Js|tzo5JD}Y^uS6e+Qieu!MontURtCCA%$xt zF5KHAC;kAx#8=b zMg=KoMyc~X;T3-77eN*@u`j|R%A&>(M4ZLQ2}P@DXYB@yM5pLx-NuhaQuMMOB@jWI zwOIQrS<^MmwpegXhMhl{jSQ)c6qF3q(6h-4W2!fxD_Lr=$xAKE{}J-KQ>{+NZ~;YS z4l&-Yq!4;6pysE+fe2)|B@a%%v<;?YJx?$h*;pzl{X_Rf9V~N_xr2B#A~t&O=}q}{54&M zEZigLx6zBxBUc@ax{Ku6oyCawSG{F;jryMLnysbpl)3brB8N73eRTYmf5$4Z9YkU zlp{Tt%1mpcm4}yXcLUFHo%)!kw# z*D8B=^AEfWBeit#Y(vs}+7GFNO=NCrYT{b`DAq`GAuHQDx%Rtwm7ldA`4 R657Y-wY&sv;(64g{{YVy3{n69 literal 0 HcmV?d00001 diff --git a/polls/views/__pycache__/monitor.cpython-38.pyc b/polls/views/__pycache__/monitor.cpython-38.pyc index a114bf214ed35521ba8aa5ad4f2e97f4e83b0a44..f4516e0a4d9dbcb39a23f87f8c22503a612f9a92 100644 GIT binary patch literal 654 zcmZWm!EV$r5Vhkt*_KvXdZr(c%ciP&L~pfvDNj;j<@!N?V@mkFW}4p zE=c^6ublb|J$0N$t4d5X&oh%u=DqRd@$n%+`*Cr7^@kGjFD6ed!Q?f%zd#T~P)!W2 zD2;KV6T>QI(keB);wGyylUF&uV7n6l7S6;NJa9Ke`83HEx(*@tk%9Xwo_o;m4_OX2i5w;3XDd^Y}>R5w+H|TVux@8 zZ839^TF7m)mM!?eTibWwax6L?A&tNy#8nnq$eq0Dr3W{Q#VE?fD{w~Zk!#5l;>yXXGpeDT9%#M8YxsgaaZxXQOsv0w|hy8%`Tk$FE29m zaWJ8W`^TMNzAO&HT&!`dUHFxC(DvX*3DsQGe%098iG{I3YX2y26goyhZ zy(qP?G_|;7B|{PGQ eEM3G3Vj&1NAomuBO>TZlX-=vg$Q@wAc$fg#N-BH+ diff --git a/polls/views/__pycache__/news.cpython-38.pyc b/polls/views/__pycache__/news.cpython-38.pyc index d1ac08445ec78df2dd4f7fc355644999091d0a4b..75e1a5394fb5721f4008638100445117d0105f82 100644 GIT binary patch literal 1189 zcmYjQ&5j&35VqZa^V73CAe2ZUf&*F5AY~@x97T~5f<&Y}0Fj_2H0o)4X56^P9or3T z)N|Tg^9DK09(fO*!dFf_LUKx#cMj{8%U`*w%jK`iFDH``f${#^_440{kpED*Ibu+r zz_h=D;Dl2}8d^|_m?_poMHFzP;wCAQfMb<5S&;>ts6jIEk->6COVzfHFWyKm$N&Ktn)TKqFK44h)>=ze!@@RGGJqR?gv%r#73J7PrpMl+(j!qliVjxIwgEs zc5bVUPp$4uB|PzoY|4#zJvjUA{#kSXjQf~F2%p)ms)V&O2EMLzo%LA*I`}@vz_whA z*(W~w;rm~Fv=Pog6A+*2RV^xKeY%#)2?N1oWnf|v<|E@YbP5_yKSMs2J10PeTD@SV9n5NxPyu>m9!2Gwo`CE)z}h<{~_ip z@cQs#@zM%o7pqb$S?)HA*65Jy;^Bjb4;GDHNhKB#su5h4jowM8jYL0el*OMC4neb> zw-@G1h&Y64?|>lD2|b}P9nh4Hj^AB6r8y0L6+@rnK$a4ip{c$A;7Cnt25m&Kja<~j z^We}*l3qqo()b+6X6+xZZ(XMmuF8cgrJ8SDqkN1zvpCRiZbLwG3k9AziwvGnWZ@^t z&DUr_GOoovKz@89;^(kokzxY(G2g&?KFj@-*Fcw^Tj(2Cb~#l>kKSA7+E6Zk_qY=noO4lWQv$Vijt|lx8Gafrcf)4z@dfrm8aI*->4(e*kKo)+ ViO2Y8EjCOJl;;d)#3-Zr^drqnGcy1H delta 548 zcmY*VJxc>Y5Z$@E+(#}EK@1_WP_W1;SXo#E5yaR2H-aLA5_WVw{TqG#3FMInZ1|jeI@>eiMR?x)K zXueUmXyJ=cCUCw6Yp3PNxOxHc4vU z`)T0;fDC43DK)7_i`NEz=Vx~?ci}`yELkj-MMKG20Vqp^9Tt?8xxTio%tI!*{#-f9 z!7+=ZP(?5 z?=}EFiH_HPp^hiz=aWz-!)|W^147pl;8Te0z*Xb)IE)XI1#y&c84ac2X7*)PHu9bL mKglC0`#I5ky!`E-K6%HyncF-~=&;9@_0YmaC;_VBj(r0UUu`P@ diff --git a/polls/views/__pycache__/task.cpython-38.pyc b/polls/views/__pycache__/task.cpython-38.pyc index c3a707ad849affad894a97a7871838058257f983..85712f3fecd6db9a2462d42b2c12e669521053a0 100644 GIT binary patch delta 1119 zcmZ8f$&M2{6fM`3siq{|>4B+*gqk!E2C-m)5D3BBAw3>!yeSoB6Dqh;!FCXl(&|N6 zutBI*tPn`>2T1Sn50dei zvX~_^%0cuKF&n3`EMm2n9du`_Z&rR@5V!;?$x>NGkEWE*1Uv_YeMr$o)9TECB0F7)R^1EpF1RYZtd3RE`R?+4d*V2KyA!x{PPdBJ+F}ts7>j^%Pz5p=EB@< z$zX1e!ne^ogLH=o6i>Dn#;z|rbAQxbAhJSMNsp|(hTF)H4q0C(8yVCT%C~u|vi`bp zher?{ZOw$ws>96p0C0YtL z6of|rD+_wgZN+N9SSBQIDC=hV!Z~(VjjV1QS3S^~R931h%squ5=SLgJl3dzbG3he(jZ+u%_({K`4)mqjpmWgHUEkV;y=GO$x@ufY7wy zi7dF_b?}G1rK~4hEUTgFfLlvl#UgkMl&VKY$#_@{;Qfpa=#!LAWLAs?_muVE{#0g6 t{8Gd%u<5{mN%m*P^~>&9hPSQ{{eCJ3}OHP delta 788 zcmZ8e%Wl&^6!qBg`w=&3h!Ek?s35pIy7$C&EeXcYuXOlcUw9pI zzUc2h%Z$(<5|yZ$nxP4+mRgw|+LflKPUePg=7nChH`03MhknJ)bS-Oy4I;%_Y*UNc zZ=^YyldxIs9qO+3>r{O#1>WNOULzo-o8>f4hebZ5$*4FK2juwT6WJx257C$*e#uvw z4Wt@CsYTOid`ekUTvx6UU+gQl$fih?BlRkjUGYT;ZXg>GfIq_qqQX3Y$-ha$sJ$gz zENZPb|4=v+V`9!~v_8|Q|4w;j&U7w5*V-F1GM9-|sI*Df6SxOtZXK4&gZszK1taE( zp1R$w11+>Vd0V7_`d8w#7$ntIIY~sNg2B(q5Vli-&g%oN=auLFg>y)tTxtm^(C=`XoPL umgpOuBWxS*#EM diff --git a/polls/views/compartment.py b/polls/views/compartment.py new file mode 100644 index 0000000..20ffed4 --- /dev/null +++ b/polls/views/compartment.py @@ -0,0 +1,22 @@ +from django.shortcuts import render +from dashboard.models import Area_code_2020 +from django.http import JsonResponse + +from django.views.decorators.csrf import csrf_exempt +from polls.decorators import polls_login_required + + +@csrf_exempt +@polls_login_required +def compartments(request): + parent_code = request.GET.get('pcode', '620000000000') + compartments = Area_code_2020.objects.filter(pcode=parent_code) + results = [] + for o in compartments: + result = dict() + result['code'] = o.code + result['name'] = o.name + result['level'] = o.level + result['pcode'] = o.pcode + results.append(result) + return JsonResponse({'status': 'success', 'message': results}, safe=False) \ No newline at end of file diff --git a/polls/views/group.py b/polls/views/group.py new file mode 100644 index 0000000..83644cd --- /dev/null +++ b/polls/views/group.py @@ -0,0 +1,24 @@ +from django.shortcuts import render +from django.http import HttpResponse, JsonResponse +from django.views.decorators.csrf import csrf_exempt +import datetime + +from polls.decorators import polls_login_required +from django.core.exceptions import ObjectDoesNotExist +from dashboard.models import Group + +@csrf_exempt +@polls_login_required +def groups(request): + if request.method == 'POST': + return HttpResponse(status=405) + id = request.user.id + groups = Group.objects.filter(status='开启') + results = [] + for o in groups: + result = dict() + result['id'] = str(o.id) + result['name'] = o.name + result['image'] = request.build_absolute_uri(o.image.url) + results.append(result) + return JsonResponse(results, safe=False) \ No newline at end of file diff --git a/polls/views/monitor.py b/polls/views/monitor.py index e31bf7d..3312ef8 100644 --- a/polls/views/monitor.py +++ b/polls/views/monitor.py @@ -1,4 +1,11 @@ from django.shortcuts import render +from dashboard.models import Douyin, Qita, Toutiao, Weibo, Weixin + def monitor_statistics(request): - return render(request, 'polls/monitor_statistics.html') + wbc = Weibo.objects.count() + wxc = Weixin.objects.count() + ttc = Toutiao.objects.count() + qtc = Qita.objects.count() + dyc = Douyin.objects.count() + return render(request, 'polls/monitor_statistics.html', {'wbc': wbc, 'wxc': wxc, 'ttc': ttc, 'dyc': dyc, 'qtc': qtc}) diff --git a/polls/views/news.py b/polls/views/news.py index a8f6cc3..0a05b37 100644 --- a/polls/views/news.py +++ b/polls/views/news.py @@ -2,8 +2,14 @@ from django.shortcuts import render from dashboard.models import News from django.http import JsonResponse +from django.views.decorators.csrf import csrf_exempt +from polls.decorators import polls_login_required + + +@csrf_exempt +@polls_login_required def news_list(request): - category = request.GET.get('category','1') + category = request.GET.get('category', '1') news_list = News.objects.filter(type=category) results = [] for o in news_list: @@ -11,10 +17,13 @@ def news_list(request): result['id'] = o.id result['title'] = o.title result['author'] = o.author - result['content'] = o.content - result['date'] = o.date + result['source'] = o.source + result['image'] = request.build_absolute_uri(o.image.url) if o.image else '' + result['date'] = o.date.strftime("%Y-%m-%d") results.append(result) - return JsonResponse(results, safe=False) + return JsonResponse({'status': 'success', 'message': results}, safe=False) -def news_detail(request): - return render(request, 'polls/news_detail.html') + +def news_detail(request, news_id): + news = News.objects.get(pk=news_id) + return render(request, 'polls/news_detail.html', {'news': news}) diff --git a/polls/views/task.py b/polls/views/task.py index a2b7e4c..6280dd6 100644 --- a/polls/views/task.py +++ b/polls/views/task.py @@ -1,13 +1,16 @@ from django.shortcuts import render from django.http import HttpResponse, JsonResponse from django.views.decorators.csrf import csrf_exempt -from django.forms.models import model_to_dict import datetime +from channels.layers import get_channel_layer +from asgiref.sync import async_to_sync from polls.decorators import polls_login_required from polls.models import Task, TaskAddition -from polls.job import process_task +from polls.tasks import process_task from django.core.exceptions import ObjectDoesNotExist +from polls.utils import model_to_dict, queryset_to_list + @csrf_exempt @@ -46,14 +49,19 @@ def create_task(request): url = request.POST.get('url') file = request.FILES.get('file') picture = request.FILES.get('picture') - if not url: + if url: urlAddtion = TaskAddition.objects.create( task=task, category=0, url=url) - if not file: + if file: fileAddtion = TaskAddition.objects.create( task=task, category=1, file=file) - if not picture: + if picture: pictureAddtion = TaskAddition.objects.create( task=task, category=2, image=picture) - process_task(task, user) + t = model_to_dict(task, ["id", "content"]) + gs = queryset_to_list(task.groups.all(), ["id"]) + channel_layer = get_channel_layer() + # async_to_sync(channel_layer.send)('test_channel', {'type': 'hello'}) + async_to_sync(channel_layer.group_send)("chat", {"type": "update_price", "content":"helo"}) + return JsonResponse({'status': 'success'}) From d22da90872b2837e8b9d95f0e4463c4a1dd1deb9 Mon Sep 17 00:00:00 2001 From: baoliang Date: Sun, 20 Sep 2020 19:20:19 +0800 Subject: [PATCH 2/2] add unit --- dashboard/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dashboard/models.py b/dashboard/models.py index e03fc78..6de5313 100644 --- a/dashboard/models.py +++ b/dashboard/models.py @@ -108,7 +108,7 @@ class Userprofile(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) name = models.CharField('姓名', null=True, blank=True, max_length=256) sex = models.CharField('性别', null=True, blank=True, max_length=256) - unit = models.CharField('单位', null=True, blank=True, max_length=256) + unit = models.CharField('自己输入单位', null=True, blank=True, max_length=256) department = models.CharField('部门', null=True, blank=True, max_length=256) post = models.CharField('职务', null=True, blank=True, max_length=256) image = models.FileField(upload_to='profile', null=True, blank=True)