refactor
This commit is contained in:
parent
5dc6267cfc
commit
01050792d0
@ -7,6 +7,7 @@ from django.db import models
|
||||
from django.urls import reverse
|
||||
from django.core.files import File
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.db.models import Q
|
||||
from datetime import datetime
|
||||
|
||||
from imagebot import settings
|
||||
@ -61,3 +62,13 @@ class Image(models.Model):
|
||||
file_hash=file_hash
|
||||
)
|
||||
os.remove(path)
|
||||
|
||||
@staticmethod
|
||||
def get_image_for_descriptor():
|
||||
image = Image.objects.filter(Q(alt_text=None) | Q(title=None)).first()
|
||||
return image
|
||||
|
||||
@staticmethod
|
||||
def get_image_to_post():
|
||||
image = Image.objects.filter(Q(alt_text__isnull=False) & Q(title__isnull=False)).first()
|
||||
return image
|
||||
|
@ -5,13 +5,8 @@ from django.urls import reverse
|
||||
|
||||
from idescriptor.forms import ImageForm
|
||||
from idescriptor.models import Image
|
||||
from django.db.models import Q
|
||||
|
||||
|
||||
def get_image_for_descriptor():
|
||||
image = Image.objects.filter(Q(alt_text=None) | Q(title=None)).first()
|
||||
return image
|
||||
|
||||
def list_images(request):
|
||||
images = Image.objects.all()
|
||||
context = {"images": images}
|
||||
@ -29,7 +24,7 @@ class ImageFormView(UpdateView):
|
||||
|
||||
def index(request):
|
||||
"""View function for home page of site."""
|
||||
image_to_describe = get_image_for_descriptor()
|
||||
image_to_describe = Image.get_image_for_descriptor()
|
||||
|
||||
if request.method == "POST":
|
||||
action = request.POST.get("action")
|
||||
|
Loading…
Reference in New Issue
Block a user