Free and open source ticket system written in python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

๐Ÿ‘Œ IMPROVE: Add python-magic library for file type identification

+45 -1
+12 -1
poetry.lock
··· 348 348 pyasn1 = ">=0.4.6,<0.6.0" 349 349 350 350 [[package]] 351 + name = "python-magic" 352 + version = "0.4.27" 353 + description = "File type identification using libmagic" 354 + optional = false 355 + python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" 356 + files = [ 357 + {file = "python-magic-0.4.27.tar.gz", hash = "sha256:c1ba14b08e4a5f5c31a302b7721239695b2f0f058d125bd5ce1ee36b9d9d3c3b"}, 358 + {file = "python_magic-0.4.27-py2.py3-none-any.whl", hash = "sha256:c212960ad306f700aa0d01e5d7a325d20548ff97eb9920dcd29513174f0294d3"}, 359 + ] 360 + 361 + [[package]] 351 362 name = "requests" 352 363 version = "2.31.0" 353 364 description = "Python HTTP for Humans." ··· 447 458 [metadata] 448 459 lock-version = "2.0" 449 460 python-versions = "^3.12" 450 - content-hash = "1e0820737369c3e1204a95a07ea47b332c4d30daadc349c61dba044b8e49ffb7" 461 + content-hash = "dba3b68991a716b8497c05f3b71bb7424d9ff208c18516ac6ac53319c9a43fcb"
+1
pyproject.toml
··· 12 12 django-colorfield = "^0.11.0" 13 13 google-auth = "^2.28.2" 14 14 google-auth-oauthlib = "^1.2.0" 15 + python-magic = "^0.4.27" 15 16 16 17 17 18 [build-system]
+32
ticketing/forms.py
··· 1 1 from django import forms 2 2 from .models import Ticket, Template, Team, Category 3 3 from django.utils.translation import gettext_lazy as _ 4 + import magic 4 5 5 6 6 7 class MultipleFileInput(forms.ClearableFileInput): ··· 27 28 attrs={'class': 'textarea textarea-bordered h-32', 'placeholder': 'Enter your comment here...'})) 28 29 hidden_from_client = forms.BooleanField(widget=forms.CheckboxInput( 29 30 attrs={'class': 'toggle toggle-error'}), required=False) 31 + 32 + 33 + ATTACHMENT_CONTENT_TYPES = [ 34 + 'image/jpeg', 35 + 'image/png', 36 + 'application/pdf' 37 + ] 30 38 31 39 32 40 class TicketForm(forms.ModelForm): ··· 48 56 status=Ticket.Status.CLOSED, user=user) 49 57 50 58 attachments = MultipleFileField(required=False) 59 + 60 + def clean_attachments(self): 61 + files = self.cleaned_data.get('attachments') 62 + if files: 63 + for file in files: 64 + # Check file size 65 + if file.size > 1024 * 1024 * 5: 66 + raise forms.ValidationError( 67 + _('File size must be under 5MB.')) 68 + 69 + # Check file type 70 + uploaded_content_type = file.content_type 71 + mg = magic.Magic(mime=True) 72 + content_type = mg.from_buffer(file.read(1024)) 73 + file.seek(0) 74 + 75 + if content_type != uploaded_content_type: 76 + uploaded_content_type = content_type 77 + 78 + if uploaded_content_type not in ATTACHMENT_CONTENT_TYPES: 79 + raise forms.ValidationError( 80 + _('File type not supported. Supported types are: .jpg, .png, .pdf')) 81 + 82 + return files 51 83 52 84 53 85 class TemplateForm(forms.Form):