add feature

This commit is contained in:
baoliang 2020-09-24 14:51:39 +08:00
parent ed2b213592
commit 1d4417d438
9 changed files with 72 additions and 5 deletions

View File

@ -33,10 +33,23 @@ class VerifyCode(models.Model):
return self.phone + ':' + self.code
NOTICE_TYPE_CHOICES = (
(0, 'normal'),
(1, 'reply'),
)
class Notice(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
user = models.ForeignKey(User, on_delete=models.CASCADE)
type = models.IntegerField(
'category', choices=NOTICE_TYPE_CHOICES, default=0)
content = models.CharField('内容', max_length=256, null=False)
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)
is_read = models.BooleanField('是否阅读', default=False)
added = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
@ -48,6 +61,14 @@ class Notice(models.Model):
now = datetime.datetime.now()
return now <= self.timeouted
@classmethod
def create_normal_notice(cls, user_id, content):
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(user_id=user_id, content=content, app=app, model=model, record_id=record_id, record_value=record_value)
def __str__(self):
return self.content + ':' + self.user.username

View File

@ -55,7 +55,7 @@
var option2 = {
title: {
text: '政务新媒体区域分布',
subtext: '省直总数{{total1}},市州总数{{total2}},县区总数{{total3}}',
subtext: '省直部门:{{total1}},市直部门:{{total2}},县区政府:{{total3}}',
subtextStyle: {
fontSize: 16,
},

View File

@ -13,7 +13,9 @@ urlpatterns = [
path('password/recovery/', views.password_recover_step_one, name='polls_password_recovery'),
path('password/recovery/save/', views.password_recover_step_two, name='polls_password_recovery_save'),
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('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'),
@ -27,7 +29,7 @@ urlpatterns = [
path('tasks/create/', views.create_task, name='polls_tasks_create'),
path('tasks/create_test/', views.create_test_task, name='polls_tasks_create_test'),
path('groups/list/', views.groups, name='polls_groups_list'),
path('group/test-room/', views.room, name='polls_group_test_room'),
path('groups/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,5 +1,5 @@
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, notice_top, read_notice, reply_notice
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

View File

@ -1,6 +1,7 @@
from django.shortcuts import render
from django.http import HttpResponse, JsonResponse
from django.views.decorators.csrf import csrf_exempt
from django.apps import apps
import datetime
from polls.decorators import polls_login_required
@ -10,6 +11,24 @@ from django.core.exceptions import ObjectDoesNotExist
@csrf_exempt
@polls_login_required
def notices(request):
if request.method == 'POST':
return HttpResponse(status=405)
id = request.user.id
notices = Notice.objects.filter(user__id=id,is_read=False)
results = []
for o in notices:
result = dict()
result['id'] = o.id
result['type'] = o.type
result['content'] = o.content
result['added'] = o.added.strftime("%Y-%m-%d %H:%M:%S")
results.append(result)
return JsonResponse({'status': 'success', 'message':results}, safe=False)
@csrf_exempt
@polls_login_required
def notice_top(request):
if request.method == 'POST':
return HttpResponse(status=405)
id = request.user.id
@ -18,10 +37,11 @@ def notices(request):
for o in notices:
result = dict()
result['id'] = o.id
result['type'] = o.type
result['content'] = o.content
result['added'] = o.added.strftime("%Y-%m-%d %H:%M:%S")
results.append(result)
return JsonResponse(results, safe=False)
return JsonResponse({'status': 'success', 'message':results}, safe=False)
@csrf_exempt
@ -40,3 +60,23 @@ def read_notice(request):
return JsonResponse({'status': 'success'})
except ObjectDoesNotExist:
return JsonResponse({'status': 'error', 'message': '通知ID错误'})
@csrf_exempt
@polls_login_required
def reply_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.value)
m.save([notice.field])
return JsonResponse({'status': 'success'})
except ObjectDoesNotExist:
return JsonResponse({'status': 'error', 'message': '通知ID错误'})

View File

@ -5,7 +5,7 @@ from django.views.decorators.csrf import csrf_exempt
from django_token.models import Token
import datetime
from polls.models import VerifyCode
from polls.models import Notice, VerifyCode
from polls.utils import generate_code, sent_sms_code
from dashboard.models import Organization, Userprofile
@ -141,6 +141,10 @@ def register_step_two(request):
u = UserModel.objects.create_user(username=phone, password=password)
profile = Userprofile.objects.create(name=name, user=u, status=0, unit=unit, department=department, post=post)
admins = Userprofile.objects.filter(organization__level__level=1)
for a in admins:
content = '用户%s注册了账号,请审核' % (name,)
Notice.create_reply_notice(a.user.id, content, 'dashboard', 'Userprofile', 'status', profile.id, '1')
return JsonResponse({'status': 'success', 'message': '注册成功'})