add feature
This commit is contained in:
parent
cfc32c37ee
commit
57723444cf
|
@ -113,6 +113,10 @@ class Organization(models.Model):
|
||||||
created = models.DateTimeField('创建时间', auto_now_add=True)
|
created = models.DateTimeField('创建时间', auto_now_add=True)
|
||||||
updated = models.DateTimeField('更新时间', auto_now=True)
|
updated = models.DateTimeField('更新时间', auto_now=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
ordering = ["name"]
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
@ -545,6 +549,10 @@ class Area_code_2020(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
ordering = ["code"]
|
||||||
|
|
||||||
|
|
||||||
# 新闻
|
# 新闻
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,10 @@ urlpatterns = [
|
||||||
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'),
|
||||||
|
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/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('news/detail/<str:news_id>/', views.news_detail, name='polls_news_detail'),
|
||||||
path('monitor/statistics/', views.monitor_statistics, name='polls_monitor_statistics'),
|
path('monitor/statistics/', views.monitor_statistics, name='polls_monitor_statistics'),
|
||||||
path('tasks/list/', views.tasks, name='polls_tasks_list'),
|
path('tasks/list/', views.tasks, name='polls_tasks_list'),
|
||||||
|
@ -26,4 +29,5 @@ urlpatterns = [
|
||||||
path('groups/list/', views.groups, name='polls_groups_list'),
|
path('groups/list/', views.groups, name='polls_groups_list'),
|
||||||
path('group/test-room/', views.room, name='polls_group_test_room'),
|
path('group/test-room/', views.room, name='polls_group_test_room'),
|
||||||
path('compartments/list/', views.compartments, name='polls_compartments_list'),
|
path('compartments/list/', views.compartments, name='polls_compartments_list'),
|
||||||
|
path('organizations/list/', views.organizations, name='polls_organizations_list'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -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 .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 .notice import notices, read_notice
|
||||||
from .media import medias, create_media, update_media
|
from .media import medias, my_medias, create_media, update_media, media_detail
|
||||||
from .news import news_list, news_detail
|
from .news import news_list, news_top, news_detail
|
||||||
from .monitor import monitor_statistics
|
from .monitor import monitor_statistics
|
||||||
from .task import tasks, create_task, create_test_task
|
from .task import tasks, create_task, create_test_task
|
||||||
from .group import groups, room
|
from .group import groups, room
|
||||||
from .compartment import compartments
|
from .compartment import compartments
|
||||||
|
from .organizations import organizations
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -9,7 +9,7 @@ from polls.decorators import polls_login_required
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
@polls_login_required
|
@polls_login_required
|
||||||
def compartments(request):
|
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)
|
compartments = Area_code_2020.objects.filter(pcode=parent_code)
|
||||||
results = []
|
results = []
|
||||||
for o in compartments:
|
for o in compartments:
|
||||||
|
|
|
@ -18,7 +18,7 @@ def groups(request):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
return HttpResponse(status=405)
|
return HttpResponse(status=405)
|
||||||
id = request.user.id
|
id = request.user.id
|
||||||
groups = Group.objects.filter(status='开启')
|
groups = Group.objects.filter(status='1')
|
||||||
results = []
|
results = []
|
||||||
for o in groups:
|
for o in groups:
|
||||||
result = dict()
|
result = dict()
|
||||||
|
@ -26,4 +26,4 @@ def groups(request):
|
||||||
result['name'] = o.name
|
result['name'] = o.name
|
||||||
result['image'] = request.build_absolute_uri(o.image.url)
|
result['image'] = request.build_absolute_uri(o.image.url)
|
||||||
results.append(result)
|
results.append(result)
|
||||||
return JsonResponse(results, safe=False)
|
return JsonResponse({'status': 'success', 'message': results}, safe=False)
|
||||||
|
|
|
@ -18,39 +18,14 @@ def medias(request):
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
@polls_login_required
|
@polls_login_required
|
||||||
def create_media(request):
|
def my_medias(request):
|
||||||
profile = request.user.userprofile_set.first()
|
if request.method == 'POST':
|
||||||
o = profile.organization
|
|
||||||
print(profile)
|
|
||||||
if request.method == 'GET':
|
|
||||||
return HttpResponse(status=405)
|
return HttpResponse(status=405)
|
||||||
category = request.POST.get('category')
|
user = request.user
|
||||||
if not category:
|
profile = user.userprofile_set.first()
|
||||||
return JsonResponse({'status': 'error', 'message': '类型错误'})
|
organization_id = profile.organization.id
|
||||||
code = request.POST.get('code')
|
new_medias = NewMedia.media_list(organization_id)
|
||||||
if not code:
|
return JsonResponse({'status': 'success', 'message': new_medias}, safe=False)
|
||||||
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'})
|
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
|
@ -110,17 +85,78 @@ def update_media(request):
|
||||||
value = request.POST.get('value')
|
value = request.POST.get('value')
|
||||||
if not name:
|
if not name:
|
||||||
return JsonResponse({'status': 'error', 'message': '值不能为空'})
|
return JsonResponse({'status': 'error', 'message': '值不能为空'})
|
||||||
|
result = dict()
|
||||||
if category == 'weixin':
|
if category == 'weixin':
|
||||||
instance = Weixin.objects.get(pk=media_id)
|
instance = Weixin.objects.get(pk=media_id)
|
||||||
|
result['media_id'] = instance.weixinid
|
||||||
elif category == 'weibo':
|
elif category == 'weibo':
|
||||||
instance = Weibo.objects.get(pk=media_id)
|
instance = Weibo.objects.get(pk=media_id)
|
||||||
|
result['media_id'] = instance.weiboid
|
||||||
elif category == 'toutiao':
|
elif category == 'toutiao':
|
||||||
instance = Toutiao.objects.get(pk=media_id)
|
instance = Toutiao.objects.get(pk=media_id)
|
||||||
|
result['media_id'] = instance.toutiaoid
|
||||||
elif category == 'douyin':
|
elif category == 'douyin':
|
||||||
instance = Douyin.objects.get(pk=media_id)
|
instance = Douyin.objects.get(pk=media_id)
|
||||||
|
result['media_id'] = instance.douyinid
|
||||||
else:
|
else:
|
||||||
instance = Qita.objects.get(pk=media_id)
|
instance = Qita.objects.get(pk=media_id)
|
||||||
|
result['media_id'] = instance.qitaid
|
||||||
|
|
||||||
setattr(instance, name, value)
|
setattr(instance, name, value)
|
||||||
instance.save(update_fields=[name])
|
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)
|
||||||
|
|
|
@ -24,6 +24,24 @@ def news_list(request):
|
||||||
return JsonResponse({'status': 'success', 'message': results}, safe=False)
|
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):
|
def news_detail(request, news_id):
|
||||||
news = News.objects.get(pk=news_id)
|
news = News.objects.get(pk=news_id)
|
||||||
return render(request, 'polls/news_detail.html', {'news': news})
|
return render(request, 'polls/news_detail.html', {'news': news})
|
||||||
|
|
|
@ -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)
|
|
@ -34,7 +34,7 @@ def polls_login(request):
|
||||||
user = UserModel.objects.filter(username=phone).first()
|
user = UserModel.objects.filter(username=phone).first()
|
||||||
if not user:
|
if not user:
|
||||||
return JsonResponse({'status': 'error', 'message': '用户名或密码错误'})
|
return JsonResponse({'status': 'error', 'message': '用户名或密码错误'})
|
||||||
profile = request.user.userprofile_set.first()
|
profile = user.userprofile_set.first()
|
||||||
if not profile or profile.status == 0:
|
if not profile or profile.status == 0:
|
||||||
return JsonResponse({'status': 'error', 'message': '用户在审核中'})
|
return JsonResponse({'status': 'error', 'message': '用户在审核中'})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue