mirror of
https://github.com/lemeow125/DocManagerBackend.git
synced 2025-01-18 17:13:00 +08:00
Add in requested changes
This commit is contained in:
parent
d81319c8ec
commit
844113d44f
7 changed files with 54 additions and 25 deletions
|
@ -8,7 +8,8 @@ class IsStaff(BasePermission):
|
|||
|
||||
def has_permission(self, request, view):
|
||||
return bool(
|
||||
request.user and request.user.role in ("head", "admin", "planning", "staff")
|
||||
request.user and request.user.role in (
|
||||
"head", "admin", "planning", "staff")
|
||||
)
|
||||
|
||||
|
||||
|
@ -18,7 +19,7 @@ class IsPlanning(BasePermission):
|
|||
"""
|
||||
|
||||
def has_permission(self, request, view):
|
||||
return bool(request.user and request.user.role in ("head", "admin", "planning"))
|
||||
return bool(request.user and request.user.role == "planning")
|
||||
|
||||
|
||||
class IsHead(BasePermission):
|
||||
|
|
|
@ -6,7 +6,7 @@ from rest_framework.settings import api_settings
|
|||
|
||||
|
||||
class CustomUserSerializer(serializers.ModelSerializer):
|
||||
birthday = serializers.DateField(format="%m-%d-%Y")
|
||||
birthday = serializers.DateField(format="%Y-%m-%d")
|
||||
|
||||
class Meta:
|
||||
model = CustomUser
|
||||
|
|
|
@ -10,19 +10,48 @@ from .models import CustomUser
|
|||
def create_admin_user(sender, **kwargs):
|
||||
# Programatically creates the administrator account
|
||||
if sender.name == "accounts":
|
||||
ADMIN_USER = CustomUser.objects.filter(
|
||||
email=get_secret("ADMIN_EMAIL")).first()
|
||||
if not ADMIN_USER:
|
||||
ADMIN_USER = CustomUser.objects.create_superuser(
|
||||
username=get_secret("ADMIN_EMAIL"),
|
||||
email=get_secret("ADMIN_EMAIL"),
|
||||
password=get_secret("ADMIN_PASSWORD"),
|
||||
sex="male",
|
||||
birthday=localdate(now()),
|
||||
)
|
||||
users = [{
|
||||
"email": get_secret("ADMIN_EMAIL"),
|
||||
"role": "head",
|
||||
"admin": True,
|
||||
}, {
|
||||
"email": "staff@test.com",
|
||||
"role": "staff",
|
||||
"admin": False,
|
||||
}, {
|
||||
"email": "planning@test.com",
|
||||
"role": "planning",
|
||||
"admin": False,
|
||||
}, {
|
||||
"email": "client@test.com",
|
||||
"role": "client",
|
||||
"admin": False,
|
||||
},]
|
||||
for user in users:
|
||||
USER = CustomUser.objects.filter(
|
||||
email=user["email"]).first()
|
||||
if not USER:
|
||||
if user["admin"]:
|
||||
USER = CustomUser.objects.create_superuser(
|
||||
username=user["email"],
|
||||
email=user["email"],
|
||||
password=get_secret("ADMIN_PASSWORD"),
|
||||
sex="male",
|
||||
birthday=localdate(now()),
|
||||
role=user["role"]
|
||||
)
|
||||
else:
|
||||
USER = CustomUser.objects.create_user(
|
||||
username=user["email"],
|
||||
email=user["email"],
|
||||
password=get_secret("ADMIN_PASSWORD"),
|
||||
sex="male",
|
||||
birthday=localdate(now()),
|
||||
role=user["role"]
|
||||
|
||||
print("Created administrator account:", ADMIN_USER.email)
|
||||
)
|
||||
print(f"Created {user['role']} account: {USER.email}")
|
||||
|
||||
ADMIN_USER.first_name = "Administrator"
|
||||
ADMIN_USER.is_active = True
|
||||
ADMIN_USER.save()
|
||||
USER.first_name = f"DEBUG_USER:{USER.email}"
|
||||
USER.is_active = True
|
||||
USER.save()
|
||||
|
|
|
@ -124,7 +124,7 @@ class PDFHandler(FileSystemEventHandler):
|
|||
# A few safety checks if the model does not follow through with output instructions
|
||||
if len(document_type) > 16:
|
||||
self.logger.warning(
|
||||
f"Ollama API gave incorrect document category: {response["message"]["content"]}. Retrying...")
|
||||
f"Ollama API gave incorrect document category: {response['message']['content']}. Retrying...")
|
||||
break
|
||||
|
||||
# If that fails, just use regular OCR read the title as a dirty fix/fallback
|
||||
|
@ -146,7 +146,7 @@ class PDFHandler(FileSystemEventHandler):
|
|||
|
||||
# Open the file for instance creation
|
||||
DOCUMENT, created = Document.objects.get_or_create(
|
||||
name=filename,
|
||||
name=filename.replace(".pdf", ""),
|
||||
defaults={
|
||||
"number_pages": num_pages,
|
||||
"ocr_metadata": metadata,
|
||||
|
@ -158,8 +158,7 @@ class PDFHandler(FileSystemEventHandler):
|
|||
DOCUMENT.file.save(
|
||||
name=filename, content=File(open(file_path, "rb")))
|
||||
self.logger.info(
|
||||
f"Document '{filename}' created successfully with type '{
|
||||
document_type}'."
|
||||
f"Document '{filename}' created successfully with type '{document_type}'."
|
||||
)
|
||||
|
||||
else:
|
||||
|
|
|
@ -8,4 +8,4 @@ from .models import Document
|
|||
class DocumentAdmin(ModelAdmin):
|
||||
model = Document
|
||||
search_fields = ["id", "name", "document_type"]
|
||||
list_display = ["id", "name", "document_type"]
|
||||
list_display = ["id", "name", "document_type", "date_uploaded"]
|
||||
|
|
|
@ -51,7 +51,7 @@ class DocumentListView(generics.ListAPIView):
|
|||
|
||||
http_method_names = ["get"]
|
||||
serializer_class = DocumentSerializer
|
||||
queryset = Document.objects.all()
|
||||
queryset = Document.objects.all().order_by("-date_uploaded")
|
||||
pagination_class = PageNumberPagination
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
{% trans 'Please visit the site to check your request:' %}
|
||||
{{ url|safe }}
|
||||
|
||||
{% trans 'For hardcopy requests, please proceed to the USTP office to avail of your requested copies:' %}
|
||||
{% trans 'For hardcopy requests, please proceed to the USTP office to avail of your requested copies. Hardcopy requests are valid only within 1 month of requesting.' %}
|
||||
{% endblock %}
|
||||
|
||||
{% block html_body %}
|
||||
|
@ -27,6 +27,6 @@
|
|||
</p>
|
||||
|
||||
<p>
|
||||
{% trans 'For hardcopy requests, please proceed to the USTP office to avail of your requested copies:' %}
|
||||
{% trans 'For hardcopy requests, please proceed to the USTP office to avail of your requested copies. Hardcopy requests are valid only within 1 month of requesting.' %}
|
||||
</p>
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in a new issue