favicon getter works
This commit is contained in:
parent
9c5d78ac2c
commit
289d3cb824
|
@ -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'),
|
||||
),
|
||||
]
|
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue