Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ac4ee0
commit 63d18fc
Showing
9 changed files
with
189 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# vim | ||
*.un~ | ||
*.swp | ||
|
||
# cache | ||
__pycache__/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.0.1 on 2020-05-09 11:09 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('database', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='message', | ||
name='_t', | ||
field=models.IntegerField(default=1589022546), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Generated by Django 3.0.1 on 2020-05-10 10:12 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('database', '0002_auto_20200509_1109'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='MESSAGES', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('course_id', models.CharField(default='', max_length=64)), | ||
('sender', models.CharField(default='', max_length=64)), | ||
('receiver', models.CharField(default='', max_length=64)), | ||
('_t', models.IntegerField(default=1589105519)), | ||
('msg', models.CharField(default='', max_length=2048)), | ||
], | ||
options={ | ||
'verbose_name': '消息表', | ||
'db_table': 'dkt_messages', | ||
'ordering': ('-_t',), | ||
}, | ||
), | ||
migrations.DeleteModel( | ||
name='MESSAGE', | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# coding=utf-8 | ||
""" | ||
用户消息接收和发布 | ||
""" | ||
|
||
import time | ||
from django.db.models import Q | ||
|
||
from dkt.database.models import MESSAGES | ||
from dkt.database.models import USERS | ||
from dkt.database.models import COURSE | ||
from dkt.const import ObjectStatus | ||
|
||
def get_message(request, post_data): | ||
""" | ||
获取对话列表, 或者历史公告 | ||
:param request: | ||
:param post_data: | ||
""" | ||
|
||
receiver = post_data.get('account') | ||
course_id = post_data.get('course_id') | ||
since = post_data.get('since', int(time.time())) | ||
sender = post_data.get('sender') | ||
|
||
if sender == 'pub': | ||
msgs = MESSAGES.objects.filter(course_id=course_id, receiver='all', _t__lte=since)[:10] | ||
else: | ||
msgs = MESSAGES.objects.filter(course_id=course_id, sender=sender, receiver=receiver, _t__lte=since)[:10] | ||
|
||
res = [] | ||
for msg in msgs: | ||
res.append({'_t': msg._t, 'msg': msg.msg, 'sender': msg.sender}) | ||
return res | ||
|
||
def pub_message(request, post_data): | ||
""" | ||
老师发布消息 | ||
:param request: | ||
:param post_data: | ||
""" | ||
|
||
course_id = post_data.get('course_id') | ||
sender = post_data.get('account') | ||
receiver = post_data.get('receiver') | ||
msg = post_data.get('msg') | ||
|
||
if not COURSE.objects.filter(Q(course_id=course_id), Q(t_account=sender)|Q(s_account=sender)): | ||
return "Course and sender can't match!" | ||
if receiver != 'all' and not COURSE.objects.filter(Q(course_id=course_id), Q(t_account=receiver)|Q(s_account=receiver)): | ||
return "Course and receiver can't match!" | ||
if receiver == 'all' and USERS.objects.get(account=sender).role != 'teacher': | ||
return "Can't send to all, because you are not a teacher!" | ||
|
||
MESSAGES.objects.create(course_id=course_id, sender=sender, receiver=receiver, _t=int(time.time()), msg=msg) | ||
|
||
return ObjectStatus.SUCCESS.value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters