Skip to content

Commit

Permalink
add the function deleting file
Browse files Browse the repository at this point in the history
  • Loading branch information
changkaiyan committed Aug 15, 2020
1 parent b809ae1 commit 9b4f1d2
Show file tree
Hide file tree
Showing 553 changed files with 107,542 additions and 7 deletions.
7 changes: 6 additions & 1 deletion Contributions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@
# Beta 0.2

- 完善了数据库的设计
- 解决了一些bug
- 解决了一些bug

# v0.4

- 增加了部署到服务器的功能
- 解决了文件删除的bug
Binary file modified app01/__pycache__/admin.cpython-38.pyc
Binary file not shown.
Binary file modified app01/__pycache__/models.cpython-38.pyc
Binary file not shown.
6 changes: 5 additions & 1 deletion app01/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,20 @@ class KnowledgeAdmin(Canexcel):
search_fields = ['abstract', 'question']
list_filter = ['toresearch']


class PaperAdmin(Canexcel):
list_display = ('_id', 'name',"typ")
search_fields = ['name', 'typ',"contribution","motivation","method"]
list_filter = ['typ']
inlines = [PaperCommentInline,]
inlines = [PaperCommentInline]
exclude = ("_file",)

class ProjectAdmin(Canexcel):
list_display = ('_id', 'name',"typ")
search_fields = ['name', 'typ',"contribution","motivation","method"]
list_filter = ['typ']
inlines = [ProjectCommentInline,]
exclude = ("_file",)

class MeetingAdmin(Canexcel):
list_display = ('name', 'start', 'end')
Expand All @@ -86,6 +89,7 @@ class SummaryAdmin(Canexcel):
list_display = ('name', "typ")
search_fields = ['name', 'typ',"contribution","motivation","method"]
list_filter = ['typ']
exclude = ("_file",)

class TaskAdmin(Canexcel):
list_display = ("_id", 'name', "typ","deadline")
Expand Down
59 changes: 59 additions & 0 deletions app01/filedelete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from django.db.models.signals import post_init, post_save, pre_delete
from django.dispatch.dispatcher import receiver
import os
from sitep.settings import MEDIA_ROOT
from .models import Paper, Project, Summary


@receiver(post_init, sender=Paper)
def welcom_paper(instance, **kwargs):
instance._file = instance.file


@receiver(post_save, sender=Paper)
def welcome_paper(instance, created, **kwargs):
if not created and instance._file != instance.file:
fname = os.path.join(MEDIA_ROOT, instance._file)
if os.path.isfile(fname):
os.remove(fname)
instance._file = instance.file


@receiver(post_init, sender=Project)
def welcom_project(instance, **kwargs):
instance._file = instance.file


@receiver(post_save, sender=Project)
def welcome_project(instance, created, **kwargs):
if not created and instance._file != instance.file:
fname = os.path.join(MEDIA_ROOT, instance._file)
if os.path.isfile(fname):
os.remove(fname)
instance._file = instance.file


@receiver(post_init, sender=Summary)
def welcom_summary(instance, **kwargs):
instance._file = instance.file


@receiver(post_save, sender=Summary)
def welcome_summary(instance, created, **kwargs):
if not created and instance._file != instance.file:
fname = os.path.join(MEDIA_ROOT, instance._file)
if os.path.isfile(fname):
os.remove(fname)
instance._file = instance.file

@receiver(pre_delete, sender=Paper)
def filedelete_paper(sender, instance, **kwargs):
instance.file.delete(False)

@receiver(pre_delete, sender=Project)
def filedelete_paper(sender, instance, **kwargs):
instance.file.delete(False)

@receiver(pre_delete, sender=Summary)
def filedelete_paper(sender, instance, **kwargs):
instance.file.delete(False)
30 changes: 30 additions & 0 deletions app01/migrations/0011_auto_20200814_2208.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 2.2 on 2020-08-14 14:08

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('app01', '0010_auto_20200812_1947'),
]

operations = [
migrations.CreateModel(
name='Myfile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('file', models.FileField(blank=True, default=None, null=True, upload_to='paper', verbose_name='Attachment')),
],
options={
'verbose_name_plural': 'Attachment',
},
),
migrations.AlterField(
model_name='paper',
name='file',
field=models.OneToOneField(default=None, on_delete=django.db.models.deletion.CASCADE, to='app01.Myfile'),
preserve_default=False,
),
]
21 changes: 21 additions & 0 deletions app01/migrations/0012_auto_20200814_2219.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 2.2 on 2020-08-14 14:19

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('app01', '0011_auto_20200814_2208'),
]

operations = [
migrations.AlterField(
model_name='paper',
name='file',
field=models.FileField(blank=True, default=None, null=True, upload_to='paper', verbose_name='Attachment'),
),
migrations.DeleteModel(
name='Myfile',
),
]
27 changes: 27 additions & 0 deletions app01/migrations/0013_auto_20200815_0716.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 2.2 on 2020-08-14 23:16

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('app01', '0012_auto_20200814_2219'),
]

operations = [
migrations.CreateModel(
name='Myfile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('file', models.FileField(blank=True, default=None, null=True, upload_to='paper', verbose_name='Attachment')),
],
options={
'verbose_name_plural': 'Attachment',
},
),
migrations.RemoveField(
model_name='paper',
name='file',
),
]
20 changes: 20 additions & 0 deletions app01/migrations/0014_paper_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 2.2 on 2020-08-14 23:18

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('app01', '0013_auto_20200815_0716'),
]

operations = [
migrations.AddField(
model_name='paper',
name='file',
field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, to='app01.Myfile'),
preserve_default=False,
),
]
24 changes: 24 additions & 0 deletions app01/migrations/0015_auto_20200815_0723.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 2.2 on 2020-08-14 23:23

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('app01', '0014_paper_file'),
]

operations = [
migrations.AlterField(
model_name='myfile',
name='file',
field=models.FileField(default=None, null=True, unique=True, upload_to='paper', verbose_name='Attachment'),
),
migrations.AlterField(
model_name='paper',
name='file',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='app01.Myfile', to_field='file'),
),
]
21 changes: 21 additions & 0 deletions app01/migrations/0016_auto_20200815_0735.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 2.2 on 2020-08-14 23:35

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('app01', '0015_auto_20200815_0723'),
]

operations = [
migrations.AlterField(
model_name='paper',
name='file',
field=models.FileField(blank=True, default=None, null=True, upload_to='', verbose_name='Attachment'),
),
migrations.DeleteModel(
name='Myfile',
),
]
18 changes: 18 additions & 0 deletions app01/migrations/0017_paper__file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2 on 2020-08-14 23:48

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('app01', '0016_auto_20200815_0735'),
]

operations = [
migrations.AddField(
model_name='paper',
name='_file',
field=models.CharField(blank=True, max_length=200),
),
]
23 changes: 23 additions & 0 deletions app01/migrations/0018_auto_20200815_0914.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 2.2 on 2020-08-15 01:14

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('app01', '0017_paper__file'),
]

operations = [
migrations.AddField(
model_name='project',
name='_file',
field=models.CharField(blank=True, max_length=200),
),
migrations.AddField(
model_name='summary',
name='_file',
field=models.CharField(blank=True, max_length=200),
),
]
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.
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.
Binary file not shown.
Binary file not shown.
7 changes: 6 additions & 1 deletion app01/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class Meta:
def __str__(self):
return "Task Comment: "+"{}".format(self._id)



class Research(models.Model):
_id = models.AutoField(primary_key=True, verbose_name="ID")
name = models.CharField(max_length=150, verbose_name="Name")
Expand Down Expand Up @@ -71,7 +73,8 @@ class Paper(models.Model):
_id = models.AutoField(primary_key=True, verbose_name="ID", default=None)
name = models.CharField(verbose_name="Name",max_length=100,unique=True, default=None)
typ = models.ForeignKey(verbose_name="Type", to="Research",on_delete=models.CASCADE, default=None)
file = models.FileField(verbose_name="Attachment", default=None,null=True, blank=True,upload_to='paper')
file = models.FileField(verbose_name="Attachment", default=None,null=True, blank=True)
_file = models.CharField(max_length=200, blank=True)
contribution = models.TextField(verbose_name="Contribution",null=True, blank=True)
motivation = models.TextField(verbose_name="Motivation",null=True, blank=True)
method = models.TextField(verbose_name="Method", null=True, blank=True)
Expand All @@ -87,6 +90,7 @@ class Project(models.Model):
name = models.CharField(verbose_name="Name", max_length=100,unique=True, default=None)
typ = models.ForeignKey(verbose_name="Type", to="Research",on_delete=models.CASCADE, default=None)
file = models.FileField(verbose_name="Attachment", default=None,null=True, blank=True)
_file = models.CharField(max_length=200, blank=True)
motivation = models.TextField(verbose_name="Motivation",null=True, blank=True)
method = models.TextField(verbose_name="Method", null=True, blank=True)
description = MDTextField(verbose_name="Description",null=True, blank=True)
Expand Down Expand Up @@ -128,6 +132,7 @@ class Summary(models.Model):
typ = models.CharField(verbose_name="Type", max_length=100, choices=summ_choice, default=None)
proposed = models.DateTimeField('Create Time', default=timezone.now)
file = models.FileField(verbose_name="Attachment", default=None, blank=True)
_file = models.CharField(max_length=200, blank=True)
background = models.TextField(verbose_name="Background",null=True, blank=True)
contribution = models.TextField(verbose_name="Contribution",null=True, blank=True)
motivation = models.TextField(verbose_name="Motivation",null=True, blank=True)
Expand Down
Binary file modified db.sqlite3
Binary file not shown.
17 changes: 15 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,29 @@
为研究人员提供一个管理科研工作的平台。可以用markdown语法写summary。考虑到研究工作者基本都是用英文,因此这个平台也用英语写的。
![研究管理系统](./Capture.PNG)

## 启动
## 调试模式启动

平台用django写,单人使用debug模式就足够了。在根目录下打开命令行窗口。注意要把settings.py中的DEBUG变量改成True。

平台用django写,单人使用debug模式就足够了。在根目录下打开命令行窗口。
~~~bash
pip install -r requirements.txt # 安装必要的包
python manage.py runserver 8000 # 启动服务器和sqllite数据库
~~~

然后打开浏览器,访问 http://127.0.0.1:8000/admin 就可以看到界面了。初始账户和密码均为admin。

## 部署到云服务器上

通过uwsgi连接nginx。注意要把settings.py中的DEBUG变量改成False。

~~~bash
pip install https://github.com/changkaiyan/django-suit.git
pip install -r requirements.txt
pip install uwsgi
uwsgi --ini uwsgi.ini # 此步之前请更改uwsgi.ini文件
nginx # 此步之前请更改/etc/nginx/nginx.conf文件建立连接
~~~

## 数据形式

每个paper和每个project都必须属于一个research,每个task也都属于research,因此要先建立research再添加其他操作。
Expand Down
Binary file modified sitep/__pycache__/settings.cpython-38.pyc
Binary file not shown.
Binary file modified sitep/__pycache__/urls.cpython-38.pyc
Binary file not shown.
4 changes: 3 additions & 1 deletion sitep/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,6 @@

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

MEDIA_URL = '/media/'
MEDIA_URL = '/media/'

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
Loading

0 comments on commit 9b4f1d2

Please sign in to comment.