newmediamonitoring/polls/models.py

284 lines
10 KiB
Python
Raw Normal View History

2020-08-20 07:38:42 +00:00
from django.db import models
2020-08-20 10:34:14 +00:00
import uuid
import datetime
2020-09-03 02:56:28 +00:00
from django.contrib.auth.models import User
2020-09-13 06:06:58 +00:00
from django.db import models
2020-09-03 02:56:28 +00:00
2021-02-01 13:55:32 +00:00
from dashboard.models import Group, Group_user, NewMedia
2020-08-20 07:38:42 +00:00
2020-08-20 10:34:14 +00:00
VERIFY_CODE_TYPE_CHOICES = (
(0, 'register'),
(1, 'password_recover'),
)
2020-09-03 02:56:28 +00:00
2020-08-20 10:34:14 +00:00
class VerifyCode(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
code = models.CharField('code', max_length=8, null=False)
phone = models.CharField('phone', max_length=11, null=False)
timeouted = models.DateTimeField('timeouted', null=False)
2020-09-03 02:56:28 +00:00
category = models.IntegerField(
'category', choices=VERIFY_CODE_TYPE_CHOICES, default=0)
2020-08-20 10:34:14 +00:00
added = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
class Meta:
ordering = ["-added"]
def is_in_progress(self):
now = datetime.datetime.now()
2020-08-24 14:35:47 +00:00
return now <= self.timeouted
2020-08-20 10:34:14 +00:00
2020-09-03 02:56:28 +00:00
def __str__(self):
return self.phone + ':' + self.code
2020-09-24 06:51:39 +00:00
NOTICE_TYPE_CHOICES = (
(0, 'normal'),
(1, 'reply'),
2021-01-10 07:21:51 +00:00
(2, 'news')
2020-09-24 06:51:39 +00:00
)
2020-09-03 02:56:28 +00:00
class Notice(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
user = models.ForeignKey(User, on_delete=models.CASCADE)
2020-09-24 06:51:39 +00:00
type = models.IntegerField(
'category', choices=NOTICE_TYPE_CHOICES, default=0)
2020-09-03 02:56:28 +00:00
content = models.CharField('内容', max_length=256, null=False)
2020-10-27 10:24:47 +00:00
group_id = models.CharField(
'group_id', max_length=256, null=True, blank=True)
2021-01-10 07:21:51 +00:00
news_id = models.CharField(
'news_id', max_length=256, null=True, blank=True)
2020-09-24 06:51:39 +00:00
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)
2020-09-26 01:47:24 +00:00
record_id = models.CharField(
'record_id', max_length=256, null=True, blank=True)
2020-09-30 08:02:29 +00:00
record_pass_value = models.CharField(
'record_pass_value', max_length=256, null=True, blank=True)
record_reject_value = models.CharField(
'record_reject_value', max_length=256, null=True, blank=True)
2020-09-18 06:03:50 +00:00
is_read = models.BooleanField('是否阅读', default=False)
2020-09-03 02:56:28 +00:00
added = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
class Meta:
ordering = ["-added"]
def is_in_progress(self):
now = datetime.datetime.now()
return now <= self.timeouted
2020-08-20 10:34:14 +00:00
2020-09-24 06:51:39 +00:00
@classmethod
2020-10-21 13:37:19 +00:00
def create_normal_notice(cls, user_id, content, group_id):
return Notice.objects.create(user_id=user_id, content=content, group_id=group_id)
2020-09-24 06:51:39 +00:00
2021-01-10 07:21:51 +00:00
@classmethod
def create_news_notice(cls, user_id, content, news_id):
2021-01-10 13:22:39 +00:00
return Notice.objects.create(type=2, user_id=user_id, content=content, news_id=news_id)
2021-01-10 07:21:51 +00:00
2020-09-24 06:51:39 +00:00
@classmethod
2021-02-03 08:15:45 +00:00
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)
2020-09-24 06:51:39 +00:00
2020-08-20 10:34:14 +00:00
def __str__(self):
2020-09-03 09:46:04 +00:00
return self.content + ':' + self.user.username
2020-09-03 02:56:28 +00:00
2020-09-18 06:03:50 +00:00
class Task(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
2020-09-18 11:09:51 +00:00
created_by = models.ForeignKey(User, on_delete=models.CASCADE)
2020-09-18 06:03:50 +00:00
groups = models.ManyToManyField(Group)
content = models.TextField('内容', null=True, blank=True)
added = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
2020-09-18 07:52:06 +00:00
def add_groups(self, groups):
if not len(groups):
2020-09-20 11:14:54 +00:00
groups = Group.objects.filter(status='开启')
2020-09-18 07:52:06 +00:00
for g in groups:
self.groups.add(g)
2020-10-10 14:44:15 +00:00
def total(self):
return sum(g.total_user() for g in self.groups.all())
def record(self):
return TaskRecord.objects.filter(task=self).count()
2020-10-11 06:58:13 +00:00
def records(self):
2020-11-23 07:43:53 +00:00
group_ids = [group.id for group in self.groups.all()]
return Group_user.objects.filter(group__in=group_ids)
2020-10-11 06:58:13 +00:00
2020-10-10 17:42:12 +00:00
def add_task_message(self, user_id):
for group in self.groups.all():
Message.objects.create(
type=4, send_from_id=user_id, send_to_id=group.id, task=self, content=self.content)
def add_url_message(self, user_id, title, description, url, image):
for group in self.groups.all():
Message.objects.create(
2021-02-03 08:15:45 +00:00
type=1, send_from_id=user_id, send_to_id=group.id, task=self, page_title=title,
page_description=description, page_image=image, url=url)
2020-10-10 17:42:12 +00:00
2020-09-18 06:03:50 +00:00
class Meta:
ordering = ["-added"]
2020-09-18 16:11:19 +00:00
TASK_ADDITION_TYPE_CHOICES = (
2020-09-18 07:52:57 +00:00
(0, 'url'),
(1, 'file'),
(2, 'picture')
)
2020-09-18 06:03:50 +00:00
class TaskAddition(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
task = models.ForeignKey(Task, on_delete=models.CASCADE)
category = models.IntegerField(
2020-09-18 16:11:19 +00:00
'category', choices=TASK_ADDITION_TYPE_CHOICES, default=1)
2020-10-11 07:32:58 +00:00
url = models.CharField('url', max_length=512, null=True, blank=True)
2020-09-18 06:03:50 +00:00
file = models.FileField(
upload_to='task/file/%Y/%m/%d/', null=True, blank=True)
picture = models.ImageField(
upload_to='task/image/%Y/%m/%d/', null=True, blank=True)
2020-09-18 07:52:06 +00:00
2020-09-18 06:03:50 +00:00
TASK_RECORD_STATUS_CHOICES = (
(0, '未完成'),
(1, '完成'),
2020-09-03 02:56:28 +00:00
)
2020-09-18 06:03:50 +00:00
class TaskRecord(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
user = models.ForeignKey(User, on_delete=models.CASCADE)
2020-10-10 14:44:15 +00:00
task = models.ForeignKey(Task, on_delete=models.CASCADE)
2020-09-18 06:03:50 +00:00
status = models.IntegerField(
2020-10-10 14:44:15 +00:00
'状态', choices=TASK_RECORD_STATUS_CHOICES, default=1)
2020-09-18 06:03:50 +00:00
added = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
2020-09-26 05:47:36 +00:00
MESSAGE_TYPE_CHOICES = (
(0, 'text'),
(1, 'url'),
(2, 'file'),
2020-09-26 07:40:15 +00:00
(3, 'image'),
2020-09-26 07:34:36 +00:00
(4, 'task')
2020-09-26 05:47:36 +00:00
)
2020-09-03 02:56:28 +00:00
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)
2020-10-08 07:12:48 +00:00
task = models.ForeignKey(
Task, on_delete=models.CASCADE, null=True, blank=True)
2020-09-26 05:51:36 +00:00
type = models.IntegerField(
2020-09-26 05:47:36 +00:00
'Type', choices=MESSAGE_TYPE_CHOICES, default=1)
2020-10-08 07:12:48 +00:00
# text
2020-09-18 16:11:19 +00:00
content = models.TextField('内容', null=True, blank=True)
2020-10-08 07:12:48 +00:00
# url
page_title = models.CharField(
2020-10-11 07:32:58 +00:00
'page_title', max_length=512, null=True, blank=True)
2020-10-08 07:12:48 +00:00
page_description = models.CharField(
2020-10-11 07:32:58 +00:00
'page_description', max_length=1024, null=True, blank=True)
2020-10-08 07:12:48 +00:00
page_image = models.CharField(
2020-10-11 07:32:58 +00:00
'page_image', max_length=512, null=True, blank=True)
url = models.CharField('url', max_length=512, null=True, blank=True)
2020-09-03 02:56:28 +00:00
2020-10-08 07:12:48 +00:00
# file
file_title = models.CharField(
'file_title', max_length=256, null=True, blank=True)
2020-09-26 05:47:36 +00:00
file = models.CharField('file', max_length=256, null=True, blank=True)
2020-09-03 02:56:28 +00:00
2020-10-08 07:12:48 +00:00
# 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)
2020-09-03 02:56:28 +00:00
2020-09-26 05:47:36 +00:00
added = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
2020-09-03 02:56:28 +00:00
2020-09-26 05:47:36 +00:00
class Meta:
2020-10-10 17:42:12 +00:00
ordering = ["added"]
2020-09-03 02:56:28 +00:00
2020-09-13 06:06:58 +00:00
2020-09-18 06:03:50 +00:00
class GroupRecord(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
user = models.ForeignKey(User, on_delete=models.CASCADE)
group = models.ForeignKey(Group, on_delete=models.CASCADE)
enter_at = models.DateTimeField(auto_now=True)
leave_at = models.DateTimeField(auto_now=True)
added = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
2020-10-27 10:24:47 +00:00
class AppVersion(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
version = models.IntegerField('version', default=1)
added = models.DateTimeField(auto_now_add=True)
2020-10-27 13:02:08 +00:00
updated = models.DateTimeField(auto_now=True)
class Meta:
ordering = ["-version"]
2020-11-17 00:45:44 +00:00
class SMSNotifyRecord(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
phone = models.CharField('phone', max_length=32)
added = models.DateField(auto_now_add=True)
2020-11-18 07:43:57 +00:00
notice_id = models.CharField('notice_id', max_length=64)
updated = models.DateTimeField(auto_now=True)
2020-11-28 10:23:56 +00:00
class VoiceNotifyRecord(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
phone = models.CharField('phone', max_length=32)
added = models.DateField(auto_now_add=True)
notice_id = models.CharField('notice_id', max_length=64)
2021-02-01 13:55:32 +00:00
updated = models.DateTimeField(auto_now=True)
UNQUALIFIED_MEDIA_TYPE_CHOICES = (
(0, 'weixin'),
(1, 'weibo'),
(2, 'toutiao'),
(3, 'douyin'),
(4, 'qita')
)
class UnqualifiedMedia(models.Model):
2021-02-03 08:15:45 +00:00
'''
type:
weixin = 0
weibo = 1
douyin = 2
toutiao = 3
qita = 4
'''
2021-02-01 13:55:32 +00:00
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
2021-02-02 02:12:08 +00:00
media_id = models.UUIDField('media_id', null=True, blank=True)
2021-02-03 08:15:45 +00:00
name = models.CharField('name', max_length=256, null=True, blank=True)
2021-02-02 05:22:45 +00:00
unit = models.CharField('unit', max_length=256, null=True, blank=True)
2021-02-02 02:12:08 +00:00
type = models.IntegerField(
'Type', choices=UNQUALIFIED_MEDIA_TYPE_CHOICES, default=0)
2021-02-02 05:22:45 +00:00
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)
2021-02-01 13:55:32 +00:00
result = models.TextField('result', null=True, blank=True)
cou = models.IntegerField('count of update', default=0)
dos = models.IntegerField('days of silent', default=0)
sdos = models.DateField('start date of silent', null=True, blank=True)
edos = models.DateField('end date of silent', null=True, blank=True)
version = models.IntegerField('version', default=0)
added = models.DateField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)