diff --git a/dashboard/models.py b/dashboard/models.py index 6de5313..e489b0a 100644 --- a/dashboard/models.py +++ b/dashboard/models.py @@ -3,6 +3,8 @@ from django.contrib.auth.models import User from django.db import models # 权限等级 + + class Level(models.Model): id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) name = models.CharField('等级名', max_length=256, null=True, blank=True) @@ -12,6 +14,8 @@ class Level(models.Model): def __str__(self): return self.name + + class Group_type(models.Model): id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) type = models.CharField('矩阵类型', max_length=256, null=True, blank=True) @@ -19,6 +23,8 @@ class Group_type(models.Model): def __str__(self): return self.type # 矩阵 + + class Group(models.Model): GROUP_STATUS_CHOICES = ( ('0', '关闭'), @@ -37,7 +43,8 @@ class Group(models.Model): 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) - user = models.ForeignKey(User,on_delete=models.CASCADE,blank=True,null=True) + user = models.ForeignKey( + User, on_delete=models.CASCADE, blank=True, null=True) created = models.DateTimeField('创建时间', auto_now_add=True) updated = models.DateTimeField('更新时间', auto_now=True) @@ -46,6 +53,8 @@ class Group(models.Model): return self.name # 矩阵管理员 + + class Group_admin(models.Model): id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) user = models.ForeignKey( @@ -58,6 +67,8 @@ class Group_admin(models.Model): def __str__(self): return self.group.name # 矩阵成员 + + class Group_user(models.Model): id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) user = models.ForeignKey( @@ -71,6 +82,8 @@ class Group_user(models.Model): return self.user.username # 单位类型 + + class Organizationtype(models.Model): id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) organizationtype = models.CharField( @@ -94,8 +107,9 @@ class Organization(models.Model): 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) - level = models.ForeignKey(Level,on_delete=models.CASCADE,null=True,blank=True) - directly = models.CharField('直属',max_length=256,null=True,blank=True) + level = models.ForeignKey( + Level, on_delete=models.CASCADE, null=True, blank=True) + directly = models.CharField('直属', max_length=256, null=True, blank=True) created = models.DateTimeField('创建时间', auto_now_add=True) updated = models.DateTimeField('更新时间', auto_now=True) @@ -148,8 +162,8 @@ class NewMedia(models.Model): Organization, on_delete=models.CASCADE, null=True, blank=True) status = models.CharField( '状态', max_length=256, null=True, blank=True, choices=NEWMEDIA_STATUS_CHOICES) - attention = models.CharField('关注量',null=True,blank=True,max_length=256) - remark = models.CharField('备注',null=True,blank=True,max_length=2560) + 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) updated = models.DateTimeField('更新时间', auto_now=True) @@ -157,16 +171,158 @@ class NewMedia(models.Model): abstract = True ordering = ["-created"] + @classmethod + def category_one_count(cls): + t1 = Weixin.objects.exclude( + organization__province='' + ).filter( + organization__cities='', + organization__district='' + ).count() + t2 = Weibo.objects.exclude( + organization__province='' + ).filter( + organization__cities='', + organization__district='' + ).count() + t3 = Toutiao.objects.exclude( + organization__province='' + ).filter( + organization__cities='', + organization__district='' + ).count() + t4 = Douyin.objects.exclude( + organization__province='' + ).filter( + organization__cities='', + organization__district='' + ).count() + t5 = Qita.objects.exclude( + organization__province='' + ).filter( + organization__cities='', + organization__district='' + ).count() + return t1 + t2 + t3 + t4 + t5 + + @classmethod + def category_two_count(cls): + t1 = Weixin.objects.exclude( + organization__province='', + organization__cities='' + ).filter( + organization__district='' + ).count() + t2 = Weibo.objects.exclude( + organization__province='', + organization__cities='' + ).filter( + organization__district='' + ).count() + t3 = Toutiao.objects.exclude( + organization__province='', + organization__cities='' + ).filter( + organization__district='' + ).count() + t4 = Douyin.objects.exclude( + organization__province='', + organization__cities='' + ).filter( + organization__district='' + ).count() + t5 = Qita.objects.exclude( + organization__province='', + organization__cities='' + ).filter( + organization__district='' + ).count() + return t1 + t2 + t3 + t4 + t5 + + @classmethod + def category_three_count(cls): + t1 = Weixin.objects.exclude( + organization__province='', + organization__cities='', + organization__district='' + ).count() + t2 = Weibo.objects.exclude( + organization__province='', + organization__cities='', + organization__district='' + ).count() + t3 = Toutiao.objects.exclude( + organization__province='', + organization__cities='', + organization__district='' + ).count() + t4 = Douyin.objects.exclude( + organization__province='', + organization__cities='', + organization__district='' + ).count() + t5 = Qita.objects.exclude( + organization__province='', + organization__cities='', + organization__district='' + ).count() + return t1 + t2 + t3 + t4 + t5 + + @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) + results = [] + for o in weixin: + result = dict() + result['id'] = o.id + result['code'] = o.code + result['alias'] = o.alias + result['type'] = 'weixin' + results.append(result) + for o in weibo: + result = dict() + result['id'] = o.id + result['code'] = o.code + result['alias'] = o.alias + result['type'] = 'weibo' + results.append(result) + for o in toutiao: + result = dict() + result['id'] = o.id + result['code'] = o.code + result['alias'] = o.alias + result['type'] = 'toutiao' + results.append(result) + for o in douyin: + result = dict() + result['id'] = o.id + result['code'] = o.code + result['alias'] = o.alias + result['type'] = 'douyin' + results.append(result) + for o in qita: + result = dict() + result['id'] = o.id + result['code'] = o.code + result['alias'] = o.alias + result['type'] = 'qita' + results.append(result) + return results + + def __str__(self): return self.code + ':' + self.alias + # 微信公众号 class Weixin(NewMedia): weixinid = models.CharField('微信ID', max_length=256, null=True, blank=True) - - # 微信文章采集 class Weixin_data(models.Model): id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) @@ -349,6 +505,8 @@ class Douyin_data(models.Model): def __str__(self): return self.mewnedia.code # 其他新媒体 + + class Qita(NewMedia): type = models.CharField('新媒体类型', max_length=256, null=True, blank=True) name = models.CharField('新媒体名称', max_length=256, null=True, blank=True) @@ -387,7 +545,9 @@ class Area_code_2020(models.Model): def __str__(self): return self.name -#新闻 +# 新闻 + + class News(models.Model): NEWMEDIA_NEWS_CHOICES = ( ('0', '政策依据'), @@ -396,15 +556,16 @@ class News(models.Model): ('3', '监测通报'), ('4', '舆情热点') ) - id = models.UUIDField('id',primary_key=True,default=uuid.uuid4) - type = models.CharField('文章类型',max_length=256,null=True,blank=True,choices=NEWMEDIA_NEWS_CHOICES) - source = models.CharField('文章来源',max_length=256,null=True,blank=True) - title = models.CharField('文章标题',max_length=256,null=True,blank=True) + id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) + type = models.CharField('文章类型', max_length=256, null=True, + blank=True, choices=NEWMEDIA_NEWS_CHOICES) + source = models.CharField('文章来源', max_length=256, null=True, blank=True) + title = models.CharField('文章标题', max_length=256, null=True, blank=True) image = models.FileField( upload_to='news/%Y/%m/%d/', null=True, blank=True) - author = models.CharField('作者',max_length=256,null=True,blank=True) - date = models.DateField('发表日期',null=True,blank=True,max_length=256) - content = models.TextField('内容',null=True,blank=True) + author = models.CharField('作者', max_length=256, null=True, blank=True) + date = models.DateField('发表日期', null=True, blank=True, max_length=256) + content = models.TextField('内容', null=True, blank=True) def __str__(self): return self.title diff --git a/polls/templates/polls/monitor_statistics.html b/polls/templates/polls/monitor_statistics.html index 4b435bc..0c71189 100644 --- a/polls/templates/polls/monitor_statistics.html +++ b/polls/templates/polls/monitor_statistics.html @@ -4,7 +4,10 @@