-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_new_user.py
58 lines (50 loc) · 2.11 KB
/
add_new_user.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import os
import shutil
from add_all_contents import add_all_contents
from django_filemanager.models import Folder, FileManager
from kernel.models import Person
from omniport.settings.base.directories import (
PARENT_DIR
)
def add_new_user(person_unique_key, person_unique_value, filemanager_name, root_folder_location):
filters = {
person_unique_key: person_unique_value
}
try:
person = Person.objects.get(**filters)
except Person.DoesNotExist:
print("person with following credentials doesnot exists")
return
filemanager = FileManager.objects.get(filemanager_name=filemanager_name)
try:
folder = Folder.objects.get(
person=person, root=None, parent=None, filemanager=filemanager)
except Folder.DoesNotExist:
code = compile(
filemanager.filemanager_access_permissions, '<bool>', 'eval')
filemanager_access_permission = eval(code)
if not filemanager_access_permission:
print("user does not have permission to this filmanager")
return
else:
unique_name = eval(filemanager.folder_name_template)
folder = Folder(filemanager=filemanager,
folder_name=unique_name,
person=person,
max_space=filemanager.max_space,
starred=False,
root=None,
parent=None,
)
folder.path = folder.get_path()
folder.save()
path = os.path.join(PARENT_DIR, root_folder_location)
add_all_contents(path, person, folder, folder, filemanager)
person_unique_key = input(
"enter unique key for the person model(eg: full_name): ")
person_unique_value = input("enter value for the correnponding value: ")
filemanager_name = input("enter filemanager name you want to add the person: ")
root_folder_location = input(
"enter parent folder location relative to the PARENT_DIR: ")
add_new_user(person_unique_key, person_unique_value,
filemanager_name, root_folder_location)