Ejemplo n.º 1
0
 def refresh_work(self, request, queryset):
     if request.POST.get('confirm'):  # Confirmed
         downloaded_titles = []
         for obj in queryset:
             chosen_poster = request.POST.get('chosen_poster_{:d}'.format(obj.id))
             if not chosen_poster:
                 continue
             if obj.retrieve_poster(chosen_poster):
                 downloaded_titles.append(obj.title)
         if downloaded_titles:
             self.message_user(
                 request,
                 "Des posters ont été trouvés pour les anime suivants : %s." % ', '.join(downloaded_titles))
         else:
             self.message_user(request, "Aucun poster n'a été trouvé, essayez de changer le titre.")
         return None
     bundle = []
     for work in queryset:
         bundle.append((work.id, work.title, get_potential_posters(work)))
     context = {
         'queryset': queryset,
         'bundle': bundle,
         'opts': self.model._meta,
         'action_checkbox_name': helpers.ACTION_CHECKBOX_NAME
     }
     return TemplateResponse(request, 'admin/refresh_poster_confirmation.html', context)
Ejemplo n.º 2
0
    def test_get_potential_posters(self, mocked_search):
        with self.subTest('When MAL returns no poster'):
            expected = [{'current': True, 'url': self.kiznaiver.ext_poster}]
            mocked_search.return_value = NonCallableMock(poster=None)
            # Let the magic occur.
            posters = get_potential_posters(self.kiznaiver)
            # In this case, `get_potential_posters` cannot fix the current poster.
            self.assertCountEqual(posters, expected)

        with self.subTest('When MAL returns a poster'):
            expected = [{
                'current': True,
                'url': self.kiznaiver.ext_poster
            }, {
                'current': False,
                'url': 'kiznaiver_mal_poster_url'
            }]
            mocked_search.return_value = NonCallableMock(
                poster=expected[1]['url'])
            posters = get_potential_posters(self.kiznaiver)
            # In this case, `get_potential_posters` should return a list of two posters, i.e. old external, MAL's one.
            self.assertCountEqual(posters, expected)
Ejemplo n.º 3
0
 def refresh_work(self, request, queryset):
     if request.POST.get('confirm'):  # Confirmed
         downloaded_titles = []
         for obj in queryset:
             if obj.category.slug == 'anime':
                 title = retrieve_poster(obj, request.POST.get('chosen_poster_%d' % obj.id))
                 if title:
                     downloaded_titles.append(title)
         if downloaded_titles:
             self.message_user(request, "Des posters ont été trouvés pour les anime suivants : %s." % ', '.join(downloaded_titles))
         else:
             self.message_user(request, "Aucun poster n'a été trouvé, essayez de changer le titre.")
         return None
     bundle = []
     for work in queryset:
         bundle.append((work.id, work.title, get_potential_posters(work)))
     context = {
         'queryset': queryset,
         'bundle': bundle,
         'opts': self.model._meta,
         'action_checkbox_name': helpers.ACTION_CHECKBOX_NAME
     }
     return TemplateResponse(request, 'admin/refresh_poster_confirmation.html', context)