remove message abstract=True
This commit is contained in:
parent
f20318af67
commit
cf71d08bb2
|
@ -14,7 +14,7 @@ class ChatConsumer(AsyncJsonWebsocketConsumer):
|
||||||
self.room_group_name,
|
self.room_group_name,
|
||||||
self.channel_name
|
self.channel_name
|
||||||
)
|
)
|
||||||
|
print(self.room_name, 'connected')
|
||||||
await self.accept()
|
await self.accept()
|
||||||
|
|
||||||
async def disconnect(self, close_code):
|
async def disconnect(self, close_code):
|
||||||
|
|
|
@ -48,8 +48,10 @@ class Notice(models.Model):
|
||||||
app = models.CharField('app', max_length=256, null=True, blank=True)
|
app = models.CharField('app', max_length=256, null=True, blank=True)
|
||||||
model = models.CharField('model', 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)
|
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_id = models.CharField(
|
||||||
record_value = models.CharField('record_value', max_length=256, null=True, blank=True)
|
'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)
|
is_read = models.BooleanField('是否阅读', default=False)
|
||||||
added = models.DateTimeField(auto_now_add=True)
|
added = models.DateTimeField(auto_now_add=True)
|
||||||
updated = models.DateTimeField(auto_now=True)
|
updated = models.DateTimeField(auto_now=True)
|
||||||
|
@ -67,7 +69,7 @@ class Notice(models.Model):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_reply_notice(cls, user_id, content, app, model, field, record_id, record_value):
|
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):
|
def __str__(self):
|
||||||
return self.content + ':' + self.user.username
|
return self.content + ':' + self.user.username
|
||||||
|
@ -134,7 +136,6 @@ class Message(models.Model):
|
||||||
updated = models.DateTimeField(auto_now=True)
|
updated = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
|
||||||
ordering = ["-added"]
|
ordering = ["-added"]
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
|
@ -3,5 +3,5 @@ from django.urls import re_path
|
||||||
from . import consumers
|
from . import consumers
|
||||||
|
|
||||||
websocket_urlpatterns = [
|
websocket_urlpatterns = [
|
||||||
re_path(r'ws/chat/(?P<room_name>\w+)/$', consumers.ChatConsumer),
|
re_path(r'ws/chat/(?P<room_name>[\w-]+)/$', consumers.ChatConsumer),
|
||||||
]
|
]
|
|
@ -15,7 +15,7 @@ urlpatterns = [
|
||||||
path('notices/list/', views.notices, name='polls_notices'),
|
path('notices/list/', views.notices, name='polls_notices'),
|
||||||
path('notices/top/', views.notice_top, name='polls_notice_top'),
|
path('notices/top/', views.notice_top, name='polls_notice_top'),
|
||||||
path('notices/read/', views.read_notice, name='polls_read_notice'),
|
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/create/', views.create_media, name='polls_add_media'),
|
||||||
path('medias/update/', views.update_media, name='polls_update_media'),
|
path('medias/update/', views.update_media, name='polls_update_media'),
|
||||||
path('medias/list/', views.medias, name='polls_medias'),
|
path('medias/list/', views.medias, name='polls_medias'),
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -2,8 +2,9 @@ from django.http import HttpResponse, JsonResponse
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
from django.core.paginator import Paginator
|
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.decorators import polls_login_required
|
||||||
|
from polls.models import Notice
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
|
@ -35,36 +36,49 @@ def create_media(request):
|
||||||
o = profile.organization
|
o = profile.organization
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
return HttpResponse(status=405)
|
return HttpResponse(status=405)
|
||||||
|
f = request.FILES.get('file')
|
||||||
category = request.POST.get('category')
|
category = request.POST.get('category')
|
||||||
if not category:
|
if not category:
|
||||||
return JsonResponse({'status': 'error', 'message': '类型错误'})
|
return JsonResponse({'status': 'error', 'message': '类型错误'})
|
||||||
code = request.POST.get('code')
|
code = request.POST.get('code')
|
||||||
if not code:
|
if not code:
|
||||||
return JsonResponse({'status': 'error', 'message': '公众号名称不能为空'})
|
return JsonResponse({'status': 'error', 'message': '名称不能为空'})
|
||||||
media_id = request.POST.get('media_id')
|
media_id = request.POST.get('media_id')
|
||||||
if not media_id:
|
if not media_id:
|
||||||
return JsonResponse({'status': 'error', 'message': '公众号ID不能为空'})
|
return JsonResponse({'status': 'error', 'message': '监测ID不能为空'})
|
||||||
alias = request.POST.get('alias')
|
alias = request.POST.get('alias')
|
||||||
if not alias:
|
if not alias:
|
||||||
return JsonResponse({'status': 'error', 'message': '别名不能为空'})
|
return JsonResponse({'status': 'error', 'message': '别名不能为空'})
|
||||||
|
attention = request.POST.get('attention', '')
|
||||||
|
remark = request.POST.get('remark', '')
|
||||||
|
model_name = ''
|
||||||
if category == 'weixin':
|
if category == 'weixin':
|
||||||
|
model_name = 'Weixin'
|
||||||
instance = Weixin(code=code, weixinid=media_id, alias=alias,
|
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':
|
elif category == 'weibo':
|
||||||
|
model_name = 'Weibo'
|
||||||
instance = Weibo(code=code, weiboid=media_id, alias=alias,
|
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':
|
elif category == 'toutiao':
|
||||||
|
model_name = 'Toutiao'
|
||||||
instance = Toutiao(code=code, toutiaoid=media_id, alias=alias,
|
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':
|
elif category == 'douyin':
|
||||||
|
model_name = 'Douyin'
|
||||||
instance = Douyin(code=code, douyinid=media_id, alias=alias,
|
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:
|
else:
|
||||||
|
model_name = 'Qita'
|
||||||
type = request.POST.get('type')
|
type = request.POST.get('type')
|
||||||
instance = Qita(code=code, qitaid=media_id, alias=alias,
|
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()
|
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'})
|
return JsonResponse({'status': 'success'})
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,8 @@ def monitor_statistics(request):
|
||||||
'organization__cities').annotate(num_media=Count('organization__cities'))
|
'organization__cities').annotate(num_media=Count('organization__cities'))
|
||||||
for row in q:
|
for row in q:
|
||||||
code = row['organization__cities']
|
code = row['organization__cities']
|
||||||
|
print(code)
|
||||||
|
|
||||||
compartment = COMPARTMENTS[code]
|
compartment = COMPARTMENTS[code]
|
||||||
if code in results:
|
if code in results:
|
||||||
nums = results[compartment]
|
nums = results[compartment]
|
||||||
|
|
|
@ -75,8 +75,8 @@ def reply_notice(request):
|
||||||
notice = Notice.objects.get(id=notice_id)
|
notice = Notice.objects.get(id=notice_id)
|
||||||
ReplyModel = apps.get_model(notice.app, notice.model)
|
ReplyModel = apps.get_model(notice.app, notice.model)
|
||||||
m = ReplyModel.objects.get(pk=notice.record_id)
|
m = ReplyModel.objects.get(pk=notice.record_id)
|
||||||
setattr(m, notice.field, notice.value)
|
setattr(m, notice.field, notice.record_value)
|
||||||
m.save([notice.field])
|
m.save(update_fields=[notice.field])
|
||||||
return JsonResponse({'status': 'success'})
|
return JsonResponse({'status': 'success'})
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
return JsonResponse({'status': 'error', 'message': '通知ID错误'})
|
return JsonResponse({'status': 'error', 'message': '通知ID错误'})
|
Loading…
Reference in New Issue