1.1.1 autosubscribe to null price subscribe

This commit is contained in:
SDE
2024-05-29 12:25:27 +03:00
parent efec0754cd
commit 17024d7350
11 changed files with 289 additions and 56 deletions

View File

@@ -1,4 +1,5 @@
from django.template.loader import render_to_string
from SubscribesApp.funcs import check_option_in_cur_user_subscribe
def get_user_timezone_Dict(user, request=None):
@@ -30,10 +31,12 @@ def get_profile_page_content_html(request, page_name, data):
if page_name == 'chat':
from ChatServiceApp.funcs import get_chat_page_content_html
return get_chat_page_content_html(request, data)
elif page_name == 'create_route_for_customer':
elif (page_name == 'create_route_for_customer' and
check_option_in_cur_user_subscribe(request.user, 'размещение заявок')):
from RoutesApp.funcs import get_profile_new_route_page_html
return get_profile_new_route_page_html(request, {'owner_type': 'customer'})
elif page_name == 'create_route_for_mover':
elif (page_name == 'create_route_for_mover' and
check_option_in_cur_user_subscribe(request.user, 'размещение заявок')):
from RoutesApp.funcs import get_profile_new_route_page_html
return get_profile_new_route_page_html(request, {'owner_type': 'mover'})
elif page_name == 'my_routes':

View File

@@ -47,8 +47,12 @@ def profile_page_View(request, page_name, id=None):
lang = get_and_set_lang(request)
page_html = get_profile_page_content_html(request, page_name, id)
if not page_html:
raise Http404
Dict = {
'page_html': get_profile_page_content_html(request, page_name, id),
'page_html': page_html,
'page_name': page_name,
'page_type': 'profile'
}

View File

@@ -7,6 +7,7 @@ import json
from django.shortcuts import render, get_object_or_404
from django.conf import settings
from django.utils.translation import gettext as _
from SubscribesApp.funcs import check_option_in_cur_user_subscribe
def get_key_Dict():
@@ -18,6 +19,9 @@ def get_key_Dict():
return Dict
def send_push(user, title, text, url=None, button_name=None, img=None):
if not check_option_in_cur_user_subscribe(user, 'push уведомления'):
return False
try:
# body = request.body
# data = json.loads(body)

View File

@@ -16,13 +16,16 @@ from django.urls import reverse
from .forms import *
from .funcs import *
from GeneralApp.funcs import get_and_set_lang
from SubscribesApp.funcs import check_option_in_cur_user_subscribe
def del_route_ajax(request):
if request.method != 'POST':
raise Http404
if not check_option_in_cur_user_subscribe(request.user, 'размещение заявок'):
return JsonResponse({'html': 'нет доступа'}, status=403)
lang = get_and_set_lang(request)
try:
@@ -58,6 +61,9 @@ def edit_route_ajax(request):
if request.method != 'POST':
raise Http404
if not check_option_in_cur_user_subscribe(request.user, 'размещение заявок'):
return JsonResponse({'html': 'нет доступа'}, status=403)
lang = get_and_set_lang(request)
data = json.loads(request.body)
@@ -108,6 +114,8 @@ def edit_route_ajax(request):
def new_route_view_ajax(request):
if request.method != 'POST':
raise Http404
if not check_option_in_cur_user_subscribe(request.user, 'размещение заявок'):
return JsonResponse({'html': 'нет доступа'}, status=403)
lang = get_and_set_lang(request)
@@ -222,6 +230,9 @@ def create_or_change_route_ajax(request, route_id=None):
if request.method != 'POST':
raise Http404
if not check_option_in_cur_user_subscribe(request.user, 'размещение заявок'):
return JsonResponse({'html': 'нет доступа'}, status=403)
lang = get_and_set_lang(request)
Dict = {}

View File

@@ -4,7 +4,7 @@ from django.utils.translation import gettext as _
from django.template.loader import render_to_string
from GeneralApp.funcs_options import get_options_by_opt_types, get_mail_send_options
from BaseModels.mailSender import admin_send_mail_by_SMTPlib, techSendMail
from SubscribesApp.funcs import check_option_in_cur_user_subscribe
def get_Dict_for_send_msgs(kwargs, search_owner_type):
@@ -36,6 +36,9 @@ def send_push_message_for_found_matches_routes(route, data_Dict):
if not route.owner.is_authenticated:
return None
if not check_option_in_cur_user_subscribe(route.owner, 'push уведомления'):
return False
from PushMessages.views import send_push
title = 'Мы нашли исполнителя по Вашему объявлению!'
text = 'Для просмотра результата нажмите на кнопку ниже'
@@ -126,8 +129,18 @@ def search_matches(for_routes=None):
if found_routes:
msg = f'found routes for send messages = {found_routes.count()}'
data_Dict = None
try:
data_Dict = get_Dict_for_send_msgs(params, found_routes[0].owner_type)
except Exception as e:
msg = f'<br>\n! search_matches Error get_Dict_for_send_msgs = {str(e)}'
print(msg)
log += msg
if data_Dict and check_option_in_cur_user_subscribe(
route.owner, 'push уведомления'
):
try:
msg = send_push_message_for_found_matches_routes(route, data_Dict)
if msg:
log += msg
@@ -136,6 +149,10 @@ def search_matches(for_routes=None):
print(msg)
log += msg
if data_Dict and check_option_in_cur_user_subscribe(
route.owner,
'уведомление на e-mail о появлении перевозчика по заданным критериям'
):
try:
msg = send_mail_found_matches_routes(route, data_Dict)
if msg:

View File

@@ -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:

View File

@@ -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=_('Длительность подписки в часах'))

View File

@@ -0,0 +1 @@
__author__ = 'SDE'

View 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

View File

@@ -1,6 +1,7 @@
{% load static %}
{% csrf_token %}
{% load i18n %}
{% load subscribes_tags_extra %}
{%trans "Профиль" as t_prof %}
{%trans "Разместить объявление как отправитель" as t_customer %}
@@ -11,6 +12,7 @@
{%trans "Моя подписка" as t_subscribe %}
{%trans "Изменить профиль" as t_change_profile %}
{%trans "Выход" as t_logout %}
{% check_subscribe_option user 'размещение заявок' as create_routes_allow %}
<div class="menu_profile {% if not page_type == 'profile' %}background{% endif %}">
<div class="subscribe_type_txt"> {% if user_subscribe %}<span class="f-l">{% trans "Подписка" %}:</span> <span class="f-r">{{ user_subscribe.subscribe.name }}</span>{% endif %}<div class="clear_both"></div></div>
@@ -18,12 +20,14 @@
{% with sel_page_name='create_route_for_mover' sel_page_name='dashboard' ajax_url="dashboard" title=t_prof img_path="/static/img/svg/User.svg"%}
{% include "widgets/profile/w_button_for_profile_menu.html" %}
{% endwith %}
{% if create_routes_allow %}
{% with sel_page_name='create_route_for_customer' dom_id="customer" ajax_url="new_route_view" owner_type="customer" title=t_customer img_path="/static/img/svg/PushPin.svg"%}
{% include "widgets/profile/w_button_for_profile_menu.html" %}
{% endwith %}
{% with sel_page_name='create_route_for_mover' dom_id="mover" ajax_url="new_route_view" owner_type="mover" title=t_mover img_path="/static/img/svg/PushPin.svg"%}
{% include "widgets/profile/w_button_for_profile_menu.html" %}
{% endwith %}
{% endif %}
{% with sel_page_name='my_routes' dom_id="my_routes_id" ajax_url="get_routes" title=t_my_routes img_path="/static/img/svg/Cards.svg"%}
{% include "widgets/profile/w_button_for_profile_menu.html" %}
{% endwith %}

View File

@@ -1,5 +1,6 @@
{% load static %}
{% load i18n %}
{% load subscribes_tags_extra %}
{% if route.departure_DT %}
{% now 'Y-m-d H:i:s' as current_date %}
@@ -99,9 +100,10 @@
{# {% endif %}#}
</div>
{% check_subscribe_option request.user 'просмотр контактов' as show_contacts_allow %}
<div name="form_carrier">
{% if user.is_authenticated %}
{% if user.is_authenticated and show_contacts_allow %}
<div class="inf_carrier">
<img class="route_contact_avatar {% if route.owner == user %} active{% endif %}" {% if route.owner.user_profile.avatar %}
src="{{ route.owner.user_profile.avatar.url }}"
@@ -135,7 +137,7 @@
</div>
{% endif %}
{% if not user.is_authenticated %}
{% if not user.is_authenticated or not show_contacts_allow %}
<div class="inf_carrier">
<a class="phones_carrier">
<img class="inf_carrier_icon" src="{% static "/img/svg/phone.svg" %}"/>
@@ -155,7 +157,7 @@
{% if not user.is_anonymous and route.owner != user %}
{% if not user.is_anonymous and route.owner != user and show_contacts_allow %}
<button class="open_chat_carrier" onclick="open_chat({{ route.owner_id }})">
<img src="{% static "img/svg/Logo.svg" %}" width="30px">
<span> {% translate "Написать сообщение" %}</span>
@@ -163,7 +165,7 @@
</button>
{% endif %}
{% if user.is_authenticated %}
{% if user.is_authenticated and show_contacts_allow %}
<button
class="open_inf_carrier"
{% if route.owner == user %} style="display: none;"{% endif %}
@@ -174,7 +176,7 @@
{% endif %}
{% if not user.is_authenticated %}
{% if not user.is_authenticated and show_contacts_allow %}
<div class="show_contact_wrapper">
<a class="open_inf_carrier" href='{% url "login_profile" %}'>
{% translate "Открыть контакт"%}