mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 03:19:16 +02:00
Now store track file mimetype in database
This commit is contained in:
parent
937c55fdd5
commit
ddea5f1825
6 changed files with 99 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue