fixed importer and copy recipe

This commit is contained in:
vabene1111
2022-09-23 16:43:22 +02:00
parent 13b91e5b91
commit 12a8582a9a
2 changed files with 6 additions and 6 deletions

View File

@@ -21,7 +21,7 @@ def get_from_scraper(scrape, request):
# converting the scrape_me object to the existing json format based on ld+json # converting the scrape_me object to the existing json format based on ld+json
recipe_json = {} recipe_json = {}
try: try:
recipe_json['name'] = parse_name(scrape.title() or None) recipe_json['name'] = parse_name(scrape.title()[:128] or None)
except Exception: except Exception:
recipe_json['name'] = None recipe_json['name'] = None
if not recipe_json['name']: if not recipe_json['name']:

View File

@@ -709,7 +709,7 @@ class RecipeOverviewSerializer(RecipeBaseSerializer):
class Meta: class Meta:
model = Recipe model = Recipe
fields = ( fields = (
'id', 'name', 'description', 'image', 'keywords', 'working_time', 'id', 'name', 'description', 'image', 'keywords', 'working_time',
'waiting_time', 'created_by', 'created_at', 'updated_at', 'waiting_time', 'created_by', 'created_at', 'updated_at',
'internal', 'servings', 'servings_text', 'rating', 'last_cooked', 'new', 'recent' 'internal', 'servings', 'servings_text', 'rating', 'last_cooked', 'new', 'recent'
) )
@@ -721,8 +721,8 @@ class RecipeSerializer(RecipeBaseSerializer):
steps = StepSerializer(many=True) steps = StepSerializer(many=True)
keywords = KeywordSerializer(many=True) keywords = KeywordSerializer(many=True)
shared = UserSerializer(many=True, required=False) shared = UserSerializer(many=True, required=False)
rating = CustomDecimalField(required=False, allow_null=True) rating = CustomDecimalField(required=False, allow_null=True, read_only=True)
last_cooked = serializers.DateTimeField(required=False, allow_null=True) last_cooked = serializers.DateTimeField(required=False, allow_null=True, read_only=True)
class Meta: class Meta:
model = Recipe model = Recipe
@@ -1124,14 +1124,14 @@ class AccessTokenSerializer(serializers.ModelSerializer):
token = serializers.SerializerMethodField('get_token') token = serializers.SerializerMethodField('get_token')
def create(self, validated_data): def create(self, validated_data):
validated_data['token'] = f'tda_{str(uuid.uuid4()).replace("-","_")}' validated_data['token'] = f'tda_{str(uuid.uuid4()).replace("-", "_")}'
validated_data['user'] = self.context['request'].user validated_data['user'] = self.context['request'].user
return super().create(validated_data) return super().create(validated_data)
def get_token(self, obj): def get_token(self, obj):
if (timezone.now() - obj.created).seconds < 15: if (timezone.now() - obj.created).seconds < 15:
return obj.token return obj.token
return f'tda_************_******_***********{obj.token[len(obj.token)-4:]}' return f'tda_************_******_***********{obj.token[len(obj.token) - 4:]}'
class Meta: class Meta:
model = AccessToken model = AccessToken