Merge remote-tracking branch 'origin/master'

This commit is contained in:
Bob 2020-09-24 14:38:22 +08:00
commit ed2b213592
16 changed files with 154 additions and 41 deletions

View File

@ -109,6 +109,10 @@ class Organization(models.Model):
created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True)
class Meta:
ordering = ["name"]
def __str__(self):
return self.name
@ -537,6 +541,10 @@ class Area_code_2020(models.Model):
def __str__(self):
return self.name
class Meta:
ordering = ["code"]
# 新闻

View File

@ -17,7 +17,10 @@ urlpatterns = [
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('news/list/', views.news_list, name='polls_news'),
path('news/top/', views.news_top, name='polls_news_top'),
path('news/detail/<str:news_id>/', 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'),
@ -26,4 +29,5 @@ urlpatterns = [
path('groups/list/', views.groups, name='polls_groups_list'),
path('group/test-room/', views.room, name='polls_group_test_room'),
path('compartments/list/', views.compartments, name='polls_compartments_list'),
path('organizations/list/', views.organizations, name='polls_organizations_list'),
]

View File

@ -1,8 +1,9 @@
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, read_notice
from .media import medias, create_media, update_media
from .news import news_list, news_detail
from .media import medias, my_medias, create_media, update_media, media_detail
from .news import news_list, news_top, news_detail
from .monitor import monitor_statistics
from .task import tasks, create_task, create_test_task
from .group import groups, room
from .compartment import compartments
from .organizations import organizations

Binary file not shown.

View File

@ -9,7 +9,7 @@ from polls.decorators import polls_login_required
@csrf_exempt
@polls_login_required
def compartments(request):
parent_code = request.GET.get('pcode', '620000000000')
parent_code = request.GET.get('code', '620000000000')
compartments = Area_code_2020.objects.filter(pcode=parent_code)
results = []
for o in compartments:

View File

@ -18,7 +18,7 @@ def groups(request):
if request.method == 'POST':
return HttpResponse(status=405)
id = request.user.id
groups = Group.objects.filter(status='开启')
groups = Group.objects.filter(status='1')
results = []
for o in groups:
result = dict()
@ -26,4 +26,4 @@ def groups(request):
result['name'] = o.name
result['image'] = request.build_absolute_uri(o.image.url)
results.append(result)
return JsonResponse(results, safe=False)
return JsonResponse({'status': 'success', 'message': results}, safe=False)

View File

@ -18,39 +18,14 @@ def medias(request):
@csrf_exempt
@polls_login_required
def create_media(request):
profile = request.user.userprofile_set.first()
o = profile.organization
print(profile)
if request.method == 'GET':
def my_medias(request):
if request.method == 'POST':
return HttpResponse(status=405)
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': '公众号名称不能为空'})
media_id = request.POST.get('media_id')
if not media_id:
return JsonResponse({'status': 'error', 'message': '公众号ID不能为空'})
alias = request.POST.get('alias')
if not alias:
return JsonResponse({'status': 'error', 'message': '别名不能为空'})
if category == 'weixin':
instance = Weixin(code=code, weixinid=media_id, alias=alias,
image=request.FILES['file'], status=1, organization=o)
elif category == 'weibo':
instance = Weibo(code=code, weixinid=media_id, alias=alias,
image=request.FILES['file'], status=1, organization=o)
elif category == 'toutiao':
instance = Toutiao(code=code, weixinid=media_id, alias=alias,
image=request.FILES['file'], status=1, organization=o)
else:
instance = Qita(code=code, weixinid=media_id, alias=alias,
image=request.FILES['file'], status=1, organization=o)
instance.save()
return JsonResponse({'status': 'success'})
user = request.user
profile = user.userprofile_set.first()
organization_id = profile.organization.id
new_medias = NewMedia.media_list(organization_id)
return JsonResponse({'status': 'success', 'message': new_medias}, safe=False)
@csrf_exempt
@ -110,17 +85,78 @@ def update_media(request):
value = request.POST.get('value')
if not name:
return JsonResponse({'status': 'error', 'message': '值不能为空'})
result = dict()
if category == 'weixin':
instance = Weixin.objects.get(pk=media_id)
result['media_id'] = instance.weixinid
elif category == 'weibo':
instance = Weibo.objects.get(pk=media_id)
result['media_id'] = instance.weiboid
elif category == 'toutiao':
instance = Toutiao.objects.get(pk=media_id)
result['media_id'] = instance.toutiaoid
elif category == 'douyin':
instance = Douyin.objects.get(pk=media_id)
result['media_id'] = instance.douyinid
else:
instance = Qita.objects.get(pk=media_id)
result['media_id'] = instance.qitaid
setattr(instance, name, value)
instance.save(update_fields=[name])
return JsonResponse({'status': 'success'})
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})
@csrf_exempt
@polls_login_required
def media_detail(request, type, media_id):
result = dict()
if type == 'weixin':
media = Weixin.objects.get(pk=media_id)
result['media_id'] = media.weixinid
elif type == 'weibo':
media = Weibo.objects.get(pk=media_id)
result['media_id'] = media.weiboid
elif type == 'toutiao':
media = Toutiao.objects.get(pk=media_id)
result['media_id'] = media.toutiaoid
elif type == 'douyin':
media = Douyin.objects.get(pk=media_id)
result['media_id'] = media.douyinid
else:
media = Qita.objects.get(pk=media_id)
result['media_id'] = media.qitaid
admins = []
for admin in media.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'] = media.id
result['code'] = media.code
result['alias'] = media.alias
result['status'] = media.status
result['attention'] = media.attention
result['remark'] = media.remark
result['organization'] = media.organization.name
result['admin'] = admins
return JsonResponse({'status': 'success', 'message': result}, safe=False)

View File

@ -24,6 +24,24 @@ def news_list(request):
return JsonResponse({'status': 'success', 'message': results}, safe=False)
@csrf_exempt
@polls_login_required
def news_top(request):
category = request.GET.get('category', '3')
news_list = News.objects.filter(type=category)[:5]
results = []
for o in news_list:
result = dict()
result['id'] = o.id
result['title'] = o.title
result['author'] = o.author
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({'status': 'success', 'message': results}, safe=False)
def news_detail(request, news_id):
news = News.objects.get(pk=news_id)
return render(request, 'polls/news_detail.html', {'news': news})

View File

@ -0,0 +1,46 @@
from django.shortcuts import render
from dashboard.models import Organization
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 organizations(request):
category = request.GET.get('category', '1')
code = request.GET.get('code')
print(category, code)
if category == '1':
organizations = Organization.objects.exclude(
province=''
).filter(
cities='',
district=''
)
elif category == '2':
organizations = Organization.objects.exclude(
province=''
).filter(
cities=code,
district=''
)
elif category == '3':
organizations = Organization.objects.exclude(
province='',
cities='',
).filter(
district=code
)
results = []
for o in organizations:
result = dict()
result['id'] = o.id
result['name'] = o.name
result['province'] = o.province
result['cities'] = o.cities
result['district'] = o.district
results.append(result)
return JsonResponse({'status': 'success', 'message': results}, safe=False)

View File

@ -34,7 +34,7 @@ def polls_login(request):
user = UserModel.objects.filter(username=phone).first()
if not user:
return JsonResponse({'status': 'error', 'message': '用户名或密码错误'})
profile = request.user.userprofile_set.first()
profile = user.userprofile_set.first()
if not profile or profile.status == 0:
return JsonResponse({'status': 'error', 'message': '用户在审核中'})