Merge remote-tracking branch 'origin/master'

This commit is contained in:
Bob 2020-10-09 09:42:20 +08:00
commit de6670e3ab
15 changed files with 197 additions and 51 deletions

View File

@ -38,13 +38,14 @@ class Group(models.Model):
type = models.ForeignKey(
Group_type, on_delete=models.CASCADE, null=True, blank=True)
status = models.IntegerField(
'状态', null=True, blank=True,default=0)
'状态', null=True, blank=True, default=0)
province = models.CharField('', max_length=256, null=True, blank=True)
cities = models.CharField('', max_length=256, null=True, blank=True)
district = models.CharField('', max_length=256, null=True, blank=True)
town = models.CharField('', max_length=256, null=True, blank=True)
village = models.CharField('', max_length=256, null=True, blank=True)
classify = models.CharField('分类',max_length=256,null=True,blank=True,choices=GROUP_CLASSIFY_CHOICES)
classify = models.CharField(
'分类', max_length=256, null=True, blank=True, choices=GROUP_CLASSIFY_CHOICES)
user = models.ForeignKey(
User, on_delete=models.CASCADE, blank=True, null=True)
@ -112,7 +113,7 @@ class Organization(models.Model):
level = models.ForeignKey(
Level, on_delete=models.CASCADE, null=True, blank=True)
directly = models.CharField('单位类型', max_length=256, null=True, blank=True)
status = models.CharField('状态',max_length=256,null=True,blank=True)
status = models.CharField('状态', max_length=256, null=True, blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True)
@ -148,6 +149,15 @@ class Userprofile(models.Model):
def is_level2(self):
return self.organization.level.level == 2
@classmethod
def level2_admin(cls, cities):
return Userprofile.objects.filter(organization__level__level=2, organization__cities=cities)
@classmethod
def level1_admin(cls):
return Userprofile.objects.filter(organization__level__level=1)
def __str__(self):
return self.user.username+":"+self.name
@ -169,7 +179,7 @@ class NewMedia(models.Model):
organization = models.ForeignKey(
Organization, on_delete=models.CASCADE, null=True, blank=True)
status = models.IntegerField(
'状态',null=True, blank=True,default=0)
'状态', null=True, blank=True, default=0)
attention = models.CharField('关注量', null=True, blank=True, max_length=256)
remark = models.CharField('备注', null=True, blank=True, max_length=2560)
created = models.DateTimeField('创建时间', auto_now_add=True)
@ -278,17 +288,23 @@ class NewMedia(models.Model):
@classmethod
def media_list(cls, organization_id):
weixin = Weixin.objects.filter(organization_id=organization_id)
weibo = Weibo.objects.filter(organization_id=organization_id)
toutiao = Toutiao.objects.filter(organization_id=organization_id)
douyin = Douyin.objects.filter(organization_id=organization_id)
qita = Qita.objects.filter(organization_id=organization_id)
weixin = Weixin.objects.filter(
organization_id=organization_id).exclude(status=0)
weibo = Weibo.objects.filter(
organization_id=organization_id).exclude(status=0)
toutiao = Toutiao.objects.filter(
organization_id=organization_id).exclude(status=0)
douyin = Douyin.objects.filter(
organization_id=organization_id).exclude(status=0)
qita = Qita.objects.filter(
organization_id=organization_id).exclude(status=0)
results = []
for o in weixin:
result = dict()
result['id'] = o.id
result['code'] = o.code
result['alias'] = o.alias
result['status'] = o.status
result['type'] = 'weixin'
results.append(result)
for o in weibo:
@ -296,6 +312,7 @@ class NewMedia(models.Model):
result['id'] = o.id
result['code'] = o.code
result['alias'] = o.alias
result['status'] = o.status
result['type'] = 'weibo'
results.append(result)
for o in toutiao:
@ -303,6 +320,7 @@ class NewMedia(models.Model):
result['id'] = o.id
result['code'] = o.code
result['alias'] = o.alias
result['status'] = o.status
result['type'] = 'toutiao'
results.append(result)
for o in douyin:
@ -310,6 +328,7 @@ class NewMedia(models.Model):
result['id'] = o.id
result['code'] = o.code
result['alias'] = o.alias
result['status'] = o.status
result['type'] = 'douyin'
results.append(result)
for o in qita:
@ -317,11 +336,11 @@ class NewMedia(models.Model):
result['id'] = o.id
result['code'] = o.code
result['alias'] = o.alias
result['status'] = o.status
result['type'] = 'qita'
results.append(result)
return results
def __str__(self):
return self.code + ':' + self.alias

View File

@ -71,8 +71,8 @@ class Notice(models.Model):
return Notice.objects.create(user_id=user_id, content=content)
@classmethod
def create_reply_notice(cls, user_id, content, app, model, field, record_id, 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 create_reply_notice(cls, user_id, content, app, model, field, record_id, record_pass_value, record_reject_value):
return Notice.objects.create(type=1, user_id=user_id, content=content, app=app, model=model, field=field, record_id=record_id, record_pass_value=record_pass_value, record_reject_value=record_reject_value)
def __str__(self):
return self.content + ':' + self.user.username
@ -143,24 +143,31 @@ class Message(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
send_from = models.ForeignKey(User, on_delete=models.CASCADE)
send_to = models.ForeignKey(Group, on_delete=models.CASCADE)
task = models.ForeignKey(Task, on_delete=models.CASCADE, null=True, blank=True)
task = models.ForeignKey(
Task, on_delete=models.CASCADE, null=True, blank=True)
type = models.IntegerField(
'Type', choices=MESSAGE_TYPE_CHOICES, default=1)
#text
# text
content = models.TextField('内容', null=True, blank=True)
#url
page_title = models.CharField('page_title', max_length=256, null=True, blank=True)
page_description = models.CharField('page_description', max_length=512, null=True, blank=True)
page_image = models.CharField('page_image', max_length=256, null=True, blank=True)
# url
page_title = models.CharField(
'page_title', max_length=256, null=True, blank=True)
page_description = models.CharField(
'page_description', max_length=512, null=True, blank=True)
page_image = models.CharField(
'page_image', max_length=256, null=True, blank=True)
url = models.CharField('url', max_length=256, null=True, blank=True)
#file
file_title = models.CharField('file_title', max_length=256, null=True, blank=True)
# file
file_title = models.CharField(
'file_title', max_length=256, null=True, blank=True)
file = models.CharField('file', max_length=256, null=True, blank=True)
#image
image_title = models.CharField('image_title', max_length=256, null=True, blank=True)
picture = models.CharField('picture', max_length=256, null=True, blank=True)
# image
image_title = models.CharField(
'image_title', max_length=256, null=True, blank=True)
picture = models.CharField(
'picture', max_length=256, null=True, blank=True)
added = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)

View File

@ -17,13 +17,16 @@ 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/pass/', views.pass_notice, name='polls_pass_notice'),
path('notices/reject/', views.reject_notice, name='polls_reject_notice'),
path('notices/detail/<str:notice_id>/', views.detail_notice, name='polls_detail_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'),
path('medias/my/', views.my_medias, name='polls_my_medias'),
path('medias/<str:type>/<str:media_id>/',
views.media_detail, name='polls_media_detail'),
path('medias/delete/', views.delete_media, name='polls_delete_media'),
path('news/list/', views.news_list, name='polls_news'),
path('news/top/', views.news_top, name='polls_news_top'),
path('news/detail/<str:news_id>/',

View File

@ -1,10 +1,10 @@
from .user import index, status_500, status_401, polls_login, send_code, register_step_one, register_step_two, password_recover_step_one, password_recover_step_two
from .notice import notices, notice_top, read_notice, reply_notice
from .media import medias, my_medias, create_media, update_media, media_detail
from .notice import notices, notice_top, read_notice, pass_notice, reject_notice, detail_notice
from .media import medias, my_medias, create_media, update_media, media_detail, delete_media
from .news import news_list, news_top, news_detail
from .monitor import monitor_statistics, monitor_result
from .task import tasks, create_task, create_test_task
from .group import groups, room
from .compartment import compartments
from .organizations import organizations, organization_level
from .message import last_messages, send_text_message
from .message import last_messages, send_text_message

View File

@ -9,8 +9,12 @@ from polls.decorators import polls_login_required
@csrf_exempt
@polls_login_required
def compartments(request):
level = request.GET.get('level')
parent_code = request.GET.get('code', '620000000000')
compartments = Area_code_2020.objects.filter(pcode=parent_code)
if level == '2':
compartments = Area_code_2020.objects.filter(code=parent_code)
else:
compartments = Area_code_2020.objects.filter(pcode=parent_code)
results = []
for o in compartments:
result = dict()

View File

@ -18,7 +18,11 @@ def groups(request):
if request.method == 'POST':
return HttpResponse(status=405)
id = request.user.id
groups = Group.objects.filter(status='1')
category = request.GET.get('category', '0')
if not category:
return JsonResponse({'status': 'error', 'message': '参数错误'})
groups = Group.objects.filter(status='1',classify=category)
results = []
for o in groups:
result = dict()

View File

@ -55,29 +55,30 @@ def create_media(request):
if category == 'weixin':
model_name = 'Weixin'
instance = Weixin(code=code, weixinid=media_id, alias=alias,
image=f, status=0, organization=o, attention=attention, remark=remark)
image=f, status=1, organization=o, attention=attention, remark=remark)
elif category == 'weibo':
model_name = 'Weibo'
instance = Weibo(code=code, weiboid=media_id, alias=alias,
image=f, status=0, organization=o, attention=attention, remark=remark)
image=f, status=1, organization=o, attention=attention, remark=remark)
elif category == 'toutiao':
model_name = 'Toutiao'
instance = Toutiao(code=code, toutiaoid=media_id, alias=alias,
image=f, status=0, organization=o, attention=attention, remark=remark)
image=f, status=1, organization=o, attention=attention, remark=remark)
elif category == 'douyin':
model_name = 'Douyin'
instance = Douyin(code=code, douyinid=media_id, alias=alias,
image=f, status=0, organization=o, attention=attention, remark=remark)
image=f, status=1, 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=f, status=0, organization=o, attention=attention, remark=remark)
image=f, status=1, organization=o, attention=attention, remark=remark)
instance.save()
admins = Userprofile.objects.filter(organization__level__level=1)
admins = Userprofile.level2_admin(instance.organization.cities)
for a in admins:
content = '用户%s创建了新媒体,请审核' % (profile.name,)
Notice.create_reply_notice(a.user.id, content, 'dashboard', model_name, 'status', instance.id, '1')
Notice.create_reply_notice(
a.user.id, content, 'dashboard', model_name, 'status', instance.id, '2', '0')
return JsonResponse({'status': 'success'})
@ -97,7 +98,7 @@ def update_media(request):
if not name:
return JsonResponse({'status': 'error', 'message': '名称不能为空'})
value = request.POST.get('value')
if not name:
if not value:
return JsonResponse({'status': 'error', 'message': '值不能为空'})
result = dict()
if category == 'weixin':
@ -156,7 +157,7 @@ def media_detail(request, type, media_id):
else:
media = Qita.objects.get(pk=media_id)
result['media_id'] = media.qitaid
admins = []
for admin in media.organization.userprofile_set.all():
u = dict()
@ -174,3 +175,65 @@ def media_detail(request, type, media_id):
result['organization'] = media.organization.name
result['admin'] = admins
return JsonResponse({'status': 'success', 'message': result}, safe=False)
@csrf_exempt
@polls_login_required
def delete_media(request):
if request.method == 'GET':
return HttpResponse(status=405)
profile = request.user.userprofile_set.first()
o = profile.organization
category = request.POST.get('category')
if not category:
return JsonResponse({'status': 'error', 'message': '参数错误'})
media_id = request.POST.get('media_id')
if not media_id:
return JsonResponse({'status': 'error', 'message': '参数错误'})
result = dict()
if category == 'weixin':
model_name = 'Weixin'
instance = Weixin.objects.get(pk=media_id)
result['media_id'] = instance.weixinid
elif category == 'weibo':
model_name = 'Weibo'
instance = Weibo.objects.get(pk=media_id)
result['media_id'] = instance.weiboid
elif category == 'toutiao':
model_name = 'Toutiao'
instance = Toutiao.objects.get(pk=media_id)
result['media_id'] = instance.toutiaoid
elif category == 'douyin':
model_name = 'Douyin'
instance = Douyin.objects.get(pk=media_id)
result['media_id'] = instance.douyinid
else:
model_name = 'Qita'
instance = Qita.objects.get(pk=media_id)
result['media_id'] = instance.qitaid
instance.status = 4
instance.save()
admins = Userprofile.level2_admin(instance.organization.cities)
for a in admins:
content = '用户%s申请注销新媒体,请审核' % (profile.name,)
Notice.create_reply_notice(
a.user.id, content, 'dashboard', model_name, 'status', instance.id, '5', '3')
admins = []
for admin in instance.organization.userprofile_set.all():
u = dict()
u['id'] = admin.user.id
u['name'] = admin.name
u['phone'] = admin.user.username
admins.append(u)
result['id'] = instance.id
result['code'] = instance.code
result['alias'] = instance.alias
result['status'] = instance.status
result['attention'] = instance.attention
result['remark'] = instance.remark
result['organization'] = instance.organization.name
result['admin'] = admins
return JsonResponse({'status': 'success', 'message': result})

View File

@ -7,6 +7,7 @@ import datetime
from polls.decorators import polls_login_required
from polls.models import Notice
from django.core.exceptions import ObjectDoesNotExist
from dashboard.models import Userprofile
@csrf_exempt
@ -22,6 +23,7 @@ def notices(request):
result['id'] = o.id
result['type'] = o.type
result['content'] = o.content
result['isRead'] = o.is_read
result['added'] = o.added.strftime("%Y-%m-%d %H:%M:%S")
results.append(result)
return JsonResponse({'status': 'success', 'message': results}, safe=False)
@ -40,6 +42,7 @@ def notice_top(request):
result['id'] = o.id
result['type'] = o.type
result['content'] = o.content
result['isRead'] = o.is_read
result['added'] = o.added.strftime("%Y-%m-%d %H:%M:%S")
results.append(result)
return JsonResponse({'status': 'success', 'message': results}, safe=False)
@ -66,9 +69,8 @@ def read_notice(request):
@csrf_exempt
@polls_login_required
def detail_notice(request, notice_id):
if request.method == 'GET':
if request.method == 'POST':
return HttpResponse(status=405)
notice_id = request.POST.get('notice')
if not notice_id:
return JsonResponse({'status': 'error', 'message': '通知ID错误'})
try:
@ -77,14 +79,25 @@ def detail_notice(request, notice_id):
results['id'] = notice.id
results['category'] = notice.type
results['content'] = notice.content
results['app'] = notice.app
results['model'] = notice.model
results['field'] = notice.field
results['record_id'] = notice.record_id
results['record_pass_value'] = notice.record_pass_value
results['record_reject_value'] = notice.record_reject_value
ReplyModel = apps.get_model(notice.app, notice.model)
m = ReplyModel.objects.get(pk=notice.record_id)
detail = dict()
detail['id'] = m.id
detail['code'] = m.code
if notice.model == 'Weixin':
detail['type'] = 'weixin'
elif notice.model == 'Weibo':
detail['type'] = 'weibo'
elif notice.model == 'Toutiao':
detail['type'] = 'Toutiao'
elif notice.model == 'Douyin':
detail['type'] = 'douyin'
else:
detail['type'] = 'qita'
detail['status'] = m.status
results['media'] = detail
results['added'] = notice.added.strftime("%Y-%m-%d %H:%M:%S")
result['updated'] = notice.updated.strftime("%Y-%m-%d %H:%M:%S")
results['updated'] = notice.updated.strftime("%Y-%m-%d %H:%M:%S")
return JsonResponse({'status': 'success', 'message': results})
except ObjectDoesNotExist:
return JsonResponse({'status': 'error', 'message': '通知ID错误'})
@ -92,7 +105,7 @@ def detail_notice(request, notice_id):
@csrf_exempt
@polls_login_required
def reply_notice(request):
def pass_notice(request):
if request.method == 'GET':
return HttpResponse(status=405)
id = request.user.id
@ -103,8 +116,41 @@ 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.record_value)
setattr(m, notice.field, notice.record_pass_value)
m.save(update_fields=[notice.field])
return JsonResponse({'status': 'success'})
notice.is_read = True
notice.save()
pass_value = notice.record_pass_value
if pass_value == '2':
admins = Userprofile.level1_admin()
for a in admins:
Notice.create_reply_notice(a.user.id, notice.content, notice.app, notice.model, notice.field, notice.record_id, '3', '0')
if pass_value == '5':
admins = Userprofile.level1_admin()
for a in admins:
Notice.create_reply_notice(a.user.id, notice.content, notice.app, notice.model, notice.field, notice.record_id, '0', '3')
return JsonResponse({'status': 'success', 'message': '申请已同意'})
except ObjectDoesNotExist:
return JsonResponse({'status': 'error', 'message': '通知ID错误'})
@csrf_exempt
@polls_login_required
def reject_notice(request):
if request.method == 'GET':
return HttpResponse(status=405)
id = request.user.id
notice_id = request.POST.get('notice_id')
if not notice_id:
return JsonResponse({'status': 'error', 'message': '通知ID错误'})
try:
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.record_reject_value)
m.save(update_fields=[notice.field])
notice.is_read = True
notice.save()
return JsonResponse({'status': 'success', 'message': '申请已拒绝'})
except ObjectDoesNotExist:
return JsonResponse({'status': 'error', 'message': '通知ID错误'})

View File

@ -57,4 +57,4 @@ def organization_level(request):
level = organization.level.level
if not level:
return JsonResponse({'status': 'error', 'message': '权限错误'})
return JsonResponse({'status': 'success', 'message': {'level': level, 'organization_id': organization.id}}, safe=False)
return JsonResponse({'status': 'success', 'message': {'level': level, 'cities': organization.cities, 'district': organization.district}}, safe=False)