mini deployment
|
@ -146,8 +146,8 @@ USE_TZ = True
|
||||||
# Static files (CSS, JavaScript, Images)
|
# Static files (CSS, JavaScript, Images)
|
||||||
# https://docs.djangoproject.com/en/3.2/howto/static-files/
|
# https://docs.djangoproject.com/en/3.2/howto/static-files/
|
||||||
|
|
||||||
STATIC_URL = '/static/'
|
|
||||||
STATIC_ROOT = '/app/static'
|
STATIC_ROOT = '/app/static'
|
||||||
|
STATIC_URL = '/static/'
|
||||||
|
|
||||||
|
|
||||||
# something for compiling bootstrap
|
# something for compiling bootstrap
|
||||||
|
@ -295,6 +295,6 @@ LOGGING = {
|
||||||
# this is where user uploaded files will go.
|
# this is where user uploaded files will go.
|
||||||
# TODO change this for prod
|
# TODO change this for prod
|
||||||
#MEDIA_ROOT = "/home/plex/Documents/code/python/gawa/media"
|
#MEDIA_ROOT = "/home/plex/Documents/code/python/gawa/media"
|
||||||
MEDIA_ROOT = "media/"
|
MEDIA_ROOT = "/app/media"
|
||||||
MEDIA_URL = "/app/media/"
|
MEDIA_URL = "/media/"
|
||||||
FILE_UPLOAD_TEMP_DIR = "/tmp/gawa/upload"
|
FILE_UPLOAD_TEMP_DIR = "/tmp/gawa/upload"
|
||||||
|
|
|
@ -32,6 +32,7 @@ urlpatterns += i18n_patterns(
|
||||||
|
|
||||||
# use my fancy error pages
|
# use my fancy error pages
|
||||||
# better yet, don't let it come to that
|
# better yet, don't let it come to that
|
||||||
handler400 = 'start.views.Error400'
|
# FIXME these break the server. something is wrong with them
|
||||||
handler404 = 'start.views.Error404'
|
#handler400 = 'start.views.Error400'
|
||||||
handler500 = 'start.views.Error500'
|
#handler404 = 'start.views.Error404'
|
||||||
|
#handler500 = 'start.views.Error500'
|
||||||
|
|
Before Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 6.7 KiB |
Before Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 6.7 KiB |
Before Width: | Height: | Size: 6.7 KiB |
Before Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 6.7 KiB |
Before Width: | Height: | Size: 6.7 KiB |
Before Width: | Height: | Size: 6.7 KiB |
Before Width: | Height: | Size: 6.7 KiB |
Before Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 6.7 KiB |
Before Width: | Height: | Size: 6.7 KiB |
Before Width: | Height: | Size: 6.7 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 6.7 KiB |
Before Width: | Height: | Size: 6.7 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 6.7 KiB |
Before Width: | Height: | Size: 6.7 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 6.7 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 11 KiB |
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 3.2.19 on 2023-06-05 23:01
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('start', '0008_link_status'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='link',
|
||||||
|
name='favicon',
|
||||||
|
field=models.ImageField(blank=True, null=True, upload_to='img/links/favicons'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -97,7 +97,7 @@ class Link(Searchable):
|
||||||
# the actual link
|
# the actual link
|
||||||
url = models.URLField(unique=True, null=False, primary_key=True)
|
url = models.URLField(unique=True, null=False, primary_key=True)
|
||||||
favicon_dir: str = "img/links/favicons"
|
favicon_dir: str = "img/links/favicons"
|
||||||
favicon = models.ImageField(blank=True, upload_to=favicon_dir)
|
favicon = models.ImageField(blank=True, upload_to=favicon_dir, null=True)
|
||||||
status = models.BooleanField(default=False)
|
status = models.BooleanField(default=False)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
@ -110,6 +110,8 @@ class Link(Searchable):
|
||||||
Implements the abstract method of Searchable
|
Implements the abstract method of Searchable
|
||||||
|
|
||||||
Searches for a favicon in the urr, if one is found, it will be stored in MEDIA_ROOT
|
Searches for a favicon in the urr, if one is found, it will be stored in MEDIA_ROOT
|
||||||
|
|
||||||
|
TODO filepathings here suck and are too error prone
|
||||||
"""
|
"""
|
||||||
logger.info(f"regenerating {self.__class__.__name__} object: {self}")
|
logger.info(f"regenerating {self.__class__.__name__} object: {self}")
|
||||||
self.suburl = f"/links#{self.title_en}"
|
self.suburl = f"/links#{self.title_en}"
|
||||||
|
@ -128,14 +130,23 @@ class Link(Searchable):
|
||||||
else:
|
else:
|
||||||
response = requests.get(icons[0].url, stream=True)
|
response = requests.get(icons[0].url, stream=True)
|
||||||
filename: str = f"favicon-{random.randint(0x1000, 0xffff)}.{icons[0].format}"
|
filename: str = f"favicon-{random.randint(0x1000, 0xffff)}.{icons[0].format}"
|
||||||
with open(f"{settings.MEDIA_ROOT}/{self.favicon_dir}/{filename}", 'wb') as image:
|
try:
|
||||||
for chunk in response.iter_content(1024):
|
with open(f"/tmp/{filename}", 'wb') as image:
|
||||||
image.write(chunk)
|
for chunk in response.iter_content(1024):
|
||||||
logger.debug(image)
|
image.write(chunk)
|
||||||
with open(f"{settings.MEDIA_ROOT}/{self.favicon_dir}/{filename}", 'rb') as image:
|
logger.debug(image)
|
||||||
self.favicon.save(filename, File(image))
|
with open(f"/tmp/{filename}", 'rb') as image:
|
||||||
logger.info(f"downloaded favicon for {self}")
|
self.favicon.save(filename, File(image))
|
||||||
self.status = True
|
logger.info(f"downloaded favicon for {self}")
|
||||||
|
self.status = True
|
||||||
|
|
||||||
|
except FileNotFoundError as fe:
|
||||||
|
logger.error(f"cant write favicon to file for {self}: {fe}")
|
||||||
|
self.favicon = None
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.warn(f"Unexpected Exception while downloading {self}: {e.with_traceback(None)}")
|
||||||
|
self.favicon = None
|
||||||
|
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
|
|