Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pandabuilder committed Aug 8, 2024
1 parent 28b7282 commit 189efd2
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 45 deletions.
8 changes: 4 additions & 4 deletions ci-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
-r requirements.txt
mypy==1.10.1
ruff==0.5.1
django-stubs==5.0.2
types-requests==2.32.0.20240622
mypy==1.11.1
ruff==0.5.5
django-stubs==5.0.4
types-requests==2.32.0.20240712
types-pytz==2024.1.0.20240417
types-python-dateutil==2.9.0.20240316
unittest-xml-reporting==3.2.0
5 changes: 3 additions & 2 deletions core/base/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,17 +475,18 @@ def get_zip_fileinfo_for_gallery(filepath: str) -> tuple[int, int]:

def available_filename(root: str, filename: str) -> str:
filename_full = os.path.join(root, filename)
file_head, file_tail = os.path.split(filename)

extra_text = 2
if os.path.isfile(filename_full):
while (
os.path.isfile(
os.path.splitext(filename_full)[0] + "-" + str(extra_text)
os.path.splitext(os.path.join(root, os.path.join(file_head, file_tail[0:251 - 1 - len(str(extra_text))])))[0] + "-" + str(extra_text)
+ os.path.splitext(filename_full)[1])
):
extra_text += 1
return (
os.path.splitext(filename)[0] + "-" + str(extra_text) + os.path.splitext(filename)[1]
os.path.splitext(os.path.join(file_head, file_tail[0:251 - 1 - len(str(extra_text))]))[0] + "-" + str(extra_text) + os.path.splitext(filename)[1]
)
else:
return filename
Expand Down
5 changes: 3 additions & 2 deletions core/providers/fakku/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def process_regular_gallery_page(self, link: str, response_text: str) -> Optiona
gallery.posted = self.parse_posted_date_from_feed(constants.aux_feed_url, gallery.gid)
if self.own_settings.get_posted_date_from_wayback and gallery.posted is None:
gallery.posted = get_oldest_entry_from_wayback(link)
gallery.title = gallery_container.find("h1", class_="block col-span-full text-2xl pt-2 font-semibold text-brand-light text-left dark:text-white dark:link:text-white pt-0").get_text()
gallery.title = gallery_container.find("h1", class_=re.compile("block col-span-full")).get_text()

description_container = soup.find("meta", property="og:description")
if description_container:
Expand Down Expand Up @@ -261,8 +261,9 @@ def get_values_from_gallery_link_list(self, links: list[str]) -> list[GalleryDat

logger.info(
"Calling API ({}). "
"Gallery: {}, total galleries: {}".format(
"Gallery URL: {}, count: {}, total galleries: {}".format(
self.name,
element,
i + 1,
len(links)
)
Expand Down
8 changes: 2 additions & 6 deletions core/providers/fakku/wanted.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ def wanted_generator(settings: 'Settings', attrs: 'AttributeManager'):
# Values that can be set:
# subpath: subpath to search. (books, tags/doujin)
# container_tag: Tag for the main container for each individual link. (div, span)
# container_attribute_name: Attribute name for the main container for each individual link. (class)
# container_attribute_value: Attribute value for the main container for each individual link. (content-meta)
# link_tag: Tag for the link container inside the container. (a, span)
# link_attribute_name: Attribute name for the link container inside the container. (a, span)
# link_attribute_value: Attribute value for the link container inside the container. (href, src)
# url_attribute_name: Attribute name for the URL container inside the container. (href, src)
# link_attribute_get_text: Boolean to specify if it should get the text inside a tag. (True, False)
for query_name, query_values in queries.items():
Expand All @@ -71,7 +67,7 @@ def wanted_generator(settings: 'Settings', attrs: 'AttributeManager'):
break
subpath = query_values['subpath']

if not {'container_tag', 'container_attribute_name', 'container_attribute_value'}.issubset(query_values.keys()):
if not {'container_tag'}.issubset(query_values.keys()):
logger.error('Cannot query without html container definition for {}'.format(query_name))
break
container_tag = query_values['container_tag']
Expand All @@ -83,7 +79,7 @@ def wanted_generator(settings: 'Settings', attrs: 'AttributeManager'):
if 'link_attribute_get_text' in query_values and query_values['link_attribute_get_text']:
get_text_from_container = True
else:
if not {'link_tag', 'link_attribute_name', 'link_attribute_value', 'url_attribute_name'}.issubset(
if not {'link_tag', 'url_attribute_name'}.issubset(
query_values.keys()):
logger.error('Cannot query without link container definition for {}'.format(query_name))
break
Expand Down
8 changes: 4 additions & 4 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
-r requirements.txt
django-debug-toolbar==4.4.6
django-unused-media==0.2.2
mypy==1.10.1
ruff==0.5.1
django-stubs==5.0.2
types-requests==2.32.0.20240622
mypy==1.11.1
ruff==0.5.5
django-stubs==5.0.4
types-requests==2.32.0.20240712
types-pytz==2024.1.0.20240417
types-python-dateutil==2.9.0.20240316
django-cors-headers==4.4.0
Expand Down
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ python-dateutil==2.9.0.post0
twitter==1.19.6
beautifulsoup4==4.12.3
CherryPy==18.10.0
Django==5.0.7
django-compressor==4.5
Django==5.0.8
django-compressor==4.5.1
Pillow==10.4.0
rarfile==4.2
py7zr==0.21.1
Expand All @@ -19,11 +19,11 @@ django-vite==3.0.4
elasticsearch==8.14.0
elasticsearch-dsl==8.14.0
django-simple-history==3.7.0
PyYAML==6.0.1
PyYAML==6.0.2
deckar01-ratelimit==3.0.2
pytz==2024.1
# For image operations in edge cases
numpy==2.0.0
numpy==2.0.1
# Optional packages (depending on features wanted):
# imagehash==4.3.1
# PySocks==1.7.1
2 changes: 1 addition & 1 deletion viewer/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def build_attrs(self, *args: Any, **kwargs: Any):

class MatchesModelChoiceField(ModelChoiceField):
def label_from_instance(self, obj: Gallery) -> str: # type: ignore[override]
first_artist_tag = Tag.objects.filter(gallery=obj.id).first_artist_tag()
first_artist_tag = Tag.objects.first_artist_tag(gallery=obj.id)
tag_name = ''
if first_artist_tag:
tag_name = first_artist_tag.name
Expand Down
24 changes: 18 additions & 6 deletions viewer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,26 @@ def as_postgresql(self, qn: SQLCompiler, connection: BaseDatabaseWrapper) -> tup
models.FileField.register_lookup(SpacedSearch)


class TagQuerySet(models.QuerySet):
class TagQuerySet(models.QuerySet['Tag']):
def are_custom(self) -> QuerySet:
return self.filter(source='user')

def not_custom(self) -> QuerySet:
return self.exclude(source='user')

def first_artist_tag(self) -> Optional['Tag']:
return self.filter(scope__exact='artist').first()
def first_artist_tag(self, **kwargs: typing.Any) -> Optional['Tag']:
return self.filter(scope__exact='artist', **kwargs).first()


class TagManager(models.Manager['Tag']):
def get_queryset(self) -> TagQuerySet:
return TagQuerySet(self.model, using=self._db)

def are_custom(self) -> QuerySet:
return self.get_queryset().are_custom()

def first_artist_tag(self, **kwargs: typing.Any) -> Optional['Tag']:
return self.get_queryset().first_artist_tag(**kwargs)


class GalleryQuerySet(models.QuerySet):
Expand Down Expand Up @@ -621,7 +632,7 @@ class Tag(models.Model):
'Source', max_length=50, blank=True, null=True, default='web')
create_date = models.DateTimeField(auto_now_add=True)

objects = TagQuerySet.as_manager()
objects = TagManager()

class Meta:
ordering = ['-id']
Expand Down Expand Up @@ -1560,9 +1571,10 @@ class Archive(models.Model):
through='ArchiveTag', through_fields=('archive', 'tag')
)

alternative_sources = models.ManyToManyField(
alternative_sources: models.ManyToManyField = models.ManyToManyField(
Gallery, related_name="alternative_sources",
blank=True, default='')

details = models.TextField(
blank=True, null=True, default='')

Expand Down Expand Up @@ -4018,7 +4030,7 @@ class WantedGallery(models.Model):
wanted_tags_exclusive_scope = models.BooleanField(blank=True, default=False)
exclusive_scope_name = models.CharField(max_length=200, blank=True, default='')
wanted_tags_accept_if_none_scope = models.CharField(max_length=200, blank=True, default='')
unwanted_tags = models.ManyToManyField(Tag, blank=True, related_name="unwanted_tags")
unwanted_tags: models.ManyToManyField = models.ManyToManyField(Tag, blank=True, related_name="unwanted_tags")
category = models.CharField(
max_length=20, blank=True, null=True, default='')
wanted_providers: models.ManyToManyField = models.ManyToManyField('Provider', blank=True)
Expand Down
10 changes: 5 additions & 5 deletions viewer/views/collaborators.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,16 +383,16 @@ def filter_by_marks(archives: QuerySet[Archive], params: QueryDict) -> tuple[Que
archives = archives.filter(manage_entries__mark_check=True)
mark_filters = True
if 'mark_reason' in params and params["mark_reason"]:
archives = archives.filter(manage_entries__mark_reason__contains=params["mark_reason"])
archives = archives.filter(manage_entries__mark_reason__contains=str(params["mark_reason"]))
mark_filters = True
if 'mark_comment' in params and params["mark_comment"]:
archives = archives.filter(manage_entries__mark_comment__contains=params["mark_comment"])
archives = archives.filter(manage_entries__mark_comment__contains=str(params["mark_comment"]))
mark_filters = True
if 'mark_extra' in params and params["mark_extra"]:
archives = archives.filter(manage_entries__mark_extra__contains=params["mark_extra"])
archives = archives.filter(manage_entries__mark_extra__contains=str(params["mark_extra"]))
mark_filters = True
if 'origin' in params and params["origin"]:
archives = archives.filter(manage_entries__origin=params["origin"])
archives = archives.filter(manage_entries__origin=str(params["origin"]))
mark_filters = True
priority_to = params.get("priority_to", None)
if priority_to is not None and priority_to != '':
Expand Down Expand Up @@ -537,7 +537,7 @@ def manage_archives(request: HttpRequest) -> HttpResponse:
)
elif 'delete_archives' in p and request.user.has_perm('viewer.delete_archive'):
for archive in archives:
message = 'Deleting archive: {}, link: {}, with it\'s file: {}'.format(
message = 'Deleting archive: {}, link: {}, with its file: {}'.format(
archive.title, archive.get_absolute_url(),
archive.zipped.path
)
Expand Down
6 changes: 3 additions & 3 deletions viewer/views/exp.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get_archive_data(data: QueryDict) -> 'QuerySet[Archive]':
Q(title__ss=q_formatted) | Q(title_jpn__ss=q_formatted)
)

if 'filename' in data:
if 'filename' in data and isinstance(data['filename'], str):
results = results.filter(zipped__icontains=data['filename'])
rating_from = data.get("rating_from")
if rating_from is not None:
Expand All @@ -77,9 +77,9 @@ def get_archive_data(data: QueryDict) -> 'QuerySet[Archive]':
if 'posted_to' in data:
results = results.filter(gallery__posted__lte=data['posted_to'])
if 'match_type' in data:
results = results.filter(match_type__icontains=data['match_type'])
results = results.filter(match_type__icontains=str(data['match_type']))
if 'source_type' in data:
results = results.filter(source_type__icontains=data['source_type'])
results = results.filter(source_type__icontains=str(data['source_type']))
if 'extracted' in data:
results = results.filter(extracted=True)

Expand Down
16 changes: 8 additions & 8 deletions viewer/views/head.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,11 +760,11 @@ def filter_galleries(request: HttpRequest, session_filters: dict[str, str], requ
if request_filters["category"]:
results = results.filter(category__icontains=request_filters["category"])
if request_filters["expunged"]:
results = results.filter(expunged=request_filters["expunged"])
results = results.filter(expunged=bool(request_filters["expunged"]))
if request_filters["disowned"]:
results = results.filter(disowned=request_filters["disowned"])
results = results.filter(disowned=bool(request_filters["disowned"]))
if request_filters["fjord"]:
results = results.filter(fjord=request_filters["fjord"])
results = results.filter(fjord=bool(request_filters["fjord"]))
if request_filters["uploader"]:
results = results.filter(uploader=request_filters["uploader"])
if request_filters["provider"]:
Expand All @@ -784,7 +784,7 @@ def filter_galleries(request: HttpRequest, session_filters: dict[str, str], requ
if request_filters["only_used"]:
results = results.only_used_galleries() # type: ignore
if request_filters["hidden"]:
results = results.filter(hidden=request_filters["hidden"])
results = results.filter(hidden=bool(request_filters["hidden"]))
if "not_normal" not in request_filters or not request_filters["not_normal"]:
results = results.eligible_for_use() # type: ignore
else:
Expand Down Expand Up @@ -1910,13 +1910,13 @@ def filter_galleries_simple(params: dict[str, str]) -> QuerySet[Gallery]:
if params["category"]:
results = results.filter(category__icontains=params["category"])
if params["expunged"]:
results = results.filter(expunged=params["expunged"])
results = results.filter(expunged=bool(params["expunged"]))
if params["disowned"]:
results = results.filter(disowned=params["disowned"])
results = results.filter(disowned=bool(params["disowned"]))
if params["hidden"]:
results = results.filter(hidden=params["hidden"])
results = results.filter(hidden=bool(params["hidden"]))
if params["fjord"]:
results = results.filter(fjord=params["fjord"])
results = results.filter(fjord=bool(params["fjord"]))
if params["uploader"]:
results = results.filter(uploader=params["uploader"])
if params["dl_type"]:
Expand Down

0 comments on commit 189efd2

Please sign in to comment.