From 289d3cb82479c6529ffad133dc61f389f8a46ce7 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Mon, 5 Jun 2023 21:22:52 +0200 Subject: [PATCH] favicon getter works --- gawa/start/migrations/0007_link_favicon.py | 18 ++++++++++++++++++ gawa/start/models.py | 6 ++++-- 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 gawa/start/migrations/0007_link_favicon.py diff --git a/gawa/start/migrations/0007_link_favicon.py b/gawa/start/migrations/0007_link_favicon.py new file mode 100644 index 0000000..6c4f097 --- /dev/null +++ b/gawa/start/migrations/0007_link_favicon.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.19 on 2023-06-05 17:48 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('start', '0006_alter_searchable_title_en'), + ] + + operations = [ + migrations.AddField( + model_name='link', + name='favicon', + field=models.ImageField(blank=True, upload_to='img/links/favicons'), + ), + ] diff --git a/gawa/start/models.py b/gawa/start/models.py index 7d2ad85..4300a0d 100644 --- a/gawa/start/models.py +++ b/gawa/start/models.py @@ -106,6 +106,8 @@ class Link(Searchable): regenerate a object Implements the abstract method of Searchable + + Searches for a favicon in the urr, if one is found, it will be stored in MEDIA_ROOT """ logger.info(f"regenerating {self.__class__.__name__} object: {self}") self.suburl = f"/links#{self.title_en}" @@ -119,11 +121,11 @@ class Link(Searchable): filename: str = f"favicon-{random.randint(0x1000, 0xffff)}.{icons[0].format}" logger.debug(response) logger.debug(filename) - with open(f"{settings.FILE_UPLOAD_TEMP_DIR}/{filename}", 'wb') as image: + with open(f"{settings.MEDIA_ROOT}/{filename}", 'wb') as image: for chunk in response.iter_content(1024): image.write(chunk) logger.debug(image) - with open(f"{settings.FILE_UPLOAD_TEMP_DIR}/{filename}", 'rb') as image: + with open(f"{settings.MEDIA_ROOT}/{filename}", 'rb') as image: self.favicon.save(filename, File(image)) #self.favicon.save(f"favicon-{self.title_en}", favicon.get(self.url, timeout=2))