Exemplo n.º 1
0
def manga_chapters_overview(request, manga_id=0):
    manga = Manga.objects.get(id=manga_id)

    chapters = Chapter.objects.filter(manga_id=manga_id)

    valid_ratings = manga.valid_ratings
    rating = None

    user = user_session.get_authenticated_user(request)

    if user:
        rating = manga.rating_by(user)
    else:
        rating = manga.rating

    authors = manga.manga_author.all()
    tags = manga.tags.all()
    translators = manga.manga_translator.all()

    manga_same_author = Manga.objects.filter(
        manga_author__in=authors, ).exclude(id=manga.id)

    manga_same_tags = parents = Manga.objects.annotate(
        count=Count('tags')).filter(count=len(tags)).exclude(id=manga.id)

    for tag in tags:
        manga_same_tags = manga_same_tags.filter(tags__id=tag.id)

    alternate_names = manga.alternate_names.all()
    translators = manga.manga_translator.all()

    context = {
        'manga': manga,
        'chapters': chapters,
        'rating': rating,
        'valid_ratings': valid_ratings,
        'tags': tags,
        'authors': authors,
        'translators': translators,
        'alternate_names': alternate_names,
        'manga_same_author': manga_same_author,
        'manga_same_tags': manga_same_tags,
    }

    user = user_session.get_authenticated_user(request)

    is_manga_in_watchlist = user_watchlist.is_manga_in_user_watchlist(
        user=user,
        manga=manga,
    )

    context['is_manga_in_watchlist'] = is_manga_in_watchlist

    template = loader.get_template(
        'manga/modules/manga_chapters_overview.dtl.html')

    return HttpResponse(template.render(context, request))
Exemplo n.º 2
0
def get_mangas_page_with_filters(request, page_number):
    items_per_page = request.GET.get('items_per_page')
    tags = request.GET.get('tags')
    authors = request.GET.get('authors')
    order_by = request.GET.get('order_by')
    section_id = request.GET.get('section_id')

    mangas = None

    if section_id == 'watchlist':
        user = user_session.get_authenticated_user(request)
        mangas = user_watchlist.get_watchlist_page_with_filters(
            user=user,
            page_number=page_number,
            items_per_page=items_per_page,
            authors=authors,
            tags=tags,
            order_by=order_by)
    elif section_id == 'bookmarks':
        user = user_session.get_authenticated_user(request)
        mangas = user_bookmarks.get_bookmarks_page_with_filters(
            user=user,
            page_number=page_number,
            items_per_page=items_per_page,
            authors=authors,
            tags=tags,
            order_by=order_by)
    elif section_id == 'history':
        user = user_session.get_authenticated_user(request)
        mangas = user_history.get_history_page_with_filters(
            user=user,
            page_number=page_number,
            items_per_page=items_per_page,
            authors=authors,
            tags=tags,
            order_by=order_by)
    elif section_id == 'favorites':
        user = user_session.get_authenticated_user(request)
        mangas = user_favorites.get_favorites_page_with_filters(
            user=user,
            page_number=page_number,
            items_per_page=items_per_page,
            authors=authors,
            tags=tags,
            order_by=order_by)
    else:
        mangas = manga_session.get_mangas_page_with_filters(
            page_number=page_number,
            items_per_page=items_per_page,
            authors=authors,
            tags=tags,
            order_by=order_by)

    return mangas
Exemplo n.º 3
0
def set_manga_reading_mode(request):
    user = user_session.get_authenticated_user(request)
    manga_id = request.GET.get('manga')
    reading_mode = request.GET.get('reading_mode')

    response = None

    try:
        manga = Manga.objects.get(id=manga_id)

        manga_reading_settings = UserMangaReadingSettings.objects.get_or_create(
            user=user, manga=manga)[0]

        manga_reading_settings.reading_mode = reading_mode.upper()

        manga_reading_settings.save()

        response = {
            'status': 'success',
            'description':
            'Your reading preferences have been saved accordingly.',
        }

    except Manga.DoesNotExist:
        response = {
            'status': 'failed',
            'description': 'The manga specified in the request does not exist.'
        }

    return JsonResponse(response, safe=False)
Exemplo n.º 4
0
def user_dashboard(request):
    template = loader.get_template('account/account_dashbord.html')
    active_user = user_session.get_authenticated_user(request)
    
    context = {
        'user': active_user,
    }

    return HttpResponse(template, context)
Exemplo n.º 5
0
def account_view(request):
    template = loader.get_template('users/modules/profile.dtl.html')

    user = user_session.get_authenticated_user(request)

    context = {
        'user': user,
    }

    return HttpResponse(template.render(context, request))
Exemplo n.º 6
0
def submit_rating(request):
    response = None

    try:
        manga_id = request.GET.get('manga_id')
        rating = request.GET.get('rating')

        manga = Manga.objects.get(id=manga_id)

        user = user_session.get_authenticated_user(request)

        if user:
            try:
                ratings.submit_rating(
                    user=user,
                    manga=manga,
                    rating=int(rating),
                )

                valid_ratings = list(manga.valid_ratings)

                response = {
                    'status':
                    'success',
                    'rating':
                    rating,
                    'valid_ratings':
                    valid_ratings,
                    'description':
                    'Thanks for your vote! You can now find this manga (with your personal rating) at "MY FAVORITES".'
                }
            except EnvironmentError:
                response = {
                    'status': 'failed',
                    'description': 'You have already rated this manga.',
                }
        else:
            response = {
                'status': 'failed',
                'description': 'You have to login to get this functionality.',
            }

    except KeyError:
        response = {
            'status': 'failed',
            'description': 'Manga not found',
        }
    except AttributeError:
        response = {'status': 'failed', 'description': 'User unauthenticated.'}
        raise

    return JsonResponse(response, safe=False)
Exemplo n.º 7
0
def validate_request(request):
    manga_id = None
    user_id = None

    try:
        manga_id = request.GET.get("manga_id")
        user_id = request.GET.get("user_id")

        active_user = user_session.get_authenticated_user(request)

        response = None

        if user_id == None:
            response = {
                'status':
                'failed',
                'description':
                'No user was specified for this request. If you\'re already logged in, log in again then retry.',
            }
        elif active_user == None:
            response = {
                'status':
                'failed',
                'description':
                'You are not logged in. Please sign up or login to your account.',
            }
        elif int(user_id) == active_user.id:
            manga = Manga.objects.get(id=manga_id)

            user = SiteUser.objects.get(id=user_id)

            response = {
                'status': 'success',
                'manga': manga,
                'user': user,
            }
        else:
            response = {
                'status':
                'failed',
                'description':
                'The user specified in the request is not the currently active user.'
            }
    except KeyError:
        response = {
            'status':
            'failed',
            'description':
            'Malformed request. Either user or manga has not been specified.',
        }

    return response
Exemplo n.º 8
0
def remove_chapter_from_user_bookmarks(request):
    request_validation = user_manga_session_request_validator.validate_request(
        request)

    response = None

    if request_validation["status"] == "success":
        manga_id = request.GET.get("manga_id")

        user = user_session.get_authenticated_user(request)
        manga = Manga.objects.get(id=manga_id)

        chapter_id = request.GET.get("chapter_id")
        chapter = Chapter.objects.get(id=chapter_id, )

        is_manga_chapter_in_user_bookmarks = user_bookmarks.is_manga_chapter_in_user_bookmarks(
            user,
            manga,
            chapter,
        )

        if is_manga_chapter_in_user_bookmarks:
            success = user_bookmarks.remove_manga_chapter_from_user_bookmarks(
                user, manga, chapter)

            if success:
                response = {
                    "status":
                    "success",
                    "description":
                    "The chapter was removed from the user's bookmarks successfully."
                }
            else:
                response = {
                    "status":
                    "failed",
                    "description":
                    "Something doubly obscure went wrong with the system. It's our fault."
                }
        else:
            response = {
                'status':
                'failed',
                'description':
                'The chapter was not found in the user\'s bookmarks.',
            }
    else:
        response = request_validation

    return JsonResponse(response, safe=False)
Exemplo n.º 9
0
def manga_list_bookmarks_view(request):
    authors_page = manga_session.get_authors_page(1, 10)
    tags_page = manga_session.get_tags_page(1, 10)

    active_user = user_session.get_authenticated_user(request)

    order_by = request.GET.get('order_by')

    if order_by is None:
        order_by = 'manga_name'

    bookmarked_mangas = user_bookmarks.get_bookmarks_page(
        active_user, 1, 12, order_by)

    template = loader.get_template('manga/modules/manga_list.dtl.html')

    context = {
        'sections': ({
            'section_id':
            'bookmarks',
            'section_name':
            'Bookmarks',
            'section_description':
            'This is where you can keep up with your reading progress.',
            'section_order':
            'manga_name',
            'section_items_per_page':
            12,
            'section_content':
            bookmarked_mangas,
            'pages':
            range(1, bookmarked_mangas.paginator.num_pages + 1)
        }, ),
        'filterable_section':
        'bookmarks',
        'filterable_section_items_per_page':
        12,
        'all_authors':
        authors_page,
        'author_pages':
        range(1, authors_page.paginator.num_pages + 1),
        'all_tags':
        tags_page,
        'tag_pages':
        range(1, tags_page.paginator.num_pages + 1),
    }

    context = user_session.attach_active_user_to_context(context, request)

    return HttpResponse(template.render(context, request))
Exemplo n.º 10
0
def manga_list_favorites_view(request):
    authors_page = manga_session.get_authors_page(1, 10)
    tags_page = manga_session.get_tags_page(1, 10)

    active_user = user_session.get_authenticated_user(request)

    order_by = request.GET.get('order_by')

    if order_by is None:
        order_by = 'updated_on'

    favorites_mangas = user_favorites.get_favorites_page(
        active_user, 1, 12, order_by)

    template = loader.get_template('manga/modules/manga_list.dtl.html')

    context = {
        'sections': ({
            'section_id':
            'favorites',
            'section_name':
            'My Favorites',
            'section_description':
            'This is where manga that you have rated goes, just to help you keep up with what caught your attention generally.',
            'section_order':
            'updated_on',
            'section_items_per_page':
            12,
            'section_content':
            favorites_mangas,
            'pages':
            range(1, favorites_mangas.paginator.num_pages + 1)
        }, ),
        'filterable_section':
        'favorites',
        'filterable_section_items_per_page':
        12,
        'all_authors':
        authors_page,
        'author_pages':
        range(1, authors_page.paginator.num_pages + 1),
        'all_tags':
        tags_page,
        'tag_pages':
        range(1, tags_page.paginator.num_pages + 1),
    }

    context = user_session.attach_active_user_to_context(context, request)

    return HttpResponse(template.render(context, request))
Exemplo n.º 11
0
def manga_chapter_view(request, manga_id=0, chapter_number=0):
    manga = Manga.objects.get(id=manga_id)

    chapters = Chapter.objects.filter(manga_id=manga_id)

    chapter = chapters.get(chapter_number=chapter_number, )

    pages = Page.objects.filter(chapter_id=chapter.id)

    context = {
        'chapter': chapter,
        'pages': pages,
        'manga': manga,
        'chapters': chapters,
        'mode': None
    }

    context = user_session.attach_active_user_to_context(context, request)

    user = user_session.get_authenticated_user(request)

    is_manga_chapter_in_bookmarks = user_bookmarks.is_manga_chapter_in_user_bookmarks(
        user=user,
        manga=manga,
        chapter=chapter,
    )

    preferences = UserMangaReadingSettings.objects.get_or_create(
        user=user, manga=manga)[0]

    reading_mode = preferences.reading_mode

    context[
        'is_manga_chapter_in_user_bookmarks'] = is_manga_chapter_in_bookmarks
    context['reading_mode'] = reading_mode.lower()

    template = loader.get_template('manga/modules/manga_chapter_view.dtl.html')

    response = HttpResponse(template.render(context, request))

    if user:
        user_history.add_chapter_to_user_history(
            user=user,
            manga=manga,
            chapter=chapter,
        )

    return response
Exemplo n.º 12
0
def manga_list_history_view(request):
    authors_page = manga_session.get_authors_page(1, 10)
    tags_page = manga_session.get_tags_page(1, 10)

    active_user = user_session.get_authenticated_user(request)

    order_by = request.GET.get('order_by')

    if order_by is None:
        order_by = 'updated_on'

    history_mangas = user_history.get_history_page(active_user, 1, 12,
                                                   order_by)

    template = loader.get_template(
        'user_manga_integration/user_manga_history.dtl.html')

    context = {
        'sections': ({
            'section_id': 'history',
            'section_name': 'Reading History',
            'section_order': 'updated_on',
            'section_items_per_page': 12,
            'section_content': history_mangas,
            'pages': range(1, history_mangas.paginator.num_pages + 1)
        }, ),
        'filterable_section':
        'history',
        'filterable_section_items_per_page':
        12,
        'all_authors':
        authors_page,
        'author_pages':
        range(1, authors_page.paginator.num_pages + 1),
        'all_tags':
        tags_page,
        'tag_pages':
        range(1, tags_page.paginator.num_pages + 1),
    }

    context = user_session.attach_active_user_to_context(context, request)

    return HttpResponse(template.render(context, request))
Exemplo n.º 13
0
def edit(request):
    user_email = request.GET.get('user_email')
    user_firstname = request.GET.get('first_name')
    user_lastname = request.GET.get('last_name')

    receive_notifications = request.GET.get('receive_notifications')
    receive_notifications = True if receive_notifications == 'on' else False

    print(receive_notifications)

    response = None

    if user_email and user_firstname and user_lastname:
        user = user_session.get_authenticated_user(request)

        user.email = user_email
        user.first_name = user_firstname
        user.last_name = user_lastname
        user.receive_notifications = receive_notifications

        user.save()

        response = {
            'status': 'success',
            'summary': 'The account was edited successfully.',
            'user': {
                'user_email': user_email,
                'first_name': user_firstname,
                'last_name': user_lastname,
                'receive_notifications': receive_notifications,
            }
        }
    else:
        response = {
            'status':
            'failed',
            'summary':
            'The account was not edited because there is something wrong with the request body.',
        }

    return JsonResponse(response, safe=False)
Exemplo n.º 14
0
def post_comment(request):
    try:
        authenticated_user = user_session.get_authenticated_user(request)
        response = None

        if authenticated_user is not None:
            url = request.POST.get('location')
            text = request.POST.get('post')

            if int(request.META.get(
                    'CONTENT_LENGTH')) > DATA_UPLOAD_MAX_MEMORY_SIZE:
                response = {
                    'status':
                    'failed',
                    'description':
                    'Your post is too large for our teeny weeny database.'
                }
            else:
                post = Post(user=authenticated_user, url=url, text=text)

                post.save()

                response = {
                    'status': 'success',
                    'description': 'The post has been added successfully.',
                }
        else:
            response = {
                'status': 'failed',
                'description': 'You need to login to get this functionality.',
            }
    except RequestDataTooBig:
        response = {
            'status': 'failed',
            'description':
            'Your post is too large for our teeny weeny database.'
        }
    return JsonResponse(response, safe=False)
Exemplo n.º 15
0
def manga_list_watchlist_view(request):
    authors_page = manga_session.get_authors_page(1, 10)
    tags_page = manga_session.get_tags_page(1, 10)

    active_user = user_session.get_authenticated_user(request)
    
    order_by = request.GET.get('order_by')

    if order_by is None:
        order_by = 'manga_name'

    watchlist_mangas = user_watchlist.get_watchlist_page(active_user, 1, 12, order_by)

    template = loader.get_template('manga/modules/manga_list.dtl.html')

    context = {
        'sections': (
            {
                'section_id': 'library',
                'section_name': 'My Library',
                'section_order': 'manga_name',
                'section_description': 'This is where you should place manga that you want notifications for (both on the site and off).',
                'section_items_per_page': 12,
                'section_content': watchlist_mangas,
                'pages': range(1, watchlist_mangas.paginator.num_pages + 1)
            },
        ),
        'filterable_section': 'library',
        'filterable_section_items_per_page': 12,
        'all_authors': authors_page,
        'author_pages': range(1, authors_page.paginator.num_pages + 1),
        'all_tags': tags_page,
        'tag_pages': range(1, tags_page.paginator.num_pages + 1),
    }

    context = user_session.attach_active_user_to_context(context, request)

    return HttpResponse(template.render(context, request))
Exemplo n.º 16
0
def bookmarked_json(request):
    response = None

    try:
        manga_id = request.GET.get('manga_id')

        manga = Manga.objects.get(id=manga_id)

        user = user_session.get_authenticated_user(request)

        chapter = manga.bookmarked_by(user)

        if chapter:
            chapter = chapter.to_dict()

            response = {
                'status': 'success',
                'chapter': chapter,
            }

        else:
            response = {
                'status': 'bookmark_not_found',
            }

    except KeyError:
        response = {
            'status': 'failed',
            'description': 'Manga not found',
        }
    except AttributeError:
        response = {
            'status': 'failed',
            'description': 'User unauthenticated.',
        }

    return JsonResponse(response, safe=False)