You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
2.4 KiB
58 lines
2.4 KiB
# -*- coding: utf-8 -*-
|
|
from collections import OrderedDict
|
|
|
|
from django.db.models.sql.where import AND, OR
|
|
from django.utils.translation import ugettext as _
|
|
|
|
from functions.model_utils import EnumChoices
|
|
|
|
|
|
members_mapping = OrderedDict([
|
|
('N200', {'min': None, 'max': 200, 'value': 1, 'label': _(u'до 200')}),
|
|
('N200500', {'min': 200, 'max': 400, 'value': 2, 'label': _(u'200-500')}),
|
|
('N5001000', {'min': 500, 'max': 500, 'value': 3, 'label': _(u'500-1000')}),
|
|
('N10002000', {'min': 1000, 'max': 2000, 'value': 4, 'label': _(u'1000-2000')}),
|
|
('N2000', {'min': 2000, 'max': None, 'value': 5, 'label': _(u'более 2000')}),
|
|
])
|
|
|
|
visitors_mapping = OrderedDict([
|
|
('N5', {'min': None, 'max': 5000, 'value': 1, 'label': _(u'до 5 000')}),
|
|
('N510', {'min': 5000, 'max': 10000, 'value': 2, 'label': _(u'5 000 - 10 000')}),
|
|
('N1030', {'min': 10000, 'max': 30000, 'value': 3, 'label': _(u'10 000 - 30 000')}),
|
|
('N3050', {'min': 30000, 'max': 50000, 'value': 4, 'label': _(u'30 000 - 50 000')}),
|
|
('N50100', {'min': 50000, 'max': 100000, 'value': 5, 'label': _(u'50 000 - 100 000')}),
|
|
('N100', {'min': 100000, 'max': None, 'value': 6, 'label': _(u'более 100 000')}),
|
|
])
|
|
|
|
price_mapping = OrderedDict([
|
|
('N1', {'min': None, 'max': 100, 'value': 1, 'label': _(u'до 100 евро')}),
|
|
('N12', {'min': 100, 'max': 200, 'value': 2, 'label': _(u'100-200 евро')}),
|
|
('N24', {'min': 200, 'max': 400, 'value': 3, 'label': _(u'200-400 евро')}),
|
|
('N4', {'min': 400, 'max': None, 'value': 4, 'label': _(u'более 400 евро')}),
|
|
])
|
|
|
|
def get_choices_kwargs(mapping):
|
|
kwargs = OrderedDict()
|
|
for key, val in mapping.iteritems():
|
|
kwargs[key] = (val.get('value'), val.get('label'))
|
|
return kwargs
|
|
|
|
MEMBERS = EnumChoices(**get_choices_kwargs(members_mapping))
|
|
VISITORS = EnumChoices(**get_choices_kwargs(visitors_mapping))
|
|
PRICE = EnumChoices(**get_choices_kwargs(price_mapping))
|
|
TYPES = EnumChoices(
|
|
EXPO=(1, _(u'Выставки')),
|
|
CONF=(2, _(_(u'Конференции'))),
|
|
)
|
|
|
|
|
|
class ExtraWhere(object):
|
|
def __init__(self, sqls, params, operator=AND):
|
|
self.sqls = sqls
|
|
self.params = params
|
|
self.operator = operator
|
|
|
|
def as_sql(self, qn=None, connection=None):
|
|
sqls = ["(%s)" % sql for sql in self.sqls]
|
|
operator = " {operator} ".format(operator=self.operator)
|
|
return operator.join(sqls), tuple(self.params or ())
|
|
|