コード例 #1
0
ファイル: views.py プロジェクト: ConcernedAnt/Dex-Scraper
def collection(request):
    user = request.user.profile

    if request.GET.get("searchcoll"):
        mangas = Manga.objects.filter(reader=user, name__icontains=request.GET.get('searchcoll'), type=1)
        search = True
    else:
        if request.GET.get('collbtn'):
            my_scraper = Scraper(user)
            my_scraper.get_all()

        search = False
        mangas = Manga.objects.filter(reader=user, type=1)

    paginator = Paginator(mangas, 20)
    page = request.GET.get('page')

    try:
        items = paginator.page(page)
    except PageNotAnInteger:
        items = paginator.page(1)
    except EmptyPage:
        items = paginator.page(paginator.num_pages)

    index = items.number - 1
    max_index = len(paginator.page_range)
    start_index = index - 5 if index >= 5 else 0
    end_index = index + 5 if index <= max_index - 5 else max_index
    page_range = paginator.page_range[start_index:end_index]

    context = {'mangas': mangas, 'items': items, 'page_range': page_range, 'end_index': end_index, 'search': search}
    return render(request, 'manga/collection.html', context)
コード例 #2
0
ファイル: views.py プロジェクト: ConcernedAnt/Dex-Scraper
def remove_from_collection(request):
    user = request.user.profile
    if request.method == "POST":
        to_delete = json.loads(request.POST['to_delete'])
        my_scraper = Scraper(user)

        for delete_id in to_delete:
            manga_to_delete = Manga.objects.get(reader=user, manga_id=delete_id)
            my_scraper.unfollow(manga_to_delete)
            manga_to_delete.delete()

    return HttpResponse('')
コード例 #3
0
ファイル: views.py プロジェクト: ConcernedAnt/Dex-Scraper
def collect_all_chapters(request):
    user = request.user.profile
    if request.method == "POST":
        if request.POST.get('allunread'):
            my_scraper = Scraper(user)
            manga = Manga.objects.get(name=request.POST.get('allunread'))
            my_scraper.all_chapters(manga)

    manga = Manga.objects.get(reader=user, name=request.POST.get('allunread'))
    chapters = manga.chapters_set.all()

    context = {'manga': manga, 'chapters': chapters}
    return render(request, 'manga/manga-details.html', context)
コード例 #4
0
ファイル: views.py プロジェクト: ConcernedAnt/Dex-Scraper
def updates(request):
    user = request.user.profile

    if request.GET.get('mybtn'):
        my_scraper = Scraper(user)
        my_scraper.scrape_following()

    Chapters.objects.filter(manga__reader=user, read_status=True).delete()
    updated_chapters = Chapters.objects.filter(manga__reader=user)

    mangas = set()
    for chapter in updated_chapters:
        mangas.add(chapter.manga)

    return render(request, 'manga/updates.html', {'mangas': mangas})
コード例 #5
0
ファイル: views.py プロジェクト: ConcernedAnt/Dex-Scraper
def add_to_coll(request):
    user = request.user.profile
    added = False
    if request.method == "POST":
        pk = request.POST['pk']

        search_manga = Manga.objects.get(manga_id=pk, type=2)
        my_scraper = Scraper(user)
        my_scraper.follow(search_manga)

        if not Manga.objects.filter(name=search_manga.name, reader=user, type=1).exists():
            search_manga.type = 1
            search_manga.save()
            added = True

    added_dict = {'added': added}
    return HttpResponse(json.dumps(added_dict), content_type='application/json')
コード例 #6
0
ファイル: views.py プロジェクト: ConcernedAnt/Dex-Scraper
def new_search(request):
    search = request.POST.get('search')
    user = request.user.profile
    Manga.objects.filter(reader=user, type=2).delete()

    my_scraper = Scraper(user)
    my_scraper.search(search)

    search_manga = Manga.objects.filter(reader=user, type=2)
    collection_manga = Manga.objects.filter(reader=user, type=1).values_list('manga_id', flat=True)

    in_collection = []
    for manga in search_manga:
        if manga.manga_id in collection_manga:
            in_collection.append(True)
        else:
            in_collection.append(False)

    mangas = zip(search_manga, in_collection)
    stuff_for_frontend = {'mangas': mangas}
    return render(request, 'manga/new_search.html', stuff_for_frontend)
コード例 #7
0
ファイル: views.py プロジェクト: ConcernedAnt/Dex-Scraper
def update_read(request):
    user = request.user.profile
    if request.method == "POST":
        pk = request.POST['pk']
        chapter = Chapters.objects.get(pk=pk)
        chapter.read_status = not chapter.read_status

        my_scraper = Scraper(user)
        if chapter.read_status:
            my_scraper.mark_read(pk)

            # Add last date read
            date = datetime.utcnow()
            manga = chapter.manga
            manga.date_read = date
            manga.save()
        else:
            my_scraper.mark_unread(pk)
        chapter.save()

    return HttpResponse('')