Skip to content

Commit

Permalink
Merge pull request #113 from SADiLaR/admin-refinements
Browse files Browse the repository at this point in the history
Admin refinements
  • Loading branch information
friedelwolff authored Aug 17, 2024
2 parents 2148b4d + 7f7ec5e commit 14dcec0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
11 changes: 6 additions & 5 deletions app/general/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import magic
from django.contrib import admin
from django.forms import HiddenInput, ModelForm
from django.utils.translation import gettext as _
from simple_history.admin import SimpleHistoryAdmin

from general.service.extract_text import GetTextError, GetTextFromPDF
Expand Down Expand Up @@ -32,29 +33,29 @@ def clean(self):
if uploaded_file:
file_type = magic.from_buffer(uploaded_file.read(), mime=True)
if file_type != "application/pdf":
self.add_error("uploaded_file", "Only PDF files are allowed.")
self.add_error("uploaded_file", _("Only PDF files are allowed."))

try:
# Extract text from PDF file
cleaned_data["document_data"] = GetTextFromPDF(uploaded_file).to_text()

except GetTextError:
return self.add_error(
"uploaded_file", "The uploaded PDF file is corrupted or not fully downloaded."
"uploaded_file", _("The uploaded file is corrupted or not fully downloaded.")
)

cleaned_data["mime_type"] = file_type

uploaded_file.seek(0) # Reset file pointer after read

if not url and not uploaded_file:
self.add_error("url", "Either URL or uploaded file must be provided.")
self.add_error("uploaded_file", "Either URL or uploaded file must be provided.")
self.add_error("url", _("Either URL or uploaded file must be provided."))
self.add_error("uploaded_file", _("Either URL or uploaded file must be provided."))

if uploaded_file:
limit = 10 * 1024 * 1024
if uploaded_file.size and uploaded_file.size > limit:
self.add_error("uploaded_file", "File size must not exceed 10MB.")
self.add_error("uploaded_file", _("File size must not exceed 10MB."))

return cleaned_data

Expand Down
7 changes: 3 additions & 4 deletions app/static/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,12 @@ a.section:link, a.section:visited {
}

.header-title {
margin: 10px;
margin: 10px 2px;
}

.main-logo {
margin-left: 1px;
width: auto;
height: 70px;
width: 140px;;
height: 73px;
}


Expand Down
21 changes: 14 additions & 7 deletions app/templates/admin/base_site.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
<!--
Django Admin template
extended from https://github.com/django/django/blob/main/django/contrib/admin/templates/admin/base.html
and https://github.com/django/django/blob/main/django/contrib/admin/templates/admin/base_site.html
-->

{% extends "admin/base.html" %}
{% comment %}
Django Admin template
extended from:
https://github.com/django/django/blob/stable/5.0.x/django/contrib/admin/templates/admin/base.html
and
https://github.com/django/django/blob/stable/5.0.x/django/contrib/admin/templates/admin/base_site.html

When upgrading Django, compare the changes in the above, to work out what
should be incorporated here, and update the links above that serve as the point
of comparison.
{% endcomment %}

{% load static %}
{% load i18n %}

{% block title %}{% if subtitle %}{{ subtitle }} | {% endif %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %}

{% block extrastyle %}
<link rel="stylesheet" href="{% static 'css/admin.css' %}">
<link rel="stylesheet" href="{% static 'css/dark_mode_override.css' %}">
<link rel="icon" href="{% static 'img/favicon.png' %}" sizes="32x32" />
{% endblock %}

{% block branding %}
<h1 class="header-title">
<a href="{% url 'home' %}">
<img src="{% static 'img/sadilar.png' %}" class="main-logo" alt=_("SADiLaR")>
<img src="{% static 'img/sadilar.png' %}" class="main-logo" alt="{% trans 'SADiLaR' %}">
</a>
</h1>
{% if user.is_anonymous %}
Expand Down

0 comments on commit 14dcec0

Please sign in to comment.