1.1.1 autosubscribe to null price subscribe
This commit is contained in:
@@ -4,6 +4,22 @@ from django.utils.translation import get_language, activate
|
||||
from datetime import datetime, timedelta
|
||||
import json
|
||||
|
||||
def check_option_in_cur_user_subscribe(user, option_name):
|
||||
if not user or not user.is_active or not user.is_authenticated:
|
||||
return False
|
||||
|
||||
user_subscribe = get_cur_user_subscribe(user)
|
||||
try:
|
||||
option = SubscribeOption.objects.get(
|
||||
rel_subscribes_for_option=user_subscribe.subscribe,
|
||||
name_ru__iexact=option_name
|
||||
)
|
||||
return True
|
||||
except SubscribeOption.DoesNotExist:
|
||||
return False
|
||||
|
||||
|
||||
|
||||
def get_null_price_subscribe():
|
||||
subscribes_null_price = Subscribe.objects.filter(
|
||||
enable=True,
|
||||
@@ -31,6 +47,9 @@ def subscribe_user_to_null_price_subscribe(user):
|
||||
|
||||
def get_cur_user_subscribe(user):
|
||||
|
||||
if not user or not user.is_active or not user.is_authenticated:
|
||||
return None
|
||||
|
||||
try:
|
||||
user_subscribe = SubscribeForUser.objects.get(enable=True, user=user)
|
||||
except SubscribeForUser.DoesNotExist:
|
||||
|
||||
@@ -3,6 +3,16 @@ from BaseModels.base_models import BaseModel
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from colorfield.fields import ColorField
|
||||
|
||||
|
||||
# options_list 29.05.2024
|
||||
# СМС уведомления
|
||||
# push уведомления
|
||||
# выделение заявки цветом (20 заявок) + 70 поднятий
|
||||
# выделение заявок цветом (3 заявки) + 5 поднятий
|
||||
# уведомление на e-mail о появлении перевозчика по заданным критериям
|
||||
# размещение заявок
|
||||
# просмотр контактов
|
||||
|
||||
class SubscribeOption(BaseModel):
|
||||
|
||||
class Meta:
|
||||
@@ -16,7 +26,8 @@ class Subscribe(BaseModel):
|
||||
|
||||
price = models.FloatField(verbose_name='Стоимость', default=0)
|
||||
options = models.ManyToManyField(
|
||||
SubscribeOption, verbose_name=_('Подключенные опции'), blank=True, related_name='rel_subscribes_for_option'
|
||||
SubscribeOption, verbose_name=_('Подключенные опции'), blank=True,
|
||||
related_name='rel_subscribes_for_option'
|
||||
)
|
||||
period_name = models.CharField(max_length=250, verbose_name=_('Название периода'))
|
||||
period = models.IntegerField(default=0, verbose_name=_('Длительность подписки в часах'))
|
||||
|
||||
1
SubscribesApp/templatetags/__init__.py
Normal file
1
SubscribesApp/templatetags/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
__author__ = 'SDE'
|
||||
157
SubscribesApp/templatetags/subscribes_tags_extra.py
Normal file
157
SubscribesApp/templatetags/subscribes_tags_extra.py
Normal file
@@ -0,0 +1,157 @@
|
||||
__author__ = 'SDE'
|
||||
|
||||
from django import template
|
||||
from django.template.defaultfilters import stringfilter
|
||||
|
||||
register = template.Library()
|
||||
|
||||
from django.core.serializers import serialize
|
||||
from django.db.models.query import QuerySet
|
||||
# import simplejson
|
||||
from django.template import Library
|
||||
from django.utils.html import mark_safe
|
||||
|
||||
# @register.filter('get_value_from_dict')
|
||||
# def get_value_from_dict(dict_data, key):
|
||||
# """
|
||||
# usage example {{ your_dict|get_value_from_dict:your_key }}
|
||||
# """
|
||||
#
|
||||
# if key in dict_data:
|
||||
# res = dict_data[key]
|
||||
# return res
|
||||
#
|
||||
# return False
|
||||
#
|
||||
#
|
||||
#
|
||||
# @register.filter()
|
||||
# def get_rows_count_by_cols_count(data, cols_count):
|
||||
# rows_count = len(data) // cols_count
|
||||
# if len(data) % cols_count:
|
||||
# rows_count += 1
|
||||
# return rows_count
|
||||
#
|
||||
# @register.filter()
|
||||
# def get_numbers_list(from_el, to_el):
|
||||
# res = range(from_el, to_el+1)
|
||||
# return res
|
||||
#
|
||||
#
|
||||
# def val_type(value):
|
||||
# res = type(value)
|
||||
# return res.__name__
|
||||
# register.filter('val_type', val_type)
|
||||
#
|
||||
# @register.filter()
|
||||
# def get_cols_table_data_for_row_when_cols3(value, row):
|
||||
# el_count = 3
|
||||
# from_el = (row-1) * el_count
|
||||
# to_el = row * el_count
|
||||
# part = list(value)[from_el:to_el]
|
||||
# return part
|
||||
# # register.filter('val_type', val_type)
|
||||
#
|
||||
#
|
||||
# @register.filter
|
||||
# @stringfilter
|
||||
# def correct_for_tables(value):
|
||||
# if value in ['None', '0.0']:
|
||||
# return '-'
|
||||
# return value
|
||||
#
|
||||
#
|
||||
# @register.filter
|
||||
# @stringfilter
|
||||
# def del_bad_symbols(value):
|
||||
# from BaseModels.functions import del_bad_symbols
|
||||
# return del_bad_symbols(value)
|
||||
#
|
||||
#
|
||||
# @register.filter
|
||||
# @stringfilter
|
||||
# def del_amp_symbols(value):
|
||||
# from BaseModels.functions import del_nbsp
|
||||
# return del_nbsp(value)
|
||||
#
|
||||
# @register.filter
|
||||
@register.simple_tag()
|
||||
def check_subscribe_option(s_user, option_name):
|
||||
from ..funcs import check_option_in_cur_user_subscribe
|
||||
res = check_option_in_cur_user_subscribe(s_user, option_name)
|
||||
return res
|
||||
#
|
||||
# @register.filter
|
||||
# @stringfilter
|
||||
# def get_color_by_number(value, arg=None):
|
||||
#
|
||||
# color = None
|
||||
# try:
|
||||
# val = float(value)
|
||||
#
|
||||
# if not color and arg == u'%':
|
||||
#
|
||||
# color = u'black'
|
||||
# if val > 50:
|
||||
# color = u'green'
|
||||
# elif val <= 50 and val >= 25:
|
||||
# color = u'#6c8107'
|
||||
# elif val <= 25 and val >= 10:
|
||||
# color = u'#a89803'
|
||||
# elif val <= 10 and val >= 5:
|
||||
# color = u'#e6a707'
|
||||
# elif val <= 5 and val >= 0:
|
||||
# color = u'#e67307'
|
||||
# elif val <= 0:
|
||||
# color = u'red'
|
||||
#
|
||||
#
|
||||
# # val_range = val_max - val_min
|
||||
# # # val_percent = (val_range * 100 / val) - 100
|
||||
# # offset = -(val_min + -(val))
|
||||
# # if val <0:
|
||||
# # val = offset
|
||||
# # if val > val_max:
|
||||
# # val = val_max
|
||||
# # elif val < 0:
|
||||
# # val = 0
|
||||
# #
|
||||
# # color_range = 16711680 - 1211136
|
||||
# # val_1unit = float(color_range) / float(val_range)
|
||||
# # dec_color = 16711680 - int(val_1unit * val)
|
||||
#
|
||||
# if not color:
|
||||
# color = u'black'
|
||||
# if val > 1000:
|
||||
# color = u'green'
|
||||
# elif val <= 1000 and val >= 500:
|
||||
# color = u'#6c8107'
|
||||
# elif val <= 500 and val >= 250:
|
||||
# color = u'#a89803'
|
||||
# elif val <= 250 and val >= 125:
|
||||
# color = u'#e6a707'
|
||||
# elif val <= 125 and val >= 50:
|
||||
# color = u'#e67307'
|
||||
# elif val <= 50:
|
||||
# color = u'red'
|
||||
#
|
||||
# # s = u'style="color: #{0}12;"'.format(str(hex(dec_color))[2:6])
|
||||
# s = u'style="color: {0};"'.format(color)
|
||||
# return s
|
||||
# except:
|
||||
# return u''
|
||||
#
|
||||
#
|
||||
# # @register.filter
|
||||
# # @stringfilter
|
||||
# # def check_aprox_compare_strings(search_phrase, txt):
|
||||
# # from ProductApp.search import get_highlight_string
|
||||
# #
|
||||
# # s = get_highlight_string(search_phrase, txt)
|
||||
# #
|
||||
# # return s
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user