remove message abstract=True

This commit is contained in:
baoliang 2020-09-26 09:47:24 +08:00
parent f20318af67
commit cf71d08bb2
11 changed files with 35 additions and 18 deletions

View File

@ -14,7 +14,7 @@ class ChatConsumer(AsyncJsonWebsocketConsumer):
self.room_group_name,
self.channel_name
)
print(self.room_name, 'connected')
await self.accept()
async def disconnect(self, close_code):

View File

@ -48,8 +48,10 @@ class Notice(models.Model):
app = models.CharField('app', max_length=256, null=True, blank=True)
model = models.CharField('model', max_length=256, null=True, blank=True)
field = models.CharField('field', max_length=256, null=True, blank=True)
record_id = models.CharField('record_id', max_length=256, null=True, blank=True)
record_value = models.CharField('record_value', max_length=256, null=True, blank=True)
record_id = models.CharField(
'record_id', max_length=256, null=True, blank=True)
record_value = models.CharField(
'record_value', max_length=256, null=True, blank=True)
is_read = models.BooleanField('是否阅读', default=False)
added = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
@ -67,7 +69,7 @@ class Notice(models.Model):
@classmethod
def create_reply_notice(cls, user_id, content, app, model, field, record_id, record_value):
return Notice.objects.create(user_id=user_id, content=content, app=app, model=model, record_id=record_id, record_value=record_value)
return Notice.objects.create(type=1, user_id=user_id, content=content, app=app, model=model, field=field, record_id=record_id, record_value=record_value)
def __str__(self):
return self.content + ':' + self.user.username
@ -134,7 +136,6 @@ class Message(models.Model):
updated = models.DateTimeField(auto_now=True)
class Meta:
abstract = True
ordering = ["-added"]
def __str__(self):

View File

@ -3,5 +3,5 @@ from django.urls import re_path
from . import consumers
websocket_urlpatterns = [
re_path(r'ws/chat/(?P<room_name>\w+)/$', consumers.ChatConsumer),
re_path(r'ws/chat/(?P<room_name>[\w-]+)/$', consumers.ChatConsumer),
]

View File

@ -15,7 +15,7 @@ urlpatterns = [
path('notices/list/', views.notices, name='polls_notices'),
path('notices/top/', views.notice_top, name='polls_notice_top'),
path('notices/read/', views.read_notice, name='polls_read_notice'),
path('notices/reply', views.reply_notice, name='polls_reply_notice'),
path('notices/reply/', views.reply_notice, name='polls_reply_notice'),
path('medias/create/', views.create_media, name='polls_add_media'),
path('medias/update/', views.update_media, name='polls_update_media'),
path('medias/list/', views.medias, name='polls_medias'),

View File

@ -2,8 +2,9 @@ from django.http import HttpResponse, JsonResponse
from django.views.decorators.csrf import csrf_exempt
from django.core.paginator import Paginator
from dashboard.models import NewMedia, Weixin, Weibo, Toutiao, Douyin, Qita
from dashboard.models import Douyin, NewMedia, Qita, Toutiao, Userprofile, Weibo, Weixin
from polls.decorators import polls_login_required
from polls.models import Notice
@csrf_exempt
@ -35,36 +36,49 @@ def create_media(request):
o = profile.organization
if request.method == 'GET':
return HttpResponse(status=405)
f = request.FILES.get('file')
category = request.POST.get('category')
if not category:
return JsonResponse({'status': 'error', 'message': '类型错误'})
code = request.POST.get('code')
if not code:
return JsonResponse({'status': 'error', 'message': '公众号名称不能为空'})
return JsonResponse({'status': 'error', 'message': '名称不能为空'})
media_id = request.POST.get('media_id')
if not media_id:
return JsonResponse({'status': 'error', 'message': '公众号ID不能为空'})
return JsonResponse({'status': 'error', 'message': '监测ID不能为空'})
alias = request.POST.get('alias')
if not alias:
return JsonResponse({'status': 'error', 'message': '别名不能为空'})
attention = request.POST.get('attention', '')
remark = request.POST.get('remark', '')
model_name = ''
if category == 'weixin':
model_name = 'Weixin'
instance = Weixin(code=code, weixinid=media_id, alias=alias,
image=request.FILES['file'], status='0', organization=o)
image=f, status=0, organization=o, attention=attention, remark=remark)
elif category == 'weibo':
model_name = 'Weibo'
instance = Weibo(code=code, weiboid=media_id, alias=alias,
image=request.FILES['file'], status='0', organization=o)
image=f, status=0, organization=o, attention=attention, remark=remark)
elif category == 'toutiao':
model_name = 'Toutiao'
instance = Toutiao(code=code, toutiaoid=media_id, alias=alias,
image=request.FILES['file'], status='0', organization=o)
image=f, status=0, organization=o, attention=attention, remark=remark)
elif category == 'douyin':
model_name = 'Douyin'
instance = Douyin(code=code, douyinid=media_id, alias=alias,
image=request.FILES['file'], status='0', organization=o)
image=f, status=0, organization=o, attention=attention, remark=remark)
else:
model_name = 'Qita'
type = request.POST.get('type')
instance = Qita(code=code, qitaid=media_id, alias=alias,
image=request.FILES['file'], status='0', organization=o)
image=f, status=0, organization=o, attention=attention, remark=remark)
instance.save()
admins = Userprofile.objects.filter(organization__level__level=1)
for a in admins:
content = '用户%s创建了新媒体,请审核' % (profile.name,)
Notice.create_reply_notice(a.user.id, content, 'dashboard', model_name, 'status', instance.id, '1')
return JsonResponse({'status': 'success'})

View File

@ -41,6 +41,8 @@ def monitor_statistics(request):
'organization__cities').annotate(num_media=Count('organization__cities'))
for row in q:
code = row['organization__cities']
print(code)
compartment = COMPARTMENTS[code]
if code in results:
nums = results[compartment]

View File

@ -75,8 +75,8 @@ def reply_notice(request):
notice = Notice.objects.get(id=notice_id)
ReplyModel = apps.get_model(notice.app, notice.model)
m = ReplyModel.objects.get(pk=notice.record_id)
setattr(m, notice.field, notice.value)
m.save([notice.field])
setattr(m, notice.field, notice.record_value)
m.save(update_fields=[notice.field])
return JsonResponse({'status': 'success'})
except ObjectDoesNotExist:
return JsonResponse({'status': 'error', 'message': '通知ID错误'})