Esempio n. 1
1
 def ready(self):
     # Connections may already exist before we are called.
     for conn in connections.all():
         if conn.connection is not None:
             register_type_handlers(conn)
     connection_created.connect(register_type_handlers)
     CharField.register_lookup(Unaccent)
     TextField.register_lookup(Unaccent)
     CharField.register_lookup(SearchLookup)
     TextField.register_lookup(SearchLookup)
     CharField.register_lookup(TrigramSimilar)
     TextField.register_lookup(TrigramSimilar)
Esempio n. 2
0
 def ready(self):
     setting_changed.connect(uninstall_if_needed)
     # Connections may already exist before we are called.
     for conn in connections.all(initialized_only=True):
         if conn.vendor == "postgresql":
             conn.introspection.data_types_reverse.update({
                 3904:
                 "django.contrib.postgres.fields.IntegerRangeField",
                 3906:
                 "django.contrib.postgres.fields.DecimalRangeField",
                 3910:
                 "django.contrib.postgres.fields.DateTimeRangeField",
                 3912:
                 "django.contrib.postgres.fields.DateRangeField",
                 3926:
                 "django.contrib.postgres.fields.BigIntegerRangeField",
             })
             if conn.connection is not None:
                 register_type_handlers(conn)
     connection_created.connect(register_type_handlers)
     CharField.register_lookup(Unaccent)
     TextField.register_lookup(Unaccent)
     CharField.register_lookup(SearchLookup)
     TextField.register_lookup(SearchLookup)
     CharField.register_lookup(TrigramSimilar)
     TextField.register_lookup(TrigramSimilar)
     CharField.register_lookup(TrigramWordSimilar)
     TextField.register_lookup(TrigramWordSimilar)
     CharField.register_lookup(TrigramStrictWordSimilar)
     TextField.register_lookup(TrigramStrictWordSimilar)
     MigrationWriter.register_serializer(RANGE_TYPES, RangeSerializer)
     IndexExpression.register_wrappers(OrderBy, OpClass, Collate)
Esempio n. 3
0
    def ready(self):
        super().ready()
        register(check_data_writable)
        register(check_mail_connection, deploy=True)
        register(check_celery, deploy=True)
        register(check_database, deploy=True)
        register(check_cache, deploy=True)
        register(check_settings, deploy=True)
        register(check_templates, deploy=True)
        register(check_site, deploy=True)
        register(check_perms, deploy=True)
        register(check_errors, deploy=True)
        register(check_version)

        monkey_patch_translate()

        init_error_collection()

        engine = settings.DATABASES["default"]["ENGINE"]
        if engine == "django.db.backends.postgresql":
            CharField.register_lookup(SearchLookup)
            TextField.register_lookup(SearchLookup)
        elif engine == "django.db.backends.mysql":
            CharField.register_lookup(MySQLSearchLookup)
            TextField.register_lookup(MySQLSearchLookup)
        else:
            raise Exception("Unsupported database: {}".format(engine))
Esempio n. 4
0
    def ready(self):
        super().ready()
        register(check_data_writable)
        register(check_mail_connection, deploy=True)
        register(check_celery, deploy=True)
        register(check_cache, deploy=True)
        register(check_settings, deploy=True)
        register(check_templates, deploy=True)
        register(check_site, deploy=True)
        register(check_perms, deploy=True)
        register(check_errors, deploy=True)
        register(check_version)
        register(check_encoding)
        register(check_diskspace, deploy=True)

        init_error_collection()

        engine = settings.DATABASES["default"]["ENGINE"]
        if engine == "django.db.backends.postgresql":
            CharField.register_lookup(PostgreSQLSearchLookup)
            TextField.register_lookup(PostgreSQLSearchLookup)
            CharField.register_lookup(PostgreSQLSubstringLookup)
            TextField.register_lookup(PostgreSQLSubstringLookup)
        elif engine == "django.db.backends.mysql":
            CharField.register_lookup(MySQLSearchLookup)
            TextField.register_lookup(MySQLSearchLookup)
            CharField.register_lookup(MySQLSubstringLookup)
            TextField.register_lookup(MySQLSubstringLookup)
        else:
            raise Exception(f"Unsupported database: {engine}")
Esempio n. 5
0
    def ready(self):
        super().ready()
        register(check_data_writable)
        register(check_mail_connection, deploy=True)
        register(check_celery, deploy=True)
        register(check_cache, deploy=True)
        register(check_settings, deploy=True)
        register(check_templates, deploy=True)
        register(check_database, deploy=True)
        register(check_site)
        register(check_perms, deploy=True)
        register(check_errors, deploy=True)
        register(check_version, deploy=True)
        register(check_encoding)
        register(check_diskspace, deploy=True)

        init_error_collection()

        if using_postgresql():
            CharField.register_lookup(PostgreSQLSearchLookup)
            TextField.register_lookup(PostgreSQLSearchLookup)
            CharField.register_lookup(PostgreSQLSubstringLookup)
            TextField.register_lookup(PostgreSQLSubstringLookup)
        else:
            CharField.register_lookup(MySQLSearchLookup)
            TextField.register_lookup(MySQLSearchLookup)
            CharField.register_lookup(MySQLSubstringLookup)
            TextField.register_lookup(MySQLSubstringLookup)
Esempio n. 6
0
 def ready(self):
     setting_changed.connect(uninstall_if_needed)
     # Connections may already exist before we are called.
     for conn in connections.all():
         if conn.vendor == 'postgresql':
             conn.introspection.data_types_reverse.update({
                 3802:
                 'django.contrib.postgres.fields.JSONField',
                 3904:
                 'django.contrib.postgres.fields.IntegerRangeField',
                 3906:
                 'django.contrib.postgres.fields.DecimalRangeField',
                 3910:
                 'django.contrib.postgres.fields.DateTimeRangeField',
                 3912:
                 'django.contrib.postgres.fields.DateRangeField',
                 3926:
                 'django.contrib.postgres.fields.BigIntegerRangeField',
             })
             if conn.connection is not None:
                 register_type_handlers(conn)
     connection_created.connect(register_type_handlers)
     CharField.register_lookup(Unaccent)
     TextField.register_lookup(Unaccent)
     CharField.register_lookup(SearchLookup)
     TextField.register_lookup(SearchLookup)
     CharField.register_lookup(TrigramSimilar)
     TextField.register_lookup(TrigramSimilar)
     MigrationWriter.register_serializer(RANGE_TYPES, RangeSerializer)
Esempio n. 7
0
 def ready(self):
     # Connections may already exist before we are called.
     for conn in connections.all():
         if conn.vendor == 'postgresql':
             conn.introspection.data_types_reverse.update({
                 3802:
                 'django.contrib.postgresql.fields.JSONField',
                 3904:
                 'django.contrib.postgresql.fields.IntegerRangeField',
                 3906:
                 'django.contrib.postgresql.fields.FloatRangeField',
                 3910:
                 'django.contrib.postgresql.fields.DateTimeRangeField',
                 3912:
                 'django.contrib.postgresql.fields.DateRangeField',
                 3926:
                 'django.contrib.postgresql.fields.BigIntegerRangeField',
             })
             if conn.connection is not None:
                 register_type_handlers(conn)
     connection_created.connect(register_type_handlers)
     CharField.register_lookup(Unaccent)
     TextField.register_lookup(Unaccent)
     CharField.register_lookup(SearchLookup)
     TextField.register_lookup(SearchLookup)
     CharField.register_lookup(TrigramSimilar)
     TextField.register_lookup(TrigramSimilar)
Esempio n. 8
0
 def ready(self):
     connection_created.connect(register_hstore_handler)
     CharField.register_lookup(Unaccent)
     TextField.register_lookup(Unaccent)
     CharField.register_lookup(SearchLookup)
     TextField.register_lookup(SearchLookup)
     CharField.register_lookup(TrigramSimilar)
     TextField.register_lookup(TrigramSimilar)
Esempio n. 9
0
class SearchView(View):
    CharField.register_lookup(Lower, "lower")
    TextField.register_lookup(Lower, "lower")
    template_name = 'news/search.html'

    def get(self, request, *args, **kwargs):
        search_query = request.GET.get('search', '')
        print(search_query.lower())

        founded_news = News.objects.filter(
            Q(title__lower__icontains=search_query)
            | Q(text__lower__icontains=search_query))
        context = {'founded_news': founded_news}
        return render(self.request, self.template_name, context)
Esempio n. 10
0
    def add_lookups(self):
        from django.db.models import CharField, TextField
        from django_mysql.models.lookups import CaseSensitiveExact, Soundex, SoundsLike

        CharField.register_lookup(CaseSensitiveExact)
        CharField.register_lookup(SoundsLike)
        CharField.register_lookup(Soundex)
        TextField.register_lookup(CaseSensitiveExact)
        TextField.register_lookup(SoundsLike)
        TextField.register_lookup(Soundex)
Esempio n. 11
0
    def add_lookups(self):
        from django.db.models import CharField, TextField
        from django_mysql.models.lookups import (
            CaseSensitiveExact, Soundex, SoundsLike
        )

        CharField.register_lookup(CaseSensitiveExact)
        CharField.register_lookup(SoundsLike)
        CharField.register_lookup(Soundex)
        TextField.register_lookup(CaseSensitiveExact)
        TextField.register_lookup(SoundsLike)
        TextField.register_lookup(Soundex)
Esempio n. 12
0
 def ready(self):
     # Connections may already exist before we are called.
     for conn in connections.all():
         if conn.connection is not None:
             register_hstore_handler(conn)
     connection_created.connect(register_hstore_handler)
     CharField.register_lookup(Unaccent)
     TextField.register_lookup(Unaccent)
     CharField.register_lookup(SearchLookup)
     TextField.register_lookup(SearchLookup)
     CharField.register_lookup(TrigramSimilar)
     TextField.register_lookup(TrigramSimilar)
Esempio n. 13
0
 def ready(self):
     # Connections may already exist before we are called.
     for conn in connections.all():
         if conn.vendor == 'postgresql':
             conn.introspection.data_types_reverse.update({
                 3802: 'django.contrib.postgres.fields.JSONField',
                 3904: 'django.contrib.postgres.fields.IntegerRangeField',
                 3906: 'django.contrib.postgres.fields.DecimalRangeField',
                 3910: 'django.contrib.postgres.fields.DateTimeRangeField',
                 3912: 'django.contrib.postgres.fields.DateRangeField',
                 3926: 'django.contrib.postgres.fields.BigIntegerRangeField',
             })
             if conn.connection is not None:
                 register_type_handlers(conn)
     connection_created.connect(register_type_handlers)
     CharField.register_lookup(Unaccent)
     TextField.register_lookup(Unaccent)
     CharField.register_lookup(SearchLookup)
     TextField.register_lookup(SearchLookup)
     CharField.register_lookup(TrigramSimilar)
     TextField.register_lookup(TrigramSimilar)
Esempio n. 14
0
from django.contrib.postgres.search import TrigramSimilarity, SearchVector, SearchQuery, SearchRank
from django.db.models.functions import Greatest
from django.db.models import CharField, TextField, Transform, Q


class UpperCase(Transform):
    lookup_name = 'upper'
    function = 'UPPER'
    bilateral = True


CharField.register_lookup(UpperCase)
TextField.register_lookup(UpperCase)


def trigram_order(query_string, search_fields, queryset):
    trigram = [
        TrigramSimilarity(field_name, query_string)
        for field_name in search_fields
    ]
    if len(trigram) > 1:
        trigram[0] = Greatest(*trigram)
    return queryset.annotate(
        similarity=trigram[0]).order_by('-similarity').distinct()


def trigram_filter(query_string, search_fields, queryset, threshold,
                   max_results):
    trigram = []
    or_query = None  # Query to search for a given term in each field
    for field_name in search_fields:
Esempio n. 15
0
from django.utils.translation import ugettext_lazy as _

from . import models


class TrigramStrictWordSimilarity(TrigramSimilarity):
    function = "STRICT_WORD_SIMILARITY"


class TrigramStrictWordSimilar(PostgresOperatorLookup):
    lookup_name = "trigram_strict_word_similar"
    postgres_operator = "<<%%"


CharField.register_lookup(TrigramStrictWordSimilar)
TextField.register_lookup(TrigramStrictWordSimilar)


@dataclasses.dataclass
class PartialDate:
    day: int
    month: int


class MatchType(enum.Enum):
    AUTHOR = "author"
    PROPERTY = "property"
    CREATED_AT = "created_at"
    ACTOR = "actor"
    TIME = "time"
Esempio n. 16
0
from django.db import models
from django.db.models import Field, Lookup, Transform, CharField, TextField
from django.utils.translation import gettext_lazy as _
from django.db import connection

from common.util.regex_matching import text_to_seq_pattern
import re


class LowerCase(Transform):
    lookup_name = 'lower'
    function = 'LOWER'
    bilateral = True


TextField.register_lookup(LowerCase)
CharField.register_lookup(LowerCase)


@Field.register_lookup
class MatchInSensitiveCommonSequence(Lookup):
    lookup_name = 'matchseq'

    def as_sql(self, compiler, connection):
        lhs, lhs_params = self.process_lhs(compiler=compiler,
                                           connection=connection)
        rhs, rhs_params = self.process_rhs(compiler=compiler,
                                           connection=connection)

        # Replace SPACE character with '%' for the RHS params
        rhs_params[0] = '{}{}{}'.format('%', rhs_params[0].replace(' ', '%'),
Esempio n. 17
0
 def ready(self):
     if "sqlite3" in settings.DATABASES["default"][
             "ENGINE"]:  # pragma: no cover
         TextField.register_lookup(IContains, lookup_name="search")
Esempio n. 18
0
#************************************************

from django.db.models import Transform, Field

class UpperCase(Transform):
    lookup_name = 'upper'
    bilateral = True

    def as_sql(self, compiler, connection):
        lhs, params = compiler.compile(self.lhs)
        return "UPPER(%s)" % lhs, params

from django.db.models import CharField, TextField
CharField.register_lookup(UpperCase)
TextField.register_lookup(UpperCase)


class AbsoluteValue(Transform):
    lookup_name = 'abs'

    def as_sql(self, compiler, connection):
        lhs, params = compiler.compile(self.lhs)
        return "ABS(%s)" % lhs, params

    @property
    def output_field(self):
        return FloatField()

#*****************************8
Esempio n. 19
0
from django.apps import AppConfig
Esempio n. 20
0
 def ready(self):
     # Force la surcharge du lookup "unaccent" sur les champs texte
     from django.db.models import CharField, TextField
     from common.fields import CustomUnaccent
     CharField.register_lookup(CustomUnaccent)
     TextField.register_lookup(CustomUnaccent)
Esempio n. 21
0
class QueryFunctions:
    """
    Built-in query functions of the Sensor Things API. Most function
    definitions act as a wrapper for django's ORM.
    """
    CharField.register_lookup(Length)
    CharField.register_lookup(Lower)
    CharField.register_lookup(Upper)
    TextField.register_lookup(Length)
    TextField.register_lookup(Lower)
    TextField.register_lookup(Upper)

    def substringof(parameterstring, **kwargs):
        """
        Returns the queryset based on a case-sensitive containment test.
        """
        django_function = '__contains'
        parsedlist = parameterstring.split(',')
        # need to do some validation: only accept two arguments!
        string_index = [
            i for i, s in enumerate(parsedlist) if s[0] == "'" and s[-1] == "'"
        ]
        field_index = [
            i for i, s in enumerate(parsedlist) if s[0] != "'" or s[-1] != "'"
        ]

        string = parsedlist[string_index[0]]
        field = parsedlist[field_index[0]]

        if field == 'result':
            field = 'result__result'

        if string[0] == "'" and string[-1] == "'":
            string = string[1:-1]
        elif string[0] == '"' and string[-1] == '"':
            string = string[1:-1]
            # REALLY I SHOULD RAISE AN ERROR HERE
        d = dict()
        d["query"] = Q(**{field + django_function: string})
        return d

    def endswith(parameterstring, **kwargs):
        """
        Returns the queryset for entries that are True for case-sensitive
        ends-with.
        """
        django_function = '__endswith'
        parsedlist = parameterstring.split(',')
        field = parsedlist[0]
        if field == 'result':
            field = 'result__result'
        string = parsedlist[1]
        if string[0] == "'" and string[-1] == "'":
            string = string[1:-1]
        elif string[0] == '"' and string[-1] == '"':
            string = string[1:-1]
        d = dict()
        d["query"] = Q(**{field + django_function: string})
        return d

    def startswith(parameterstring, **kwargs):
        """
        Returns the queryset for entries that are True for case-sensitive
        starts-with.
        """
        django_function = '__startswith'
        parsedlist = parameterstring.split(',')
        field = parsedlist[0]
        if field == 'result':
            field = 'result__result'
        string = parsedlist[1]
        if string[0] == "'" and string[-1] == "'":
            string = string[1:-1]
        elif string[0] == '"' and string[-1] == '"':
            string = string[1:-1]
        d = dict()
        d["query"] = Q(**{field + django_function: string})
        return d

    def length(parameterstring, **kwargs):
        """
        Wraps the query with the PostgreSQL Length function and
        registers as a transform.
        """
        django_function = '__length'
        field = parameterstring
        if field == 'result':
            field = 'result__result'
        d = dict()
        d['query_field'] = field + django_function
        return d

    def tolower(parameterstring, **kwargs):
        """
        Wraps the query with the PostgreSQL Lower function and
        registers as a transform.
        """
        django_function = '__lower'
        field = parameterstring
        if field == 'result':
            field = 'result__result'
        d = dict()
        d['query_field'] = field + django_function
        return d

    def toupper(parameterstring, **kwargs):
        """
        Wraps the query with the PostgreSQL Upper function and
        registers as a transform.
        """
        django_function = '__upper'
        field = parameterstring
        if field == 'result':
            field = 'result__result'
        d = dict()
        d['query_field'] = field + django_function
        return d

    def year(parameterstring, **kwargs):
        django_function = '__year'
        field = parameterstring
        if field == 'result':
            field = 'result__result'
        d = {}
        d['query_field'] = field + django_function
        return d

    def month(parameterstring, **kwargs):
        django_function = '__month'
        field = parameterstring
        if field == 'result':
            field = 'result__result'
        d = dict()
        d['query_field'] = field + django_function
        return d

    def day(parameterstring, **kwargs):
        django_function = '__day'
        field = parameterstring
        if field == 'result':
            field = 'result__result'
        d = dict()
        d['query_field'] = field + django_function
        return d

    def hour(parameterstring, **kwargs):
        django_function = '__hour'
        field = parameterstring
        if field == 'result':
            field = 'result__result'
        d = dict()
        d['query_field'] = field + django_function
        return d

    def minute(parameterstring, **kwargs):
        django_function = '__minute'
        field = parameterstring
        if field == 'result':
            field = 'result__result'
        d = dict()
        d['query_field'] = field + django_function
        return d

    def second(parameterstring, **kwargs):
        django_function = '__second'
        field = parameterstring
        if field == 'result':
            field = 'result__result'
        d = dict()
        d['query_field'] = field + django_function
        return d

    def millisecond(parameterstring, **kwargs):
        d = dict()
        django_function = CustomFunctions.FractionalSecond
        field = parameterstring
        temporary_field = "temp" + str(kwargs['index'])
        d['query_field'] = temporary_field
        d['annotation'] = {temporary_field: django_function(field)}
        return d

    def offsetminutes(parameterstring, **kwargs):
        d = dict()
        django_function = CustomFunctions.ExtractMinutes
        field = parameterstring
        temporary_field = "temp" + str(kwargs['index'])
        d['query_field'] = temporary_field
        d['annotation'] = {temporary_field: django_function(field)}
        return d

    def date(parameterstring, **kwargs):
        django_function = '__date'
        field = parameterstring
        if field == 'result':
            field = 'result__result'
        d = dict()
        d['query_field'] = field + django_function
        return d

    def time(parameterstring, **kwargs):
        # TODO: this only looks up aware times in a query if the django settings timezone matches the query one.
        django_function = '__time'
        field = parameterstring
        if field == 'result':
            field = 'result__result'
        d = dict()
        d['query_field'] = field + django_function
        return d

    def round(parameterstring, **kwargs):
        d = dict()
        django_function = CustomFunctions.Round
        field = parameterstring
        temporary_field = "temp" + str(kwargs['index'])
        d['query_field'] = temporary_field
        d['annotation'] = {temporary_field: django_function(field)}
        return d

    def floor(parameterstring, **kwargs):
        d = dict()
        django_function = CustomFunctions.Floor
        field = parameterstring
        temporary_field = "temp" + str(kwargs['index'])
        d['query_field'] = temporary_field
        d['annotation'] = {temporary_field: django_function(field)}
        return d

    def ceiling(parameterstring, **kwargs):
        d = dict()
        django_function = CustomFunctions.Ceiling
        field = parameterstring
        temporary_field = "temp" + str(kwargs['index'])
        d['query_field'] = temporary_field
        d['annotation'] = {temporary_field: django_function(field)}
        return d

    def geo_distance(parameterstring, **kwargs):
        d = dict()
        django_function = CustomFunctions.ST_Distance
        parsedlist = parameterstring.split(',')
        # this is not very good ... easy to break
        point_index = [i for i, s in enumerate(parsedlist) if "POINT" in s]
        field_index = [
            i for i, s in enumerate(parsedlist) if s[0] != "'" or s[-1] != "'"
        ]

        string = parsedlist[point_index[0]]
        try:
            string = string.split("'")[1]
        except:
            pass

        field = parsedlist[field_index[0]]

        temporary_field = "temp" + str(kwargs['index'])
        d['query_field'] = temporary_field
        d['annotation'] = {
            temporary_field: django_function(field, Value(string))
        }
        return d

    def geo_length(parameterstring, **kwargs):
        d = dict()
        django_function = CustomFunctions.ST_Length
        field = parameterstring
        temporary_field = "temp" + str(kwargs['index'])
        d['query_field'] = temporary_field
        d['annotation'] = {temporary_field: django_function(field)}
        return d

    def st_equals(parameterstring, **kwargs):
        django_function = '__equals'
        field = parameterstring.split(',')[0]
        geometry = parameterstring.split("'")[1]
        if field == 'result':
            field = 'result__result'
        d = dict()
        d['query'] = Q(**{field + django_function: geometry})
        return d

    def st_within(parameterstring, **kwargs):
        django_function = '__within'
        field = parameterstring.split(',')[0]
        geometry = parameterstring.split("'")[1]
        if field == 'result':
            field = 'result__result'
        d = dict()
        d['query'] = Q(**{field + django_function: geometry})
        return d

    def st_disjoint(parameterstring, **kwargs):
        django_function = '__disjoint'
        field = parameterstring.split(',')[0]
        geometry = parameterstring.split("'")[1]
        if field == 'result':
            field = 'result__result'
        d = dict()
        d['query'] = Q(**{field + django_function: geometry})
        return d

    def st_touches(parameterstring, **kwargs):
        django_function = '__touches'
        field = parameterstring.split(',')[0]
        geometry = parameterstring.split("'")[1]
        if field == 'result':
            field = 'result__result'
        d = dict()
        d['query'] = Q(**{field + django_function: geometry})
        return d

    def st_overlaps(parameterstring, **kwargs):
        django_function = '__overlaps'
        field = parameterstring.split(',')[0]
        geometry = parameterstring.split("'")[1]
        if field == 'result':
            field = 'result__result'
        d = dict()
        d['query'] = Q(**{field + django_function: geometry})
        return d

    def st_intersects(parameterstring, **kwargs):
        django_function = '__intersects'
        field = parameterstring.split(',')[0]
        geometry = parameterstring.split("'")[1]
        if field == 'result':
            field = 'result__result'
        d = dict()
        d['query'] = Q(**{field + django_function: geometry})
        return d

    def st_contains(parameterstring, **kwargs):
        django_function = '__contains'
        field = parameterstring.split(',')[0]
        geometry = parameterstring.split("'")[1]
        if field == 'result':
            field = 'result__result'
        d = dict()
        d['query'] = Q(**{field + django_function: geometry})
        return d

    def st_crosses(parameterstring, **kwargs):
        django_function = '__crosses'
        field = parameterstring.split(',')[0]
        geometry = parameterstring.split("'")[1]
        if field == 'result':
            field = 'result__result'
        d = dict()
        d['query'] = Q(**{field + django_function: geometry})
        return d

    def st_relate(parameterstring, **kwargs):
        django_function = '__relate'
        field = parameterstring.split(',')[0]
        geometry = parameterstring.split("'")[1]
        intersection = parameterstring.split(",")[-1]
        intersection = intersection.split("'")[1]
        if field == 'result':
            field = 'result__result'
        d = dict()
        d['query'] = Q(**{field + django_function: (geometry, intersection)})
        return d

    implemented = {
        "substringof": substringof,
        "endswith": endswith,
        "startswith": startswith,
        "length": length,
        "tolower": tolower,
        "toupper": toupper,
        "year": year,
        "month": month,
        "day": day,
        "hour": hour,
        "minute": minute,
        "second": second,
        "fractionalseconds": millisecond,
        "totaloffsetminutes": offsetminutes,
        "date": date,
        "time": time,
        "round": round,
        "floor": floor,
        "ceiling": ceiling,
        "geo.distance": geo_distance,
        "geo.length": geo_length,
        "geo.intersects": st_intersects,
        "st_equals": st_equals,
        "st_disjoint": st_disjoint,
        "st_touches": st_touches,
        "st_within": st_within,
        "st_crosses": st_crosses,
        "st_intersects": st_intersects,
        "st_contains": st_contains,
        "st_relate": st_relate,
        "st_overlaps": st_overlaps
    }
Esempio n. 22
0
 def ready(self):
     CharField.register_lookup(Unaccent)
     TextField.register_lookup(Unaccent)
Esempio n. 23
0
 def ready(self):
     connection_created.connect(register_hstore_handler)
     CharField.register_lookup(Unaccent)
     TextField.register_lookup(Unaccent)
Esempio n. 24
0
    def test_download_metadata(self):
        CharField.register_lookup(Length, 'length')
        TextField.register_lookup(Length, 'length')
        load_gin_config('backend/add_videos.gin')

        example_unlisted_video = 'dHFYikxUatY'
        example_correct_video = '9bZkp7q19f0'
        example_wrong_url_video = 'w$url'
        example_notfound_video = 'notfoundvid'
        test_videos = [
            example_unlisted_video, example_correct_video,
            example_wrong_url_video, example_notfound_video
        ]
        test_responses = [{
            'name__length__gt': 5,
            'is_unlisted': True,
            'description__length__gt': 1,
            'publication_date__isnull': False,
            'language__isnull': False,
            'views__isnull': False,
            'metadata_timestamp__isnull': False,
            'uploader__isnull': False,
            'duration__isnull': False,
            'last_download_time__isnull': False,
            'download_attempts__gt': 0,
            'add_time__isnull': False,
            'download_failed': False
        }, {
            'name__length__gt': 5,
            'is_unlisted': False,
            'views__isnull': False,
            'description__length__gt': 1,
            'publication_date__isnull': False,
            'uploader__isnull': False,
            'duration__isnull': False,
            'language__isnull': False,
            'metadata_timestamp__isnull': False,
            'wrong_url': False,
            'last_download_time__isnull': False,
            'download_attempts__gt': 0,
            'add_time__isnull': False,
            'download_failed': False
        }, {
            'name': "",
            'is_unlisted': False,
            'metadata_timestamp__isnull': True,
            'wrong_url': True,
            'last_download_time__isnull': False,
            'download_attempts__gt': 0,
            'add_time__isnull': False,
            'download_failed': True
        }, {
            'name': "",
            'is_unlisted': False,
            'metadata_timestamp__isnull': True,
            'wrong_url': False,
            'last_download_time__isnull': False,
            'download_attempts__gt': 0,
            'add_time__isnull': False,
            'download_failed': True
        }]

        for v, resp in zip(test_videos, test_responses):
            Video.objects.filter(video_id=v).delete()
            vm = VideoManager(only_download=[v])
            vm.fill_info()
            vm.add_videos_in_folder_to_db()
            qs = Video.objects.filter(video_id=v)
            assert qs.count() == 1

            # format: key, val
            errors = []
            for key, val in resp.items():
                sub_qs = qs.filter(**{key: val})
                if sub_qs.count() != 1:
                    errors.append((key, val))

            assert not errors, (v, resp, errors)

            o = qs.get()
            print(o)
Esempio n. 25
0
        'create_missing': True
    },
}

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
        'LOCATION': '/var/tmp/django_cache',
    }
}

from django.db.models import Q, CharField, TextField
from django.db.models.functions import Lower

CharField.register_lookup(Lower, "lower")
TextField.register_lookup(Lower, "lower")
DEFAULT_CHARSET = 'UTF-8'
MINUTES_AGO_HIT_COUNT = 15
IPV6_IP2LOCATION_PATH = "data/IP2LOCATION-LITE-DB1.BIN/IP2LOCATION-LITE-DB1.BIN"
IPV4_IP2LOCATION_PATH = "data/IP2LOCATION-LITE-DB1.IPV6.BIN/IP2LOCATION-LITE-DB1.IPV6.BIN"

IMPORT_EXPORT_USE_TRANSACTIONS = True

MAX_PHOTO_SIZE = 10000000
MAX_PHOTO_SIZE_MB = int(MAX_PHOTO_SIZE / 1000 / 1000)

FILE_UPLOAD_DIRECTORY_PERMISSIONS = 0o755
FILE_UPLOAD_PERMISSIONS = 0o644

#mailing
TESTING_EMAILS = [
Esempio n. 26
0
gpd.io.file.fiona.drvsupport.supported_drivers['KML'] = 'rw'
import shapely.speedups
import os
dirname = os.path.dirname(__file__)
# Define regije.kml path
filename = os.path.join(dirname, 'regije.kml')
shapely.speedups.enable()
import urllib.parse
from itertools import chain
from django.db.models import CharField, TextField
from django.db.models.functions import Lower
import json
import ast

CharField.register_lookup(Lower)
TextField.register_lookup(Lower)

def unique_chain(*iterables):
    known_ids = set()
    for it in iterables:
        for element in it:
            if element.id not in known_ids:
                known_ids.add(element.id)
                yield element

class PlotDownload(APIView):
    permission_classes = [IsAuthenticated]

    def get(self, request, id, format=None):
        try:
            data = Plot.objects.get(pk=id)