Skip to content

Commit

Permalink
1.管理端-设备,新增所属用户字段,只有超级用户可以修改该字段。该字段是管理端的注册用户。
Browse files Browse the repository at this point in the history
2.管理端-设备,超级用户可以查看所有设备,普通用户只能查看属于自己的设备
3.init.py脚本可选是否删除旧数据库,可选是否创建超级用户
  • Loading branch information
lim1942 committed Apr 4, 2024
1 parent 9f53f58 commit 47b99fb
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 11 deletions.
17 changes: 15 additions & 2 deletions general/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,27 @@ class MobileAdmin(ExportActionMixin, admin.ModelAdmin):
form = forms.MobileForm
show_full_result_count = True
search_fields = ['name']
list_filter = ['device_type', 'updated_time', 'created_time']
list_display = ['device_id', 'device_name', 'device_type', 'recorder', 'online', 'screen', 'filemanager', 'updated_time', 'created_time']
list_filter = ['device_type', 'user', 'updated_time', 'created_time']
list_display = ['device_id', 'device_name', 'user', 'device_type', 'recorder', 'online', 'screen', 'filemanager', 'updated_time', 'created_time']
actions = ['connect', 'disconnect', 'tcpip5555']

def connect(self, request, queryset):
for obj in queryset:
adb.AdbDevice.connect(obj.device_id)

def get_fields(self, request, obj=None):
fields = super().get_fields(request, obj)
if not request.user.is_superuser and 'user' in fields:
fields.remove('user')
return fields

def get_queryset(self, request):
queryset = super().get_queryset(request)
if request.user.is_superuser:
return queryset
else:
return queryset.filter(user=request.user)

def disconnect(self, request, queryset):
for obj in queryset:
adb.AdbDevice.disconnect(obj.device_id)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 4.2.4 on 2024-04-04 12:31

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


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('general', '0006_auto_20230519_2004'),
]

operations = [
migrations.AlterModelOptions(
name='mobile',
options={'ordering': ('-updated_time',), 'verbose_name': '手机', 'verbose_name_plural': '手机'},
),
migrations.AddField(
model_name='mobile',
name='user',
field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='所属用户'),
),
migrations.AlterField(
model_name='mobile',
name='config',
field=models.TextField(default='{"recorder_enable": false, "recorder_format": "mp4", "audio": true, "video_codec": "h264", "audio_codec": "aac", "audio_source": "output", "max_size": 720, "video_bit_rate": 800000, "audio_bit_rate": 128000, "max_fps": 25, "tunnel_forward": true, "crop": "", "control": true, "show_touches": false, "stay_awake": true, "video_codec_options": "profile=1,level=2", "audio_codec_options": "", "video_encoder": "", "audio_encoder": "", "power_off_on_close": false, "clipboard_autosync": false, "power_on": true}', help_text='配置视频分辨率,帧率等', verbose_name='配置详情'),
),
migrations.AlterField(
model_name='video',
name='config',
field=models.TextField(default='{"recorder_enable": false, "recorder_format": "mp4", "audio": true, "video_codec": "h264", "audio_codec": "aac", "audio_source": "output", "max_size": 720, "video_bit_rate": 800000, "audio_bit_rate": 128000, "max_fps": 25, "tunnel_forward": true, "crop": "", "control": true, "show_touches": false, "stay_awake": true, "video_codec_options": "profile=1,level=2", "audio_codec_options": "", "video_encoder": "", "audio_encoder": "", "power_off_on_close": false, "clipboard_autosync": false, "power_on": true}', help_text='配置视频分辨率,帧率等', verbose_name='配置详情'),
),
]
3 changes: 2 additions & 1 deletion general/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
import json

from django.contrib.auth.models import User
from django.db import models


Expand Down Expand Up @@ -135,6 +135,7 @@


class Mobile(models.Model):
user = models.ForeignKey(User, verbose_name='所属用户', on_delete=models.CASCADE, default=None, null=True, blank=True)
device_id = models.CharField("device_id", max_length=127, unique=True, null=False, blank=False)
device_name = models.CharField('设备名', max_length=32, blank=True, null=False)
device_type = models.CharField('设备类型', max_length=32, blank=True, null=False)
Expand Down
30 changes: 22 additions & 8 deletions init.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
"""Django's command-line utility for administrative tasks."""
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_scrcpy.settings')
try:
os.remove('db.sqlite3')
except Exception as e:
pass

# 1.清空数据库
if input("(1).是否清除旧数据库:1是,0否 ___ ") == '1':
try:
os.remove('db.sqlite3')
print("成功清除旧数据库信息")
except Exception as e:
pass
print()
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand All @@ -14,9 +19,18 @@
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc

# 2.更新数据库结构和静态文件
print("(2).更新数据库结构和静态文件")
execute_from_command_line(['manage.py', 'migrate'])
execute_from_command_line(['manage.py', 'collectstatic', '--noinput'])
print('\n==================================================')
print('Please create a super user !!!')
print('==================================================')
execute_from_command_line(['manage.py', 'createsuperuser'])
print("更新成功")
print()

# 3.创建超级用户
if input("(3).是否创建超级用户:1是,0否 ___ ") == '1':
print('\n==================================================')
print('Please create a super user !!!')
print('==================================================')
execute_from_command_line(['manage.py', 'createsuperuser'])
print("创建成功")

0 comments on commit 47b99fb

Please sign in to comment.