Skip to content

Commit

Permalink
Merge pull request #583 from WebarchivCZ/updates
Browse files Browse the repository at this point in the history
Session age, pip bumps, TC seeds, #579, #576, #569, #582
  • Loading branch information
Fasand authored May 10, 2021
2 parents 990b7a4 + 8cd5858 commit 0e244bc
Show file tree
Hide file tree
Showing 28 changed files with 13,710 additions and 7,530 deletions.
8 changes: 4 additions & 4 deletions Seeder/blacklists/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class ListView(BlacklistView, TemplateView):

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
last_change = timezone.now().replace(microsecond=0) -\
models.Blacklist.last_change().replace(microsecond=0)

context['last_change'] = last_change
last_change = models.Blacklist.last_change()
if last_change:
context['last_change'] = (timezone.now().replace(microsecond=0) -
last_change.replace(microsecond=0))
context['blacklists'] = models.Blacklist.objects.all()
return context

Expand Down
3 changes: 3 additions & 0 deletions Seeder/core/dashboard_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ def get_queryset(self):
random.seed(str(self.user) + str(timezone.now().date()))
# Include all sources, both owned by user and not
qa_sources = source_models.Source.objects.needs_qa()
# Don't continue if there are no QA sources
if qa_sources.count() == 0:
return qa_sources
# Randomly select up to N sources for QA with at most M tries
random_qa = set() # collect pks
tries = 0
Expand Down
15 changes: 11 additions & 4 deletions Seeder/harvests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from itertools import chain
from datetime import date
from django.contrib import messages

from django.db import models
from django.utils.translation import ugettext_lazy as _
Expand Down Expand Up @@ -96,7 +97,7 @@ def get_custom_seeds(self):
return set(self.custom_seeds.splitlines())

def get_custom_sources_seeds(self):
seeds = Seed.objects.archiving().filter(
seeds = Seed.objects.filter(
source__in=self.custom_sources.all())
return set(seeds.values_list('url', flat=True)) - self.get_blacklisted()

Expand Down Expand Up @@ -341,8 +342,12 @@ def freeze_seeds(self):
"""
Freezes the seeds to preserve them for later use
"""
self.seeds_frozen = '\n'.join(self.get_seeds())
self.save()
seeds = self.get_seeds()
if len(seeds) > 0:
self.seeds_frozen = '\n'.join(seeds)
self.save()
return True # frozen correctly
return False # not frozen

@property
def is_oneshot(self):
Expand Down Expand Up @@ -496,4 +501,6 @@ def freeze_urls(sender, instance, **kwargs):
:type instance: Harvest
"""
if instance.status == Harvest.STATE_RUNNING and not instance.seeds_frozen:
instance.freeze_seeds()
# If cannot freeze correctly, reset Harvest status
if not instance.freeze_seeds():
instance.status = Harvest.STATE_PLANNED
1 change: 1 addition & 0 deletions Seeder/harvests/templates/topic_collection.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ <h4>{% trans 'Seeds' %}</h4>
<h4>{% trans 'Links' %}:</h4>
<a href="{% url 'harvests:topic_collection_edit' pk=object.pk %}" class="btn btn-primary btn-warning btn-block">{% trans 'Edit' %}</a>
<a href="{% url 'harvests:topic_collection_history' pk=object.pk %}" class="btn btn-primary btn-info btn-block">{% trans 'History' %}</a>
<a href="{% url 'harvests:topic_collection_urls' pk=object.pk %}" class="btn btn-primary btn-info btn-block" target="_blank">{% trans 'Seed URLs' %}</a>
<br />
<form action='{% url 'harvests:topic_collection_update_slug' pk=object.pk %}' method='post'>
{% csrf_token %}
Expand Down
2 changes: 2 additions & 0 deletions Seeder/harvests/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def to_url(self, value):
name='topic_collection_edit'),
path('<int:pk>/collection_detail', CollectionDetail.as_view(),
name='topic_collection_detail'),
path('<int:pk>/collection_urls', CollectionListUrls.as_view(),
name='topic_collection_urls'),
path('<int:pk>/collection_history', CollectionHistory.as_view(),
name='topic_collection_history'),
path('<int:pk>/toggle_publish', CollectionTogglePublish.as_view(),
Expand Down
16 changes: 15 additions & 1 deletion Seeder/harvests/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ class ReorderCollections(View):
def get(self, request, *args, **kwargs):
collections = models.TopicCollection.objects.order_by('order')
for i, tc in enumerate(collections):
tc.order = i+1
tc.order = i + 1
tc.save()
return HttpResponseRedirect(reverse('harvests:topic_collection_list'))

Expand All @@ -434,6 +434,20 @@ class CollectionDetail(TCView, DetailView, CommentViewGeneric):
template_name = 'topic_collection.html'


class CollectionListUrls(TCView, DetailView, TemplateView):
"""
List all seeds for a specific topic collection.
"""
template_name = 'urls.html'

def get_context_data(self, **kwargs):
self.object = self.get_object()
context = super().get_context_data(**kwargs)
context['head_lines'] = [f"# {self.object.title}"]
context['urls'] = self.object.get_seeds()
return context


class CollectionHistory(TCView, generic_views.HistoryView):
"""
History of changes to TopicCollections
Expand Down
Loading

0 comments on commit 0e244bc

Please sign in to comment.