remove unused imports, vairables and commented code
from views, and base cookbook and recipes modules
This commit is contained in:
parent
1f0cd58d7d
commit
538fb8b42e
@ -10,13 +10,13 @@ from treebeard.forms import movenodeform_factory
|
|||||||
|
|
||||||
from cookbook.managers import DICTIONARY
|
from cookbook.managers import DICTIONARY
|
||||||
|
|
||||||
from .models import (Automation, BookmarkletImport, Comment, CookLog, Food, FoodInheritField,
|
from .models import (BookmarkletImport, Comment, CookLog, Food, ImportLog, Ingredient, InviteLink,
|
||||||
ImportLog, Ingredient, InviteLink, Keyword, MealPlan, MealType,
|
Keyword, MealPlan, MealType, NutritionInformation, Property, PropertyType,
|
||||||
NutritionInformation, Property, PropertyType, Recipe, RecipeBook,
|
Recipe, RecipeBook, RecipeBookEntry, RecipeImport, SearchPreference, ShareLink,
|
||||||
RecipeBookEntry, RecipeImport, SearchPreference, ShareLink, ShoppingList,
|
ShoppingList, ShoppingListEntry, ShoppingListRecipe, Space, Step, Storage,
|
||||||
ShoppingListEntry, ShoppingListRecipe, Space, Step, Storage, Supermarket,
|
Supermarket, SupermarketCategory, SupermarketCategoryRelation, Sync, SyncLog,
|
||||||
SupermarketCategory, SupermarketCategoryRelation, Sync, SyncLog, TelegramBot,
|
TelegramBot, Unit, UnitConversion, UserFile, UserPreference, UserSpace,
|
||||||
Unit, UnitConversion, UserFile, UserPreference, UserSpace, ViewLog)
|
ViewLog)
|
||||||
|
|
||||||
|
|
||||||
class CustomUserAdmin(UserAdmin):
|
class CustomUserAdmin(UserAdmin):
|
||||||
|
@ -34,35 +34,14 @@ class RecipeSearchManager(models.Manager):
|
|||||||
+ SearchVector(StringAgg('steps__ingredients__food__name__unaccent', delimiter=' '), weight='B', config=language)
|
+ SearchVector(StringAgg('steps__ingredients__food__name__unaccent', delimiter=' '), weight='B', config=language)
|
||||||
+ SearchVector(StringAgg('keywords__name__unaccent', delimiter=' '), weight='B', config=language))
|
+ SearchVector(StringAgg('keywords__name__unaccent', delimiter=' '), weight='B', config=language))
|
||||||
search_rank = SearchRank(search_vectors, search_query)
|
search_rank = SearchRank(search_vectors, search_query)
|
||||||
# USING TRIGRAM BREAKS WEB SEARCH
|
|
||||||
# ADDING MULTIPLE TRIGRAMS CREATES DUPLICATE RESULTS
|
|
||||||
# DISTINCT NOT COMPAITBLE WITH ANNOTATE
|
|
||||||
# trigram_name = (TrigramSimilarity('name', search_text))
|
|
||||||
# trigram_description = (TrigramSimilarity('description', search_text))
|
|
||||||
# trigram_food = (TrigramSimilarity('steps__ingredients__food__name', search_text))
|
|
||||||
# trigram_keyword = (TrigramSimilarity('keywords__name', search_text))
|
|
||||||
# adding additional trigrams created duplicates
|
|
||||||
# + TrigramSimilarity('description', search_text)
|
|
||||||
# + TrigramSimilarity('steps__ingredients__food__name', search_text)
|
|
||||||
# + TrigramSimilarity('keywords__name', search_text)
|
|
||||||
return (
|
return (
|
||||||
self.get_queryset()
|
self.get_queryset()
|
||||||
.annotate(
|
.annotate(
|
||||||
search=search_vectors,
|
search=search_vectors,
|
||||||
rank=search_rank,
|
rank=search_rank,
|
||||||
# trigram=trigram_name+trigram_description+trigram_food+trigram_keyword
|
|
||||||
# trigram_name=trigram_name,
|
|
||||||
# trigram_description=trigram_description,
|
|
||||||
# trigram_food=trigram_food,
|
|
||||||
# trigram_keyword=trigram_keyword
|
|
||||||
)
|
)
|
||||||
.filter(
|
.filter(
|
||||||
Q(search=search_query)
|
Q(search=search_query)
|
||||||
# | Q(trigram_name__gt=0.1)
|
|
||||||
# | Q(name__icontains=search_text)
|
|
||||||
# | Q(trigram_name__gt=0.2)
|
|
||||||
# | Q(trigram_description__gt=0.2)
|
|
||||||
# | Q(trigram_food__gt=0.2)
|
|
||||||
# | Q(trigram_keyword__gt=0.2)
|
|
||||||
)
|
)
|
||||||
.order_by('-rank'))
|
.order_by('-rank'))
|
||||||
|
@ -67,17 +67,3 @@ class FilterSchema(AutoSchema):
|
|||||||
'schema': {'type': 'string', },
|
'schema': {'type': 'string', },
|
||||||
})
|
})
|
||||||
return parameters
|
return parameters
|
||||||
|
|
||||||
|
|
||||||
# class QueryOnlySchema(AutoSchema):
|
|
||||||
# def get_path_parameters(self, path, method):
|
|
||||||
# if not is_list_view(path, method, self.view):
|
|
||||||
# return super(QueryOnlySchema, self).get_path_parameters(path, method)
|
|
||||||
|
|
||||||
# parameters = super().get_path_parameters(path, method)
|
|
||||||
# parameters.append({
|
|
||||||
# "name": 'query', "in": "query", "required": False,
|
|
||||||
# "description": 'Query string matched (fuzzy) against object name.',
|
|
||||||
# 'schema': {'type': 'string', },
|
|
||||||
# })
|
|
||||||
# return parameters
|
|
||||||
|
@ -570,7 +570,6 @@ class FoodSimpleSerializer(serializers.ModelSerializer):
|
|||||||
class FoodSerializer(UniqueFieldsMixin, WritableNestedModelSerializer, ExtendedRecipeMixin, OpenDataModelMixin):
|
class FoodSerializer(UniqueFieldsMixin, WritableNestedModelSerializer, ExtendedRecipeMixin, OpenDataModelMixin):
|
||||||
supermarket_category = SupermarketCategorySerializer(allow_null=True, required=False)
|
supermarket_category = SupermarketCategorySerializer(allow_null=True, required=False)
|
||||||
recipe = RecipeSimpleSerializer(allow_null=True, required=False)
|
recipe = RecipeSimpleSerializer(allow_null=True, required=False)
|
||||||
# shopping = serializers.SerializerMethodField('get_shopping_status')
|
|
||||||
shopping = serializers.ReadOnlyField(source='shopping_status')
|
shopping = serializers.ReadOnlyField(source='shopping_status')
|
||||||
inherit_fields = FoodInheritFieldSerializer(many=True, allow_null=True, required=False)
|
inherit_fields = FoodInheritFieldSerializer(many=True, allow_null=True, required=False)
|
||||||
child_inherit_fields = FoodInheritFieldSerializer(many=True, allow_null=True, required=False)
|
child_inherit_fields = FoodInheritFieldSerializer(many=True, allow_null=True, required=False)
|
||||||
@ -609,9 +608,6 @@ class FoodSerializer(UniqueFieldsMixin, WritableNestedModelSerializer, ExtendedR
|
|||||||
filter |= Q(path__startswith=obj.path, depth__gt=obj.depth)
|
filter |= Q(path__startswith=obj.path, depth__gt=obj.depth)
|
||||||
return Food.objects.filter(filter).filter(onhand_users__id__in=shared_users).exists()
|
return Food.objects.filter(filter).filter(onhand_users__id__in=shared_users).exists()
|
||||||
|
|
||||||
# def get_shopping_status(self, obj):
|
|
||||||
# return ShoppingListEntry.objects.filter(space=obj.space, food=obj, checked=False).count() > 0
|
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
name = validated_data['name'].strip()
|
name = validated_data['name'].strip()
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
from decimal import Decimal
|
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@ -13,8 +12,8 @@ from django_scopes import scope, scopes_disabled
|
|||||||
from cookbook.helper.cache_helper import CacheHelper
|
from cookbook.helper.cache_helper import CacheHelper
|
||||||
from cookbook.helper.shopping_helper import RecipeShoppingEditor
|
from cookbook.helper.shopping_helper import RecipeShoppingEditor
|
||||||
from cookbook.managers import DICTIONARY
|
from cookbook.managers import DICTIONARY
|
||||||
from cookbook.models import (Food, FoodInheritField, Ingredient, MealPlan, Recipe,
|
from cookbook.models import (Food, MealPlan, PropertyType, Recipe, SearchFields, SearchPreference,
|
||||||
ShoppingListEntry, Step, UserPreference, SearchPreference, SearchFields, Unit, PropertyType)
|
Step, Unit, UserPreference)
|
||||||
|
|
||||||
SQLITE = True
|
SQLITE = True
|
||||||
if settings.DATABASES['default']['ENGINE'] in ['django.db.backends.postgresql_psycopg2',
|
if settings.DATABASES['default']['ENGINE'] in ['django.db.backends.postgresql_psycopg2',
|
||||||
|
@ -3,8 +3,7 @@ from django.utils.html import format_html
|
|||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
from django_tables2.utils import A
|
from django_tables2.utils import A
|
||||||
|
|
||||||
from .models import (CookLog, InviteLink, Recipe, RecipeImport,
|
from .models import CookLog, InviteLink, RecipeImport, Storage, Sync, SyncLog, ViewLog
|
||||||
Storage, Sync, SyncLog, ViewLog)
|
|
||||||
|
|
||||||
|
|
||||||
class StorageTable(tables.Table):
|
class StorageTable(tables.Table):
|
||||||
|
@ -1490,7 +1490,6 @@ class ImportOpenData(APIView):
|
|||||||
# TODO validate data
|
# TODO validate data
|
||||||
print(request.data)
|
print(request.data)
|
||||||
selected_version = request.data['selected_version']
|
selected_version = request.data['selected_version']
|
||||||
selected_datatypes = request.data['selected_datatypes']
|
|
||||||
update_existing = str2bool(request.data['update_existing'])
|
update_existing = str2bool(request.data['update_existing'])
|
||||||
use_metric = str2bool(request.data['use_metric'])
|
use_metric = str2bool(request.data['use_metric'])
|
||||||
|
|
||||||
|
@ -10,12 +10,11 @@ from django.utils.translation import gettext as _
|
|||||||
from django.utils.translation import ngettext
|
from django.utils.translation import ngettext
|
||||||
from django_tables2 import RequestConfig
|
from django_tables2 import RequestConfig
|
||||||
from oauth2_provider.models import AccessToken
|
from oauth2_provider.models import AccessToken
|
||||||
from rest_framework.authtoken.models import Token
|
|
||||||
|
|
||||||
from cookbook.forms import BatchEditForm, SyncForm
|
from cookbook.forms import BatchEditForm, SyncForm
|
||||||
from cookbook.helper.permission_helper import group_required, has_group_permission, above_space_limit
|
from cookbook.helper.permission_helper import (above_space_limit, group_required,
|
||||||
from cookbook.models import (Comment, Food, Keyword, Recipe, RecipeImport, Sync,
|
has_group_permission)
|
||||||
Unit, UserPreference, BookmarkletImport)
|
from cookbook.models import BookmarkletImport, Recipe, RecipeImport, Sync
|
||||||
from cookbook.tables import SyncTable
|
from cookbook.tables import SyncTable
|
||||||
from recipes import settings
|
from recipes import settings
|
||||||
|
|
||||||
@ -119,11 +118,19 @@ def import_url(request):
|
|||||||
return HttpResponseRedirect(reverse('index'))
|
return HttpResponseRedirect(reverse('index'))
|
||||||
|
|
||||||
if (api_token := AccessToken.objects.filter(user=request.user, scope='bookmarklet').first()) is None:
|
if (api_token := AccessToken.objects.filter(user=request.user, scope='bookmarklet').first()) is None:
|
||||||
api_token = AccessToken.objects.create(user=request.user, scope='bookmarklet', expires=(timezone.now() + timezone.timedelta(days=365*10)), token=f'tda_{str(uuid.uuid4()).replace("-","_")}')
|
api_token = AccessToken.objects.create(
|
||||||
|
user=request.user,
|
||||||
|
scope='bookmarklet',
|
||||||
|
expires=(
|
||||||
|
timezone.now() +
|
||||||
|
timezone.timedelta(
|
||||||
|
days=365 *
|
||||||
|
10)),
|
||||||
|
token=f'tda_{str(uuid.uuid4()).replace("-","_")}')
|
||||||
|
|
||||||
bookmarklet_import_id = -1
|
bookmarklet_import_id = -1
|
||||||
if 'id' in request.GET:
|
if 'id' in request.GET:
|
||||||
if bookmarklet_import := BookmarkletImport.objects.filter(id=request.GET['id']).first():
|
if bookmarklet_import := BookmarkletImport.objects.filter(id=request.GET['id']).first():
|
||||||
bookmarklet_import_id = bookmarklet_import.pk
|
bookmarklet_import_id = bookmarklet_import.pk
|
||||||
|
|
||||||
return render(request, 'url_import.html', {'api_token': api_token, 'bookmarklet_import_id': bookmarklet_import_id})
|
return render(request, 'url_import.html', {'api_token': api_token, 'bookmarklet_import_id': bookmarklet_import_id})
|
||||||
|
@ -9,7 +9,7 @@ from django.views.generic import DeleteView
|
|||||||
|
|
||||||
from cookbook.helper.permission_helper import GroupRequiredMixin, OwnerRequiredMixin, group_required
|
from cookbook.helper.permission_helper import GroupRequiredMixin, OwnerRequiredMixin, group_required
|
||||||
from cookbook.models import (Comment, InviteLink, MealPlan, Recipe, RecipeBook, RecipeBookEntry,
|
from cookbook.models import (Comment, InviteLink, MealPlan, Recipe, RecipeBook, RecipeBookEntry,
|
||||||
RecipeImport, Storage, Sync, UserSpace, Space)
|
RecipeImport, Space, Storage, Sync, UserSpace)
|
||||||
from cookbook.provider.dropbox import Dropbox
|
from cookbook.provider.dropbox import Dropbox
|
||||||
from cookbook.provider.local import Local
|
from cookbook.provider.local import Local
|
||||||
from cookbook.provider.nextcloud import Nextcloud
|
from cookbook.provider.nextcloud import Nextcloud
|
||||||
@ -99,18 +99,6 @@ class SyncDelete(GroupRequiredMixin, DeleteView):
|
|||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
# class KeywordDelete(GroupRequiredMixin, DeleteView):
|
|
||||||
# groups_required = ['user']
|
|
||||||
# template_name = "generic/delete_template.html"
|
|
||||||
# model = Keyword
|
|
||||||
# success_url = reverse_lazy('list_keyword')
|
|
||||||
|
|
||||||
# def get_context_data(self, **kwargs):
|
|
||||||
# context = super(KeywordDelete, self).get_context_data(**kwargs)
|
|
||||||
# context['title'] = _("Keyword")
|
|
||||||
# return context
|
|
||||||
|
|
||||||
|
|
||||||
class StorageDelete(GroupRequiredMixin, DeleteView):
|
class StorageDelete(GroupRequiredMixin, DeleteView):
|
||||||
groups_required = ['admin']
|
groups_required = ['admin']
|
||||||
template_name = "generic/delete_template.html"
|
template_name = "generic/delete_template.html"
|
||||||
|
@ -9,9 +9,9 @@ from django.views.generic import UpdateView
|
|||||||
from django.views.generic.edit import FormMixin
|
from django.views.generic.edit import FormMixin
|
||||||
|
|
||||||
from cookbook.forms import CommentForm, ExternalRecipeForm, StorageForm, SyncForm
|
from cookbook.forms import CommentForm, ExternalRecipeForm, StorageForm, SyncForm
|
||||||
from cookbook.helper.permission_helper import GroupRequiredMixin, OwnerRequiredMixin, group_required, above_space_limit
|
from cookbook.helper.permission_helper import (GroupRequiredMixin, OwnerRequiredMixin,
|
||||||
from cookbook.models import (Comment, MealPlan, MealType, Recipe, RecipeImport, Storage, Sync,
|
above_space_limit, group_required)
|
||||||
UserPreference)
|
from cookbook.models import Comment, Recipe, RecipeImport, Storage, Sync
|
||||||
from cookbook.provider.dropbox import Dropbox
|
from cookbook.provider.dropbox import Dropbox
|
||||||
from cookbook.provider.local import Local
|
from cookbook.provider.local import Local
|
||||||
from cookbook.provider.nextcloud import Nextcloud
|
from cookbook.provider.nextcloud import Nextcloud
|
||||||
@ -74,40 +74,6 @@ class SyncUpdate(GroupRequiredMixin, UpdateView, SpaceFormMixing):
|
|||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
# class KeywordUpdate(GroupRequiredMixin, UpdateView):
|
|
||||||
# groups_required = ['user']
|
|
||||||
# template_name = "generic/edit_template.html"
|
|
||||||
# model = Keyword
|
|
||||||
# form_class = KeywordForm
|
|
||||||
|
|
||||||
# # TODO add msg box
|
|
||||||
|
|
||||||
# def get_success_url(self):
|
|
||||||
# return reverse('list_keyword')
|
|
||||||
|
|
||||||
# def get_context_data(self, **kwargs):
|
|
||||||
# context = super().get_context_data(**kwargs)
|
|
||||||
# context['title'] = _("Keyword")
|
|
||||||
# return context
|
|
||||||
|
|
||||||
|
|
||||||
# class FoodUpdate(GroupRequiredMixin, UpdateView, SpaceFormMixing):
|
|
||||||
# groups_required = ['user']
|
|
||||||
# template_name = "generic/edit_template.html"
|
|
||||||
# model = Food
|
|
||||||
# form_class = FoodForm
|
|
||||||
|
|
||||||
# # TODO add msg box
|
|
||||||
|
|
||||||
# def get_success_url(self):
|
|
||||||
# return reverse('edit_food', kwargs={'pk': self.object.pk})
|
|
||||||
|
|
||||||
# def get_context_data(self, **kwargs):
|
|
||||||
# context = super(FoodUpdate, self).get_context_data(**kwargs)
|
|
||||||
# context['title'] = _("Food")
|
|
||||||
# return context
|
|
||||||
|
|
||||||
|
|
||||||
@group_required('admin')
|
@group_required('admin')
|
||||||
def edit_storage(request, pk):
|
def edit_storage(request, pk):
|
||||||
instance = get_object_or_404(Storage, pk=pk, space=request.space)
|
instance = get_object_or_404(Storage, pk=pk, space=request.space)
|
||||||
|
@ -7,8 +7,7 @@ from django_tables2 import RequestConfig
|
|||||||
|
|
||||||
from cookbook.helper.permission_helper import group_required
|
from cookbook.helper.permission_helper import group_required
|
||||||
from cookbook.models import InviteLink, RecipeImport, Storage, SyncLog, UserFile
|
from cookbook.models import InviteLink, RecipeImport, Storage, SyncLog, UserFile
|
||||||
from cookbook.tables import (ImportLogTable, InviteLinkTable, RecipeImportTable,
|
from cookbook.tables import ImportLogTable, InviteLinkTable, RecipeImportTable, StorageTable
|
||||||
StorageTable)
|
|
||||||
|
|
||||||
|
|
||||||
@group_required('admin')
|
@group_required('admin')
|
||||||
@ -196,7 +195,7 @@ def custom_filter(request):
|
|||||||
def user_file(request):
|
def user_file(request):
|
||||||
try:
|
try:
|
||||||
current_file_size_mb = UserFile.objects.filter(space=request.space).aggregate(Sum('file_size_kb'))[
|
current_file_size_mb = UserFile.objects.filter(space=request.space).aggregate(Sum('file_size_kb'))[
|
||||||
'file_size_kb__sum'] / 1000
|
'file_size_kb__sum'] / 1000
|
||||||
except TypeError:
|
except TypeError:
|
||||||
current_file_size_mb = 0
|
current_file_size_mb = 0
|
||||||
|
|
||||||
|
@ -1,22 +1,14 @@
|
|||||||
import re
|
|
||||||
from datetime import datetime, timedelta
|
|
||||||
from html import escape
|
|
||||||
from smtplib import SMTPException
|
|
||||||
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth.models import Group
|
|
||||||
from django.core.mail import BadHeaderError, send_mail
|
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.shortcuts import get_object_or_404, redirect, render
|
from django.shortcuts import get_object_or_404, redirect, render
|
||||||
from django.urls import reverse, reverse_lazy
|
from django.urls import reverse, reverse_lazy
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
from django.views.generic import CreateView
|
from django.views.generic import CreateView
|
||||||
|
|
||||||
from cookbook.forms import ImportRecipeForm, InviteLinkForm, Storage, StorageForm
|
from cookbook.forms import ImportRecipeForm, Storage, StorageForm
|
||||||
from cookbook.helper.permission_helper import GroupRequiredMixin, group_required, above_space_limit
|
from cookbook.helper.permission_helper import GroupRequiredMixin, above_space_limit, group_required
|
||||||
from cookbook.models import (InviteLink, MealPlan, MealType, Recipe, RecipeBook, RecipeImport,
|
from cookbook.models import Recipe, RecipeImport, ShareLink, Step
|
||||||
ShareLink, Step, UserPreference, UserSpace)
|
|
||||||
from cookbook.views.edit import SpaceFormMixing
|
|
||||||
from recipes import settings
|
from recipes import settings
|
||||||
|
|
||||||
|
|
||||||
@ -56,24 +48,6 @@ def share_link(request, pk):
|
|||||||
return HttpResponseRedirect(reverse('view_recipe', kwargs={'pk': pk, 'share': link.uuid}))
|
return HttpResponseRedirect(reverse('view_recipe', kwargs={'pk': pk, 'share': link.uuid}))
|
||||||
|
|
||||||
|
|
||||||
# class KeywordCreate(GroupRequiredMixin, CreateView):
|
|
||||||
# groups_required = ['user']
|
|
||||||
# template_name = "generic/new_template.html"
|
|
||||||
# model = Keyword
|
|
||||||
# form_class = KeywordForm
|
|
||||||
# success_url = reverse_lazy('list_keyword')
|
|
||||||
|
|
||||||
# def form_valid(self, form):
|
|
||||||
# form.cleaned_data['space'] = self.request.space
|
|
||||||
# form.save()
|
|
||||||
# return HttpResponseRedirect(reverse('list_keyword'))
|
|
||||||
|
|
||||||
# def get_context_data(self, **kwargs):
|
|
||||||
# context = super(KeywordCreate, self).get_context_data(**kwargs)
|
|
||||||
# context['title'] = _("Keyword")
|
|
||||||
# return context
|
|
||||||
|
|
||||||
|
|
||||||
class StorageCreate(GroupRequiredMixin, CreateView):
|
class StorageCreate(GroupRequiredMixin, CreateView):
|
||||||
groups_required = ['admin']
|
groups_required = ['admin']
|
||||||
template_name = "generic/new_template.html"
|
template_name = "generic/new_template.html"
|
||||||
@ -133,5 +107,3 @@ def create_new_external_recipe(request, import_id):
|
|||||||
)
|
)
|
||||||
|
|
||||||
return render(request, 'forms/edit_import_recipe.html', {'form': form})
|
return render(request, 'forms/edit_import_recipe.html', {'form': form})
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@ import json
|
|||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from django.db.models import Q
|
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
|
||||||
from cookbook.helper.ingredient_parser import IngredientParser
|
from cookbook.helper.ingredient_parser import IngredientParser
|
||||||
from cookbook.helper.permission_helper import group_required
|
from cookbook.helper.permission_helper import group_required
|
||||||
from cookbook.models import ShoppingList, ShoppingListEntry, TelegramBot
|
from cookbook.models import ShoppingListEntry, TelegramBot
|
||||||
|
|
||||||
|
|
||||||
@group_required('user')
|
@group_required('user')
|
||||||
@ -21,7 +20,8 @@ def setup_bot(request, pk):
|
|||||||
create_response = requests.get(f'https://api.telegram.org/bot{bot.token}/setWebhook?url={hook_url}')
|
create_response = requests.get(f'https://api.telegram.org/bot{bot.token}/setWebhook?url={hook_url}')
|
||||||
info_response = requests.get(f'https://api.telegram.org/bot{bot.token}/getWebhookInfo')
|
info_response = requests.get(f'https://api.telegram.org/bot{bot.token}/getWebhookInfo')
|
||||||
|
|
||||||
return JsonResponse({'hook_url': hook_url, 'create_response': json.loads(create_response.content.decode()), 'info_response': json.loads(info_response.content.decode())}, json_dumps_params={'indent': 4})
|
return JsonResponse({'hook_url': hook_url, 'create_response': json.loads(create_response.content.decode()),
|
||||||
|
'info_response': json.loads(info_response.content.decode())}, json_dumps_params={'indent': 4})
|
||||||
|
|
||||||
|
|
||||||
@group_required('user')
|
@group_required('user')
|
||||||
@ -31,7 +31,8 @@ def remove_bot(request, pk):
|
|||||||
remove_response = requests.get(f'https://api.telegram.org/bot{bot.token}/deleteWebhook')
|
remove_response = requests.get(f'https://api.telegram.org/bot{bot.token}/deleteWebhook')
|
||||||
info_response = requests.get(f'https://api.telegram.org/bot{bot.token}/getWebhookInfo')
|
info_response = requests.get(f'https://api.telegram.org/bot{bot.token}/getWebhookInfo')
|
||||||
|
|
||||||
return JsonResponse({'remove_response': json.loads(remove_response.content.decode()), 'info_response': json.loads(info_response.content.decode())}, json_dumps_params={'indent': 4})
|
return JsonResponse({'remove_response': json.loads(remove_response.content.decode()),
|
||||||
|
'info_response': json.loads(info_response.content.decode())}, json_dumps_params={'indent': 4})
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import time
|
|
||||||
from os import getenv
|
from os import getenv
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@ -31,12 +30,12 @@ def terminal_width():
|
|||||||
s = struct.pack('HHHH', 0, 0, 0, 0)
|
s = struct.pack('HHHH', 0, 0, 0, 0)
|
||||||
x = fcntl.ioctl(1, termios.TIOCGWINSZ, s)
|
x = fcntl.ioctl(1, termios.TIOCGWINSZ, s)
|
||||||
width = struct.unpack('HHHH', x)[1]
|
width = struct.unpack('HHHH', x)[1]
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
if width <= 0:
|
if width <= 0:
|
||||||
try:
|
try:
|
||||||
width = int(getenv['COLUMNS'])
|
width = int(getenv['COLUMNS'])
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
if width <= 0:
|
if width <= 0:
|
||||||
width = 80
|
width = 80
|
||||||
|
@ -52,7 +52,7 @@ for p in settings.PLUGINS:
|
|||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
print(e.msg)
|
print(e.msg)
|
||||||
print(f'ERROR failed loading plugin <{p["name"]}> urls, did you forget creating urls.py in your plugin?')
|
print(f'ERROR failed loading plugin <{p["name"]}> urls, did you forget creating urls.py in your plugin?')
|
||||||
except Exception as e:
|
except Exception:
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
print(f'ERROR failed loading urls for plugin <{p["name"]}>')
|
print(f'ERROR failed loading urls for plugin <{p["name"]}>')
|
||||||
traceback.format_exc()
|
traceback.format_exc()
|
||||||
|
Loading…
Reference in New Issue
Block a user