Now store track file mimetype in database

This commit is contained in:
Eliot Berriot 2018-02-18 23:46:15 +01:00
parent 937c55fdd5
commit ddea5f1825
No known key found for this signature in database
GPG key ID: DD6965E2476E5C27
6 changed files with 99 additions and 1 deletions

View file

@ -1,7 +1,9 @@
import magic
import re
from django.db.models import Q
def normalize_query(query_string,
findterms=re.compile(r'"([^"]+)"|(\S+)').findall,
normspace=re.compile(r'\s{2,}').sub):
@ -15,6 +17,7 @@ def normalize_query(query_string,
'''
return [normspace(' ', (t[0] or t[1]).strip()) for t in findterms(query_string)]
def get_query(query_string, search_fields):
''' Returns a query, that is a combination of Q objects. That combination
aims to search keywords within a model by testing the given search fields.
@ -35,3 +38,8 @@ def get_query(query_string, search_fields):
else:
query = query & or_query
return query
def guess_mimetype(f):
b = min(100000, f.size)
return magic.from_buffer(f.read(b), mime=True)