rescrape
This commit is contained in:
parent
8fa1ba05a7
commit
7cb4a376ce
16 changed files with 151 additions and 21 deletions
|
@ -22,8 +22,24 @@
|
||||||
|
|
||||||
<section id="content" class="container">
|
<section id="content" class="container">
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
|
{% if is_update and form.source_site.value != 'in-site' %}
|
||||||
|
<div style="float:right;padding-left:16px">
|
||||||
|
<div class="aside-section-wrapper">
|
||||||
|
<div class="action-panel">
|
||||||
|
<div class="action-panel__label">{% trans '源网站' %}: <a href="{{ form.source_url.value }}">{{ form.source_site.value }}</a></div>
|
||||||
|
<div class="action-panel__button-group">
|
||||||
|
<form method="post" action="{% url 'books:rescrape' form.id.value %}">
|
||||||
|
{% csrf_token %}
|
||||||
|
<input class="button" type="submit" value="{% trans '从源网站重新抓取' %}">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<div class="single-section-wrapper" id="main">
|
<div class="single-section-wrapper" id="main">
|
||||||
<a href="{% url 'books:scrape' %}" class="single-section-wrapper__link single-section-wrapper__link--secondary">{% trans '>>> 试试一键剽取~ <<<' %}</a>
|
{% comment %} <a href="{% url 'books:scrape' %}" class="single-section-wrapper__link single-section-wrapper__link--secondary">{% trans '>>> 试试一键剽取~ <<<' %}</a> {% endcomment %}
|
||||||
<form class="entity-form" action="{{ submit_url }}" method="post" enctype="multipart/form-data">
|
<form class="entity-form" action="{{ submit_url }}" method="post" enctype="multipart/form-data">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form.media }}
|
{{ form.media }}
|
||||||
|
|
|
@ -8,6 +8,7 @@ urlpatterns = [
|
||||||
path('<int:id>/', retrieve, name='retrieve'),
|
path('<int:id>/', retrieve, name='retrieve'),
|
||||||
path('update/<int:id>/', update, name='update'),
|
path('update/<int:id>/', update, name='update'),
|
||||||
path('delete/<int:id>/', delete, name='delete'),
|
path('delete/<int:id>/', delete, name='delete'),
|
||||||
|
path('rescrape/<int:id>/', rescrape, name='rescrape'),
|
||||||
path('mark/', create_update_mark, name='create_update_mark'),
|
path('mark/', create_update_mark, name='create_update_mark'),
|
||||||
path('wish/<int:id>/', wish, name='wish'),
|
path('wish/<int:id>/', wish, name='wish'),
|
||||||
re_path('(?P<book_id>[0-9]+)/mark/list/(?:(?P<following_only>\\d+))?', retrieve_mark_list, name='retrieve_mark_list'),
|
re_path('(?P<book_id>[0-9]+)/mark/list/(?:(?P<following_only>\\d+))?', retrieve_mark_list, name='retrieve_mark_list'),
|
||||||
|
|
|
@ -19,6 +19,7 @@ from .forms import *
|
||||||
from .forms import BookMarkStatusTranslator
|
from .forms import BookMarkStatusTranslator
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from collection.models import CollectionItem
|
from collection.models import CollectionItem
|
||||||
|
from common.scraper import get_scraper_by_url, get_normalized_url
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -89,6 +90,18 @@ def create(request):
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def rescrape(request, id):
|
||||||
|
if request.method != 'POST':
|
||||||
|
return HttpResponseBadRequest()
|
||||||
|
item = get_object_or_404(Book, pk=id)
|
||||||
|
url = get_normalized_url(item.source_url)
|
||||||
|
scraper = get_scraper_by_url(url)
|
||||||
|
scraper.scrape(url)
|
||||||
|
form = scraper.save(request_user=request.user, instance=item)
|
||||||
|
return redirect(reverse("books:retrieve", args=[form.instance.id]))
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def update(request, id):
|
def update(request, id):
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
|
@ -99,6 +112,7 @@ def update(request, id):
|
||||||
'books/create_update.html',
|
'books/create_update.html',
|
||||||
{
|
{
|
||||||
'form': form,
|
'form': form,
|
||||||
|
'is_update': True,
|
||||||
'title': _('修改书籍'),
|
'title': _('修改书籍'),
|
||||||
'submit_url': reverse("books:update", args=[book.id]),
|
'submit_url': reverse("books:update", args=[book.id]),
|
||||||
# provided for frontend js
|
# provided for frontend js
|
||||||
|
@ -127,6 +141,7 @@ def update(request, id):
|
||||||
'books/create_update.html',
|
'books/create_update.html',
|
||||||
{
|
{
|
||||||
'form': form,
|
'form': form,
|
||||||
|
'is_update': True,
|
||||||
'title': _('修改书籍'),
|
'title': _('修改书籍'),
|
||||||
'submit_url': reverse("books:update", args=[book.id]),
|
'submit_url': reverse("books:update", args=[book.id]),
|
||||||
# provided for frontend js
|
# provided for frontend js
|
||||||
|
|
|
@ -107,6 +107,7 @@ def update(request, id):
|
||||||
'create_update.html',
|
'create_update.html',
|
||||||
{
|
{
|
||||||
'form': form,
|
'form': form,
|
||||||
|
'is_update': True,
|
||||||
'title': page_title,
|
'title': page_title,
|
||||||
'submit_url': reverse("collection:update", args=[collection.id]),
|
'submit_url': reverse("collection:update", args=[collection.id]),
|
||||||
# provided for frontend js
|
# provided for frontend js
|
||||||
|
@ -130,6 +131,7 @@ def update(request, id):
|
||||||
'create_update.html',
|
'create_update.html',
|
||||||
{
|
{
|
||||||
'form': form,
|
'form': form,
|
||||||
|
'is_update': True,
|
||||||
'title': page_title,
|
'title': page_title,
|
||||||
'submit_url': reverse("collection:update", args=[collection.id]),
|
'submit_url': reverse("collection:update", args=[collection.id]),
|
||||||
# provided for frontend js
|
# provided for frontend js
|
||||||
|
|
|
@ -211,11 +211,11 @@ class AbstractScraper:
|
||||||
return raw_img, ext
|
return raw_img, ext
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def save(cls, request_user):
|
def save(cls, request_user, instance=None):
|
||||||
entity_cover = {
|
entity_cover = {
|
||||||
'cover': SimpleUploadedFile('temp.' + cls.img_ext, cls.raw_img)
|
'cover': SimpleUploadedFile('temp.' + cls.img_ext, cls.raw_img)
|
||||||
} if cls.img_ext is not None else None
|
} if cls.img_ext is not None else None
|
||||||
form = cls.form_class(cls.raw_data, entity_cover)
|
form = cls.form_class(data=cls.raw_data, files=entity_cover, instance=instance)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
form.instance.last_editor = request_user
|
form.instance.last_editor = request_user
|
||||||
form.instance._change_reason = 'scrape'
|
form.instance._change_reason = 'scrape'
|
||||||
|
|
|
@ -181,16 +181,16 @@ class SpotifyAlbumScraper(AbstractScraper):
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@classmethod
|
# @classmethod
|
||||||
def save(cls, request_user):
|
# def save(cls, request_user):
|
||||||
form = super().save(request_user)
|
# form = super().save(request_user)
|
||||||
# task = Thread(
|
# task = Thread(
|
||||||
# target=cls.add_tracks,
|
# target=cls.add_tracks,
|
||||||
# args=(form.instance, request_user),
|
# args=(form.instance, request_user),
|
||||||
# daemon=True
|
# daemon=True
|
||||||
# )
|
# )
|
||||||
# task.start()
|
# task.start()
|
||||||
return form
|
# return form
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_api_url(cls, url):
|
def get_api_url(cls, url):
|
||||||
|
|
|
@ -11,13 +11,14 @@ def GameMarkStatusTranslator(status):
|
||||||
|
|
||||||
|
|
||||||
class GameForm(forms.ModelForm):
|
class GameForm(forms.ModelForm):
|
||||||
# id = forms.IntegerField(required=False, widget=forms.HiddenInput())
|
id = forms.IntegerField(required=False, widget=forms.HiddenInput())
|
||||||
|
|
||||||
other_info = JSONField(required=False, label=_("其他信息"))
|
other_info = JSONField(required=False, label=_("其他信息"))
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Game
|
model = Game
|
||||||
fields = [
|
fields = [
|
||||||
|
'id',
|
||||||
'title',
|
'title',
|
||||||
'source_site',
|
'source_site',
|
||||||
'source_url',
|
'source_url',
|
||||||
|
|
|
@ -22,9 +22,24 @@
|
||||||
|
|
||||||
<section id="content" class="container">
|
<section id="content" class="container">
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
|
{% if is_update and form.source_site.value != 'in-site' %}
|
||||||
|
<div style="float:right;padding-left:16px">
|
||||||
|
<div class="aside-section-wrapper">
|
||||||
|
<div class="action-panel">
|
||||||
|
<div class="action-panel__label">{% trans '源网站' %}: <a href="{{ form.source_url.value }}">{{ form.source_site.value }}</a></div>
|
||||||
|
<div class="action-panel__button-group">
|
||||||
|
<form method="post" action="{% url 'games:rescrape' form.id.value %}">
|
||||||
|
{% csrf_token %}
|
||||||
|
<input class="button" type="submit" value="{% trans '从源网站重新抓取' %}">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<div class="single-section-wrapper" id="main">
|
<div class="single-section-wrapper" id="main">
|
||||||
<a href="{% url 'games:scrape' %}"
|
{% comment %} <a href="{% url 'games:scrape' %}" class="single-section-wrapper__link single-section-wrapper__link--secondary">{% trans '>>> 试试一键剽取~ <<<' %}</a> {% endcomment %}
|
||||||
class="single-section-wrapper__link single-section-wrapper__link--secondary">{% trans '>>> 试试一键剽取~ <<<' %}</a>
|
|
||||||
<form class="entity-form" action="{{ submit_url }}" method="post" enctype="multipart/form-data">
|
<form class="entity-form" action="{{ submit_url }}" method="post" enctype="multipart/form-data">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form.media }}
|
{{ form.media }}
|
||||||
|
|
|
@ -8,6 +8,7 @@ urlpatterns = [
|
||||||
path('<int:id>/', retrieve, name='retrieve'),
|
path('<int:id>/', retrieve, name='retrieve'),
|
||||||
path('update/<int:id>/', update, name='update'),
|
path('update/<int:id>/', update, name='update'),
|
||||||
path('delete/<int:id>/', delete, name='delete'),
|
path('delete/<int:id>/', delete, name='delete'),
|
||||||
|
path('rescrape/<int:id>/', rescrape, name='rescrape'),
|
||||||
path('mark/', create_update_mark, name='create_update_mark'),
|
path('mark/', create_update_mark, name='create_update_mark'),
|
||||||
path('wish/<int:id>/', wish, name='wish'),
|
path('wish/<int:id>/', wish, name='wish'),
|
||||||
re_path('(?P<game_id>[0-9]+)/mark/list/(?:(?P<following_only>\\d+))?', retrieve_mark_list, name='retrieve_mark_list'),
|
re_path('(?P<game_id>[0-9]+)/mark/list/(?:(?P<following_only>\\d+))?', retrieve_mark_list, name='retrieve_mark_list'),
|
||||||
|
|
|
@ -18,6 +18,7 @@ from .models import *
|
||||||
from .forms import *
|
from .forms import *
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from collection.models import CollectionItem
|
from collection.models import CollectionItem
|
||||||
|
from common.scraper import get_scraper_by_url, get_normalized_url
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -88,6 +89,18 @@ def create(request):
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def rescrape(request, id):
|
||||||
|
if request.method != 'POST':
|
||||||
|
return HttpResponseBadRequest()
|
||||||
|
item = get_object_or_404(Game, pk=id)
|
||||||
|
url = get_normalized_url(item.source_url)
|
||||||
|
scraper = get_scraper_by_url(url)
|
||||||
|
scraper.scrape(url)
|
||||||
|
form = scraper.save(request_user=request.user, instance=item)
|
||||||
|
return redirect(reverse("games:retrieve", args=[form.instance.id]))
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def update(request, id):
|
def update(request, id):
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
|
@ -99,6 +112,7 @@ def update(request, id):
|
||||||
'games/create_update.html',
|
'games/create_update.html',
|
||||||
{
|
{
|
||||||
'form': form,
|
'form': form,
|
||||||
|
'is_update': True,
|
||||||
'title': page_title,
|
'title': page_title,
|
||||||
'submit_url': reverse("games:update", args=[game.id]),
|
'submit_url': reverse("games:update", args=[game.id]),
|
||||||
# provided for frontend js
|
# provided for frontend js
|
||||||
|
@ -128,6 +142,7 @@ def update(request, id):
|
||||||
'games/create_update.html',
|
'games/create_update.html',
|
||||||
{
|
{
|
||||||
'form': form,
|
'form': form,
|
||||||
|
'is_update': True,
|
||||||
'title': page_title,
|
'title': page_title,
|
||||||
'submit_url': reverse("games:update", args=[game.id]),
|
'submit_url': reverse("games:update", args=[game.id]),
|
||||||
# provided for frontend js
|
# provided for frontend js
|
||||||
|
|
|
@ -21,10 +21,25 @@
|
||||||
{% include "partial/_navbar.html" %}
|
{% include "partial/_navbar.html" %}
|
||||||
|
|
||||||
<section id="content" class="container">
|
<section id="content" class="container">
|
||||||
<div class="grid">
|
<div class="grid" class="single-section-wrapper">
|
||||||
|
{% if is_update and form.source_site.value != 'in-site' %}
|
||||||
|
<div style="float:right;padding-left:16px">
|
||||||
|
<div class="aside-section-wrapper">
|
||||||
|
<div class="action-panel">
|
||||||
|
<div class="action-panel__label">{% trans '源网站' %}: <a href="{{ form.source_url.value }}">{{ form.source_site.value }}</a></div>
|
||||||
|
<div class="action-panel__button-group">
|
||||||
|
<form method="post" action="{% url 'movies:rescrape' form.id.value %}">
|
||||||
|
{% csrf_token %}
|
||||||
|
<input class="button" type="submit" value="{% trans '从源网站重新抓取' %}">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<div class="single-section-wrapper" id="main">
|
<div class="single-section-wrapper" id="main">
|
||||||
<a href="{% url 'movies:scrape' %}"
|
{% comment %} <a href="{% url 'movies:scrape' %}" class="single-section-wrapper__link single-section-wrapper__link--secondary">{% trans '>>> 试试一键剽取~ <<<' %}</a> {% endcomment %}
|
||||||
class="single-section-wrapper__link single-section-wrapper__link--secondary">{% trans '>>> 试试一键剽取~ <<<' %}</a>
|
|
||||||
<form class="entity-form" action="{{ submit_url }}" method="post" enctype="multipart/form-data">
|
<form class="entity-form" action="{{ submit_url }}" method="post" enctype="multipart/form-data">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form.media }}
|
{{ form.media }}
|
||||||
|
|
|
@ -8,6 +8,7 @@ urlpatterns = [
|
||||||
path('<int:id>/', retrieve, name='retrieve'),
|
path('<int:id>/', retrieve, name='retrieve'),
|
||||||
path('update/<int:id>/', update, name='update'),
|
path('update/<int:id>/', update, name='update'),
|
||||||
path('delete/<int:id>/', delete, name='delete'),
|
path('delete/<int:id>/', delete, name='delete'),
|
||||||
|
path('rescrape/<int:id>/', rescrape, name='rescrape'),
|
||||||
path('mark/', create_update_mark, name='create_update_mark'),
|
path('mark/', create_update_mark, name='create_update_mark'),
|
||||||
path('wish/<int:id>/', wish, name='wish'),
|
path('wish/<int:id>/', wish, name='wish'),
|
||||||
re_path('(?P<movie_id>[0-9]+)/mark/list/(?:(?P<following_only>\\d+))?', retrieve_mark_list, name='retrieve_mark_list'),
|
re_path('(?P<movie_id>[0-9]+)/mark/list/(?:(?P<following_only>\\d+))?', retrieve_mark_list, name='retrieve_mark_list'),
|
||||||
|
|
|
@ -18,6 +18,7 @@ from .models import *
|
||||||
from .forms import *
|
from .forms import *
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from collection.models import CollectionItem
|
from collection.models import CollectionItem
|
||||||
|
from common.scraper import get_scraper_by_url, get_normalized_url
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -88,6 +89,18 @@ def create(request):
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def rescrape(request, id):
|
||||||
|
if request.method != 'POST':
|
||||||
|
return HttpResponseBadRequest()
|
||||||
|
item = get_object_or_404(Movie, pk=id)
|
||||||
|
url = get_normalized_url(item.source_url)
|
||||||
|
scraper = get_scraper_by_url(url)
|
||||||
|
scraper.scrape(url)
|
||||||
|
form = scraper.save(request_user=request.user, instance=item)
|
||||||
|
return redirect(reverse("movies:retrieve", args=[form.instance.id]))
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def update(request, id):
|
def update(request, id):
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
|
@ -99,6 +112,7 @@ def update(request, id):
|
||||||
'movies/create_update.html',
|
'movies/create_update.html',
|
||||||
{
|
{
|
||||||
'form': form,
|
'form': form,
|
||||||
|
'is_update': True,
|
||||||
'title': page_title,
|
'title': page_title,
|
||||||
'submit_url': reverse("movies:update", args=[movie.id]),
|
'submit_url': reverse("movies:update", args=[movie.id]),
|
||||||
# provided for frontend js
|
# provided for frontend js
|
||||||
|
@ -128,6 +142,7 @@ def update(request, id):
|
||||||
'movies/create_update.html',
|
'movies/create_update.html',
|
||||||
{
|
{
|
||||||
'form': form,
|
'form': form,
|
||||||
|
'is_update': True,
|
||||||
'title': page_title,
|
'title': page_title,
|
||||||
'submit_url': reverse("movies:update", args=[movie.id]),
|
'submit_url': reverse("movies:update", args=[movie.id]),
|
||||||
# provided for frontend js
|
# provided for frontend js
|
||||||
|
|
|
@ -22,9 +22,24 @@
|
||||||
|
|
||||||
<section id="content" class="container">
|
<section id="content" class="container">
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
|
{% if is_update and form.source_site.value != 'in-site' %}
|
||||||
|
<div style="float:right;padding-left:16px">
|
||||||
|
<div class="aside-section-wrapper">
|
||||||
|
<div class="action-panel">
|
||||||
|
<div class="action-panel__label">{% trans '源网站' %}: <a href="{{ form.source_url.value }}">{{ form.source_site.value }}</a></div>
|
||||||
|
<div class="action-panel__button-group">
|
||||||
|
<form method="post" action="{% url 'music:rescrape' form.id.value %}">
|
||||||
|
{% csrf_token %}
|
||||||
|
<input class="button" type="submit" value="{% trans '从源网站重新抓取' %}">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<div class="single-section-wrapper" id="main">
|
<div class="single-section-wrapper" id="main">
|
||||||
<a href="{% url 'music:scrape_album' %}"
|
{% comment %} <a href="{% url 'music:scrape_album' %}" class="single-section-wrapper__link single-section-wrapper__link--secondary">{% trans '>>> 试试一键剽取~ <<<' %}</a> {% endcomment %}
|
||||||
class="single-section-wrapper__link single-section-wrapper__link--secondary">{% trans '>>> 试试一键剽取~ <<<' %}</a>
|
|
||||||
<form class="entity-form" action="{{ submit_url }}" method="post" enctype="multipart/form-data">
|
<form class="entity-form" action="{{ submit_url }}" method="post" enctype="multipart/form-data">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form.media }}
|
{{ form.media }}
|
||||||
|
|
|
@ -25,6 +25,7 @@ urlpatterns = [
|
||||||
path('album/<int:id>/', retrieve_album, name='retrieve_album'),
|
path('album/<int:id>/', retrieve_album, name='retrieve_album'),
|
||||||
path('album/update/<int:id>/', update_album, name='update_album'),
|
path('album/update/<int:id>/', update_album, name='update_album'),
|
||||||
path('album/delete/<int:id>/', delete_album, name='delete_album'),
|
path('album/delete/<int:id>/', delete_album, name='delete_album'),
|
||||||
|
path('rescrape/<int:id>/', rescrape, name='rescrape'),
|
||||||
path('album/mark/', create_update_album_mark, name='create_update_album_mark'),
|
path('album/mark/', create_update_album_mark, name='create_update_album_mark'),
|
||||||
path('album/wish/<int:id>/', wish_album, name='wish_album'),
|
path('album/wish/<int:id>/', wish_album, name='wish_album'),
|
||||||
re_path('album/(?P<album_id>[0-9]+)/mark/list/(?:(?P<following_only>\\d+))?', retrieve_album_mark_list, name='retrieve_album_mark_list'),
|
re_path('album/(?P<album_id>[0-9]+)/mark/list/(?:(?P<following_only>\\d+))?', retrieve_album_mark_list, name='retrieve_album_mark_list'),
|
||||||
|
|
|
@ -18,6 +18,7 @@ from django.shortcuts import render, get_object_or_404, redirect, reverse
|
||||||
import logging
|
import logging
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from collection.models import CollectionItem
|
from collection.models import CollectionItem
|
||||||
|
from common.scraper import get_scraper_by_url, get_normalized_url
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -99,6 +100,7 @@ def update_song(request, id):
|
||||||
'music/create_update_song.html',
|
'music/create_update_song.html',
|
||||||
{
|
{
|
||||||
'form': form,
|
'form': form,
|
||||||
|
'is_update': True,
|
||||||
'title': page_title,
|
'title': page_title,
|
||||||
'submit_url': reverse("music:update_song", args=[song.id]),
|
'submit_url': reverse("music:update_song", args=[song.id]),
|
||||||
# provided for frontend js
|
# provided for frontend js
|
||||||
|
@ -128,6 +130,7 @@ def update_song(request, id):
|
||||||
'music/create_update_song.html',
|
'music/create_update_song.html',
|
||||||
{
|
{
|
||||||
'form': form,
|
'form': form,
|
||||||
|
'is_update': True,
|
||||||
'title': page_title,
|
'title': page_title,
|
||||||
'submit_url': reverse("music:update_song", args=[song.id]),
|
'submit_url': reverse("music:update_song", args=[song.id]),
|
||||||
# provided for frontend js
|
# provided for frontend js
|
||||||
|
@ -637,6 +640,18 @@ def create_album(request):
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def rescrape(request, id):
|
||||||
|
if request.method != 'POST':
|
||||||
|
return HttpResponseBadRequest()
|
||||||
|
item = get_object_or_404(Album, pk=id)
|
||||||
|
url = get_normalized_url(item.source_url)
|
||||||
|
scraper = get_scraper_by_url(url)
|
||||||
|
scraper.scrape(url)
|
||||||
|
form = scraper.save(request_user=request.user, instance=item)
|
||||||
|
return redirect(reverse("music:retrieve_album", args=[form.instance.id]))
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def update_album(request, id):
|
def update_album(request, id):
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
|
@ -648,6 +663,7 @@ def update_album(request, id):
|
||||||
'music/create_update_album.html',
|
'music/create_update_album.html',
|
||||||
{
|
{
|
||||||
'form': form,
|
'form': form,
|
||||||
|
'is_update': True,
|
||||||
'title': page_title,
|
'title': page_title,
|
||||||
'submit_url': reverse("music:update_album", args=[album.id]),
|
'submit_url': reverse("music:update_album", args=[album.id]),
|
||||||
# provided for frontend js
|
# provided for frontend js
|
||||||
|
@ -677,6 +693,7 @@ def update_album(request, id):
|
||||||
'music/create_update_album.html',
|
'music/create_update_album.html',
|
||||||
{
|
{
|
||||||
'form': form,
|
'form': form,
|
||||||
|
'is_update': True,
|
||||||
'title': page_title,
|
'title': page_title,
|
||||||
'submit_url': reverse("music:update_album", args=[album.id]),
|
'submit_url': reverse("music:update_album", args=[album.id]),
|
||||||
# provided for frontend js
|
# provided for frontend js
|
||||||
|
|
Loading…
Add table
Reference in a new issue