diff --git a/books/forms.py b/books/forms.py index 5ff9cc5c..b023028f 100644 --- a/books/forms.py +++ b/books/forms.py @@ -1,11 +1,8 @@ from django import forms -from django.contrib.postgres.forms import SimpleArrayField from django.utils.translation import gettext_lazy as _ from .models import Book, BookMark, BookReview from common.models import MarkStatusEnum -from common.forms import RadioBooleanField, RatingValidator, TagField, TagInput -from common.forms import KeyValueInput -from common.forms import PreviewImageInput +from common.forms import * def BookMarkStatusTranslator(status): @@ -21,6 +18,7 @@ class BookForm(forms.ModelForm): pub_year = forms.IntegerField(required=False, max_value=9999, min_value=0, label=_("出版年份")) pub_month = forms.IntegerField(required=False, max_value=12, min_value=1, label=_("出版月份")) id = forms.IntegerField(required=False, widget=forms.HiddenInput()) + other_info = JSONField(required=False, label=_("其他信息")) class Meta: model = Book fields = [ @@ -66,7 +64,6 @@ class BookForm(forms.ModelForm): widgets = { 'author': forms.TextInput(attrs={'placeholder': _("多个作者使用英文逗号分隔")}), 'translator': forms.TextInput(attrs={'placeholder': _("多个译者使用英文逗号分隔")}), - 'other_info': KeyValueInput(), # 'cover': forms.FileInput(), 'cover': PreviewImageInput(), } diff --git a/books/templates/books/create_update.html b/books/templates/books/create_update.html index 1d34c053..02033e1a 100644 --- a/books/templates/books/create_update.html +++ b/books/templates/books/create_update.html @@ -10,7 +10,7 @@ - {% trans 'Nicedb - ' %}{{ title }} + {% trans 'NiceDB - ' %}{{ title }} @@ -27,6 +27,7 @@
{% csrf_token %} + {{ form.media }} {{ form }}
diff --git a/books/templates/books/create_update_review.html b/books/templates/books/create_update_review.html index 7ce6f2a3..1a134598 100644 --- a/books/templates/books/create_update_review.html +++ b/books/templates/books/create_update_review.html @@ -10,7 +10,7 @@ - {% trans 'Nicedb - ' %}{{ title }} + {% trans 'NiceDB - ' %}{{ title }} diff --git a/books/templates/books/delete.html b/books/templates/books/delete.html index 9dab37a4..7f2bf7e7 100644 --- a/books/templates/books/delete.html +++ b/books/templates/books/delete.html @@ -10,7 +10,7 @@ - {% trans 'Nicedb - 删除图书' %} + {% trans 'NiceDB - 删除图书' %} diff --git a/books/templates/books/delete_review.html b/books/templates/books/delete_review.html index 581cc175..19c3e449 100644 --- a/books/templates/books/delete_review.html +++ b/books/templates/books/delete_review.html @@ -10,7 +10,7 @@ - {% trans 'Nicedb - 删除评论' %} + {% trans 'NiceDB - 删除评论' %} diff --git a/books/templates/books/detail.html b/books/templates/books/detail.html index f767b26e..216ff5a3 100644 --- a/books/templates/books/detail.html +++ b/books/templates/books/detail.html @@ -14,6 +14,7 @@ + {% if book.author %} {% endif %} @@ -21,7 +22,7 @@ {% endif %} - {% trans 'Nicedb - 书籍详情' %} | {{ book.title }} + {% trans 'NiceDB - 书籍详情' %} | {{ book.title }} @@ -62,14 +63,14 @@
{% if book.isbn %}{% trans 'ISBN:' %}{{ book.isbn }}{% endif %}
{% if book.author %}{% trans '作者:' %} {% for author in book.author %} - {{ author }} + {{ author }}{% if not forloop.last %} / {% endif %} {% endfor %} {% endif %}
{% if book.pub_house %}{% trans '出版社:' %}{{ book.pub_house }}{% endif %}
{% if book.subtitle %}{% trans '副标题:' %}{{ book.subtitle }}{% endif %}
{% if book.translator %}{% trans '译者:' %} {% for translator in book.translator %} - {{ translator }} + {{ translator }}{% if not forloop.last %} / {% endif %} {% endfor %} {% endif %}
{% if book.orig_title %}{% trans '原作名:' %}{{ book.orig_title }}{% endif %}
diff --git a/books/templates/books/list.html b/books/templates/books/list.html index 44b11b1c..63d62165 100644 --- a/books/templates/books/list.html +++ b/books/templates/books/list.html @@ -11,7 +11,7 @@ - {% trans 'Nicedb - ' %}{{ user.username }}{{ list_title }} + {% trans 'NiceDB - ' %}{{ user.username }}{{ list_title }} diff --git a/books/templates/books/mark_list.html b/books/templates/books/mark_list.html index bf4f4beb..9b72db6d 100644 --- a/books/templates/books/mark_list.html +++ b/books/templates/books/mark_list.html @@ -11,7 +11,7 @@ - {% trans 'Nicedb - ' %}{{ book.title }}{% trans '的标记' %} + {% trans 'NiceDB - ' %}{{ book.title }}{% trans '的标记' %} diff --git a/books/templates/books/review_detail.html b/books/templates/books/review_detail.html index c330510a..3eb0e686 100644 --- a/books/templates/books/review_detail.html +++ b/books/templates/books/review_detail.html @@ -15,7 +15,7 @@ - {% trans 'Nicedb - 评论详情' %} + {% trans 'NiceDB - 评论详情' %} diff --git a/books/templates/books/review_list.html b/books/templates/books/review_list.html index d43a2608..7abf4c25 100644 --- a/books/templates/books/review_list.html +++ b/books/templates/books/review_list.html @@ -11,7 +11,7 @@ - {% trans 'Nicedb - ' %}{{ book.title }}{% trans '的评论' %} + {% trans 'NiceDB - ' %}{{ book.title }}{% trans '的评论' %} diff --git a/books/templates/books/scrape.html b/books/templates/books/scrape.html index 8fee4505..c16a1f0b 100644 --- a/books/templates/books/scrape.html +++ b/books/templates/books/scrape.html @@ -10,7 +10,7 @@ - {% trans 'Nicedb - 从豆瓣获取数据' %} + {% trans 'NiceDB - 从豆瓣获取数据' %} @@ -68,6 +68,7 @@ ISBN: 9787020104345
{% csrf_token %} + {{ form.media }} {{ form }}
{% trans '剽取!' %} @@ -97,7 +98,10 @@ ISBN: 9787020104345
diff --git a/books/views.py b/books/views.py index af69aa95..66765291 100644 --- a/books/views.py +++ b/books/views.py @@ -132,7 +132,7 @@ def retrieve(request, id): except ObjectDoesNotExist: mark = None if mark: - mark_tags = mark.mark_tags.all() + mark_tags = mark.bookmark_tags.all() mark.get_status_display = BookMarkStatusTranslator(mark.status) mark_form = BookMarkForm(instance=mark, initial={ 'tags': mark_tags @@ -239,7 +239,7 @@ def create_update_mark(request): if pk: mark = get_object_or_404(BookMark, pk=pk) old_rating = mark.rating - old_tags = mark.mark_tags.all() + old_tags = mark.bookmark_tags.all() # update form = BookMarkForm(request.POST, instance=mark) else: diff --git a/common/forms.py b/common/forms.py index 890bb37c..25301801 100644 --- a/common/forms.py +++ b/common/forms.py @@ -1,5 +1,6 @@ from django import forms -from django.contrib.postgres.forms import JSONField +import django.contrib.postgres.forms as postgres +from django.utils import formats from django.core.exceptions import ValidationError from django.utils.translation import gettext_lazy as _ import json @@ -26,6 +27,21 @@ class KeyValueInput(forms.Widget): context['widget']['keyvalue_pairs'] = key_value_pairs return context + class Media: + js = ('js/key_value_input.js',) + + +class JSONField(postgres.JSONField): + widget = KeyValueInput + def to_python(self, value): + if not value: + return None + json = {} + pairs = eval(value) + for pair in pairs: + json = {**json, **pair} + return super().to_python(json) + class RadioBooleanField(forms.ChoiceField): widget = forms.RadioSelect @@ -110,3 +126,35 @@ class TagField(forms.CharField): if not value: return return [t.strip() for t in value.split(',')] + + +class MultiSelect(forms.SelectMultiple): + template_name = 'widgets/multi_select.html' + + +class HstoreInput(forms.Widget): + template_name = 'widgets/hstore.html' + + def format_value(self, value): + """ + Return a value as it should appear when rendered in a template. + """ + if value == '' or value is None: + return None + if self.is_localized: + return formats.localize_input(value) + return value + + class Media: + js = ('js/key_value_input.js',) + + +class HstoreField(forms.CharField): + widget = HstoreInput + def to_python(self, value): + if not value: + return None + pairs = eval(value) + if len(pairs) == 1: + pairs = (pairs,) + return pairs diff --git a/common/scraper.py b/common/scraper.py index 894f8585..c3a2a784 100644 --- a/common/scraper.py +++ b/common/scraper.py @@ -300,7 +300,7 @@ def scrape_douban_movie(url): if duration_elem: duration = duration_elem[0].strip() if other_duration_elem: - duration += other_duration_elem[0] + duration += other_duration_elem[0].rstrip() else: duration = None @@ -324,7 +324,7 @@ def scrape_douban_movie(url): is_series = True if episodes else False brief_elem = content.xpath("//span[@property='v:summary']/text()") - brief = brief[0].strip() if brief_elem else None + brief = brief_elem[0].strip() if brief_elem else None img_url_elem = content.xpath("//img[@rel='v:image']/@src") img_url = img_url_elem[0].strip() if img_url_elem else None diff --git a/common/static/css/boofilsic.css b/common/static/css/boofilsic.css index ed22f322..b7863979 100644 --- a/common/static/css/boofilsic.css +++ b/common/static/css/boofilsic.css @@ -1193,10 +1193,15 @@ select::placeholder { font-weight: bold; } +.entity-detail .entity-detail__title--secondary { + color: #bbb; +} + .entity-detail .entity-detail__fields { display: inline-block; vertical-align: top; - width: 48%; + width: 46%; + margin-left: 2%; } .entity-detail .entity-detail__fields div, .entity-detail .entity-detail__fields span { @@ -2083,3 +2088,44 @@ select::placeholder { .rating-star .jq-star { cursor: unset !important; } + +.ms-parent > .ms-choice { + margin-bottom: 1.5rem; + -webkit-appearance: none; + -moz-appearance: none; + appearance: none; + background-color: transparent; + border: 0.1rem solid #ccc; + border-radius: .4rem; + -webkit-box-shadow: none; + box-shadow: none; + -webkit-box-sizing: inherit; + box-sizing: inherit; + padding: .6rem 1.0rem; + width: 100%; + height: 30.126px; +} + +.ms-parent > .ms-choice:focus { + border-color: #00a1cc; +} + +.ms-parent > .ms-choice > .icon-caret { + top: 15.5px; +} + +.ms-parent > .ms-choice > span { + color: black; + font-weight: initial; + font-size: 13.3333px; + top: 2.5px; + left: 2px; +} + +.ms-parent > .ms-choice > span:hover, .ms-parent > .ms-choice > span:focus { + color: black; +} + +.ms-parent > .ms-drop > ul > li > label > span { + margin-left: 10px; +} diff --git a/common/static/js/key_value_input.js b/common/static/js/key_value_input.js new file mode 100644 index 00000000..aa7abd55 --- /dev/null +++ b/common/static/js/key_value_input.js @@ -0,0 +1,63 @@ +function keyValueInput(valueKeyWidget, hiddenInput) { + let placeholderKey = valueKeyWidget.attr('placeholder-key'); + let placeholderValue = valueKeyWidget.attr('placeholder-value'); + if (placeholderKey == null) { + placeholderKey = ''; + } + + if (placeholderValue == null) { + placeholderValue = ''; + } + + let newInputPair = $(''); + valueKeyWidget.append(newInputPair.clone()); + // add new input pair + valueKeyWidget.on('input', ':nth-last-child(1)', function () { + if ($(this).val() && $(this).prev().val()) { + valueKeyWidget.append($(newInputPair).clone()); + } + }); + valueKeyWidget.on('input', ':nth-last-child(2)', function () { + if ($(this).val() && $(this).next().val()) { + valueKeyWidget.append($(newInputPair).clone()); + } + }); + valueKeyWidget.on('input', ':nth-last-child(4)', function () { + if (!$(this).val() && !$(this).next().val() && valueKeyWidget.children("input").length > 2) { + $(this).next().remove(); + $(this).remove(); + } + }); + + valueKeyWidget.on('input', ':nth-last-child(3)', function () { + if (!$(this).val() && !$(this).prev().val() && valueKeyWidget.children("input").length > 2) { + $(this).prev().remove(); + $(this).remove(); + } + }); + + valueKeyWidget.on('input', function () { + let keys = $(this).children(":nth-child(odd)").map(function () { + if ($(this).val()) { + return $(this).val(); + } + }).get(); + let values = $(this).children(":nth-child(even)").map(function () { + if ($(this).val()) { + return $(this).val(); + } + }).get(); + if (keys.length == values.length) { + let finalValue = []; + keys.forEach(function (key, i) { + let json = new Object; + json[key] = values[i]; + finalValue.push(JSON.stringify(json)) + }); + hiddenInput.val(finalValue.toString()); + } else { + + } + }); +} + diff --git a/common/static/sass/_Color.sass b/common/static/sass/_Color.sass index 74cfb583..edf8093f 100644 --- a/common/static/sass/_Color.sass +++ b/common/static/sass/_Color.sass @@ -5,7 +5,7 @@ $color-initial: #fff !default $color-primary: #00a1cc !default $color-secondary: #606c76 !default -$color-tertiary: #fff !default +$color-tertiary: #bbb !default $color-quaternary: #d5d5d5 !default $color-quinary: #e5e5e5 !default diff --git a/common/static/sass/_Divider.sass b/common/static/sass/_Divider.sass index 1583766f..4398327c 100644 --- a/common/static/sass/_Divider.sass +++ b/common/static/sass/_Divider.sass @@ -4,5 +4,5 @@ hr border: 0 - border-top: .1rem solid $color-tertiary + border-top: .1rem solid $color-initial margin: 3.0rem 0 diff --git a/common/static/sass/_MainSection.sass b/common/static/sass/_MainSection.sass index 4a347275..8f073a5d 100644 --- a/common/static/sass/_MainSection.sass +++ b/common/static/sass/_MainSection.sass @@ -106,11 +106,15 @@ $sub-section-title-margin: 8px & &__title font-weight: bold + + & &__title--secondary + color: $color-tertiary & &__fields display: inline-block vertical-align: top - width: 48% + width: 46% + margin-left: 2% // margin-bottom: 5px & div, & span margin: 1px 0 diff --git a/common/static/sass/_Vendor.sass b/common/static/sass/_Vendor.sass index 3021b378..bc0af71a 100644 --- a/common/static/sass/_Vendor.sass +++ b/common/static/sass/_Vendor.sass @@ -2,4 +2,35 @@ min-height: 100px .rating-star .jq-star - cursor: unset !important \ No newline at end of file + cursor: unset !important + +.ms-parent > .ms-choice + margin-bottom: 1.5rem + appearance: none + background-color: transparent + border: 0.1rem solid #ccc + border-radius: .4rem + box-shadow: none + box-sizing: inherit + padding: .6rem 1.0rem + width: 100% + height: 30.126px + + &:focus + border-color: $color-primary + + & > .icon-caret + top: 15.5px + + & > span + color: black + font-weight: initial + // font-size: 1.3rem + font-size: 13.3333px + top: 2.5px + left: 2px + &:hover, &:focus + color: black + +.ms-parent > .ms-drop > ul > li > label > span + margin-left: 10px \ No newline at end of file diff --git a/common/templates/common/home.html b/common/templates/common/home.html index 1722307c..8b10acb8 100644 --- a/common/templates/common/home.html +++ b/common/templates/common/home.html @@ -10,7 +10,13 @@ - {% trans 'Nicedb - 主页' %} + + {% if user == request.user %} + {% trans 'NiceDB - 我的主页' %} + {% else %} + {% trans 'NiceDB - ' %}{{user.username}}{% trans '的主页' %} + {% endif %} + @@ -109,6 +115,84 @@
+
+
+ {% trans '想看的电影/剧集' %} +
+ {% if wish_movies_more %} + {% trans '更多' %} + {% endif %} + + +
+ +
+
+ {% trans '在看的电影/剧集' %} +
+ {% if do_movies_more %} + {% trans '更多' %} + {% endif %} + + +
+ +
+
+ {% trans '看过的电影/剧集' %} +
+ {% if collect_movies_more %} + {% trans '更多' %} + {% endif %} + + +
+ diff --git a/common/templates/common/search_result.html b/common/templates/common/search_result.html index e16a5770..f0906fd5 100644 --- a/common/templates/common/search_result.html +++ b/common/templates/common/search_result.html @@ -11,7 +11,7 @@ - {% trans 'Nicedb - 搜索结果' %} + {% trans 'NiceDB - 搜索结果' %} diff --git a/common/templates/widgets/hstore.html b/common/templates/widgets/hstore.html new file mode 100644 index 00000000..b1d726db --- /dev/null +++ b/common/templates/widgets/hstore.html @@ -0,0 +1,31 @@ + +
+ {% if widget.value != None %} + + {% for pair in widget.value %} + + {% for k, v in pair.items %} + + {% endfor %} + + {% endfor %} + + {% endif %} +
+ + \ No newline at end of file diff --git a/common/templates/widgets/key_value.html b/common/templates/widgets/key_value.html index 2ca666f2..80082bf8 100644 --- a/common/templates/widgets/key_value.html +++ b/common/templates/widgets/key_value.html @@ -8,7 +8,7 @@ margin-left: 1%; } -
+
{% if widget.value != None %} {% for k, v in widget.keyvalue_pairs.items %} @@ -19,53 +19,8 @@
\ No newline at end of file diff --git a/common/templates/widgets/multi_select.html b/common/templates/widgets/multi_select.html new file mode 100644 index 00000000..11ee5780 --- /dev/null +++ b/common/templates/widgets/multi_select.html @@ -0,0 +1,18 @@ + + + + \ No newline at end of file diff --git a/common/utils.py b/common/utils.py index b3f1ed98..0bc708f4 100644 --- a/common/utils.py +++ b/common/utils.py @@ -54,4 +54,12 @@ class PageLinksGenerator: self.first_page = 1 self.last_page = total_pages self.page_range = range(self.start_page, self.end_page + 1) - # assert self.has_prev is not None and self.has_next is not None \ No newline at end of file + # assert self.has_prev is not None and self.has_next is not None + + +def ChoicesDictGenerator(choices_enum): + choices_dict = {} + for attr in dir(choices_enum): + if not '__' in attr: + choices_dict[getattr(choices_enum, attr).value] = getattr(choices_enum, attr).label + return choices_dict \ No newline at end of file diff --git a/common/views.py b/common/views.py index bf1827e4..0a86a7de 100644 --- a/common/views.py +++ b/common/views.py @@ -12,6 +12,9 @@ from django.http import HttpResponseBadRequest # how many books have in each set at the home page BOOKS_PER_SET = 5 +# how many movies have in each set at the home page +MOVIES_PER_SET = 5 + # how many items are showed in one search result page ITEMS_PER_PAGE = 20 @@ -38,6 +41,19 @@ def home(request): status=MarkStatusEnum.COLLECT).order_by("-edited_time") collect_books_more = True if collect_book_marks.count() > BOOKS_PER_SET else False + + do_movie_marks = request.user.user_moviemarks.filter( + status=MarkStatusEnum.DO).order_by("-edited_time") + do_movies_more = True if do_movie_marks.count() > MOVIES_PER_SET else False + + wish_movie_marks = request.user.user_moviemarks.filter( + status=MarkStatusEnum.WISH).order_by("-edited_time") + wish_movies_more = True if wish_movie_marks.count() > MOVIES_PER_SET else False + + collect_movie_marks = request.user.user_moviemarks.filter( + status=MarkStatusEnum.COLLECT).order_by("-edited_time") + collect_movies_more = True if collect_movie_marks.count() > MOVIES_PER_SET else False + reports = Report.objects.order_by('-submitted_time').filter(is_read=False) # reports = Report.objects.latest('submitted_time').filter(is_read=False) @@ -51,6 +67,12 @@ def home(request): 'do_books_more': do_books_more, 'wish_books_more': wish_books_more, 'collect_books_more': collect_books_more, + 'do_movie_marks': do_movie_marks[:MOVIES_PER_SET], + 'wish_movie_marks': wish_movie_marks[:MOVIES_PER_SET], + 'collect_movie_marks': collect_movie_marks[:MOVIES_PER_SET], + 'do_movies_more': do_movies_more, + 'wish_movies_more': wish_movies_more, + 'collect_movies_more': collect_movies_more, 'reports': reports, } ) diff --git a/movies/forms.py b/movies/forms.py index 51e28c23..c0488f50 100644 --- a/movies/forms.py +++ b/movies/forms.py @@ -1,11 +1,9 @@ from django import forms from django.contrib.postgres.forms import SimpleArrayField from django.utils.translation import gettext_lazy as _ -from .models import Movie, MovieMark, MovieReview +from .models import Movie, MovieMark, MovieReview, MovieGenreEnum from common.models import MarkStatusEnum -from common.forms import RadioBooleanField, RatingValidator, TagField, TagInput -from common.forms import KeyValueInput -from common.forms import PreviewImageInput +from common.forms import * def MovieMarkStatusTranslator(status): @@ -22,7 +20,24 @@ class MovieForm(forms.ModelForm): # required=False, max_value=9999, min_value=0, label=_("出版年份")) # pub_month = forms.IntegerField( # required=False, max_value=12, min_value=1, label=_("出版月份")) + id = forms.IntegerField(required=False, widget=forms.HiddenInput()) + genre = forms.MultipleChoiceField( + choices=MovieGenreEnum.choices, + widget= MultiSelect, + label=_("类型") + ) + showtime = HstoreField( + required=False, + label=_("上映时间"), + widget=HstoreInput( + attrs={ + 'placeholder-key': _("日期"), + 'placeholder-value': _("地区"), + } + ) + ) + other_info = JSONField(required=False, label=_("其他信息")) class Meta: model = Movie @@ -31,7 +46,7 @@ class MovieForm(forms.ModelForm): 'title', 'orig_title', 'other_title', - 'imbd_code', + 'imdb_code', 'director', 'playwright', 'actor', @@ -46,14 +61,15 @@ class MovieForm(forms.ModelForm): 'episodes', 'single_episode_length', 'cover', - 'brief', 'is_series', + 'brief', + 'other_info', ] labels = { 'title': _("标题"), 'orig_title': _("原名"), 'other_title': _("又名"), - 'imbd_code': _("IMBd编号"), + 'imdb_code': _("IMDb编号"), 'director': _("导演"), 'playwright': _("编剧"), 'actor': _("主演"), @@ -69,16 +85,20 @@ class MovieForm(forms.ModelForm): 'single_episode_length': _("单集片长"), 'cover': _("封面"), 'brief': _("简介"), - 'is_series': _("是否是剧集"), + 'other_info': _("其他信息"), + 'is_series': _("是否为剧集"), } - # widgets = { - # 'author': forms.TextInput(attrs={'placeholder': _("多个作者使用英文逗号分隔")}), - # 'translator': forms.TextInput(attrs={'placeholder': _("多个译者使用英文逗号分隔")}), - # 'other_info': KeyValueInput(), - # # 'cover': forms.FileInput(), - # 'cover': PreviewImageInput(), - # } + widgets = { + 'other_title': forms.TextInput(attrs={'placeholder': _("多个别名使用英文逗号分隔")}), + 'director': forms.TextInput(attrs={'placeholder': _("多个导演使用英文逗号分隔")}), + 'actor': forms.TextInput(attrs={'placeholder': _("多个主演使用英文逗号分隔")}), + 'playwright': forms.TextInput(attrs={'placeholder': _("多个编剧使用英文逗号分隔")}), + 'area': forms.TextInput(attrs={'placeholder': _("多个国家/地区使用英文逗号分隔")}), + 'language': forms.TextInput(attrs={'placeholder': _("多种语言使用英文逗号分隔")}), + 'cover': PreviewImageInput(), + 'is_series': forms.CheckboxInput(attrs={'style': 'width: auto; position: relative; top: 2px'}) + } # def clean_isbn(self): # isbn = self.cleaned_data.get('isbn') diff --git a/movies/models.py b/movies/models.py index a84ff70a..393e2dd3 100644 --- a/movies/models.py +++ b/movies/models.py @@ -4,6 +4,7 @@ from django.utils.translation import ugettext_lazy as _ from django.db import models from django.core.serializers.json import DjangoJSONEncoder from common.models import Resource, Mark, Review, Tag +from common.utils import ChoicesDictGenerator from boofilsic.settings import MOVIE_MEDIA_PATH_ROOT, DEFAULT_MOVIE_IMAGE from django.utils import timezone @@ -54,6 +55,9 @@ class MovieGenreEnum(models.TextChoices): TALK_SHOW = 'Talk-Show', _('脱口秀') +MovieGenreTranslator = ChoicesDictGenerator(MovieGenreEnum) + + class Movie(Resource): ''' Can either be movie or series. @@ -70,7 +74,7 @@ class Movie(Resource): blank=True, default=list, ) - imbd_code = models.CharField( + imdb_code = models.CharField( blank=True, max_length=10, null=True, unique=True, db_index=True) director = postgres.ArrayField( models.CharField(_("director"), blank=True, @@ -93,12 +97,17 @@ class Movie(Resource): blank=True, default=list, ) - genre = models.CharField( - _("genre"), + genre = postgres.ArrayField( + models.CharField( + _("genre"), + blank=True, + default='', + choices=MovieGenreEnum.choices, + max_length=50 + ), + null=True, blank=True, - default='', - choices=MovieGenreEnum.choices, - max_length=50 + default=list, ) showtime = postgres.ArrayField( # HStoreField stores showtime-region pair @@ -107,7 +116,7 @@ class Movie(Resource): blank=True, default=list, ) - site = models.URLField(_('site url'), max_length=200) + site = models.URLField(_('site url'), blank=True, default='', max_length=200) # country or region area = postgres.ArrayField( @@ -162,6 +171,13 @@ class Movie(Resource): return self.movie_tags + def get_genre_display(self): + translated_genre = [] + for g in self.genre: + translated_genre.append(MovieGenreTranslator[g]) + return translated_genre + + class MovieMark(Mark): movie = models.ForeignKey(Movie, on_delete=models.CASCADE, related_name='movie_marks', null=True) class Meta: diff --git a/movies/templates/movies/create_update.html b/movies/templates/movies/create_update.html index 1d34c053..ffc35975 100644 --- a/movies/templates/movies/create_update.html +++ b/movies/templates/movies/create_update.html @@ -10,7 +10,7 @@ - {% trans 'Nicedb - ' %}{{ title }} + {% trans 'NiceDB - ' %}{{ title }} @@ -27,7 +27,22 @@
{% csrf_token %} - {{ form }} + {{ form.media }} + {% for field in form %} + + {% if field.id_for_label == 'id_is_series' %} + + {{ field }} + {% else %} + {% if field.id_for_label != 'id_id' %} + + {% endif %} + {{ field }} + {% endif %} + + {% endfor %} +
diff --git a/movies/templates/movies/create_update_review.html b/movies/templates/movies/create_update_review.html index e376ee0d..edf47be6 100644 --- a/movies/templates/movies/create_update_review.html +++ b/movies/templates/movies/create_update_review.html @@ -1,5 +1,7 @@ {% load static %} {% load i18n %} +{% load l10n %} +{% load humanize %} {% load admin_url %} {% load mastodon %} {% load oauth_token %} @@ -10,7 +12,7 @@ - {% trans 'Nicedb - ' %}{{ title }} + {% trans 'NiceDB - ' %}{{ title }} @@ -36,16 +38,61 @@
-
{{ movie.title }}
-
{% if movie.isbn %}{% trans 'ISBN:' %}{{ movie.isbn }}{% endif %}
-
{% if movie.author %}{% trans '作者:' %} - {% for author in movie.author %} - {{ author }} +
+ {% if movie.season %} + {{ movie.title }} {% trans '第' %}{{ movie.season|apnumber }}{% trans '季' %} {{ movie.orig_title }} Season + {{ movie.season }} + + ({{ movie.year }}) + + {% else %} + {{ movie.title }} {{ movie.orig_title }} + + ({{ movie.year }}) + + {% endif %} +
+
{% if movie.director %}{% trans '导演:' %} + {% for director in movie.director %} + {{ director }}{% if not forloop.last %} / {% endif %} + {% endfor %} + {% endif %}
+
{% if movie.genre %}{% trans '类型:' %} + {% for genre in movie.get_genre_display %} + {{ genre }}{% if not forloop.last %} / {% endif %} + {% endfor %} + {% endif %}
+ +
{% if movie.actor %}{% trans '主演:' %} + {% for actor in movie.actor %} + 5 %}style="display: none;"{% endif %}>{{ actor }} + {% if forloop.counter <= 5 %} + {% if not forloop.last %} / {% endif %} + {% endif %} {% endfor %} + + {% if movie.actor|length > 5 %} + {% trans '更多' %} + + {% endif %} + {% endif %}
-
{% if movie.pub_house %}{% trans '出版社:' %}{{ movie.pub_house }}{% endif %}
-
{%if movie.pub_year %}{% trans '出版时间:' %}{{ movie.pub_year }}{% trans '年' %}{% if movie.pub_month %}{{ movie.pub_month }}{% trans '月' %}{% endif %}{% endif %}
- +
{% if movie.showtime %}{% trans '上映时间:' %} + {% for showtime in movie.showtime %} + {% for time, region in showtime.items %} + {{ time }}({{ region }}) + {% endfor %} + {% if not forloop.last %} / {% endif %} + {% endfor %} + {% endif %}
+ {% if movie.rating %} {% trans '评分:' %} {{ movie.rating }} diff --git a/movies/templates/movies/delete.html b/movies/templates/movies/delete.html index c655ae27..18b0b132 100644 --- a/movies/templates/movies/delete.html +++ b/movies/templates/movies/delete.html @@ -1,5 +1,7 @@ {% load static %} {% load i18n %} +{% load l10n %} +{% load humanize %} {% load admin_url %} {% load mastodon %} {% load oauth_token %} @@ -10,7 +12,7 @@ - {% trans 'Nicedb - 删除电影/剧集' %} + {% trans 'NiceDB - 删除电影/剧集' %} @@ -39,7 +41,18 @@
- {{ movie.title }} + {% if movie.season %} + {{ movie.title }} {% trans '第' %}{{ movie.season|apnumber }}{% trans '季' %} {{ movie.orig_title }} Season + {{ movie.season }} + + ({{ movie.year }}) + + {% else %} + {{ movie.title }} {{ movie.orig_title }} + + ({{ movie.year }}) + + {% endif %}
{% if movie.rating %} diff --git a/movies/templates/movies/delete_review.html b/movies/templates/movies/delete_review.html index 87538b7d..5d82c20d 100644 --- a/movies/templates/movies/delete_review.html +++ b/movies/templates/movies/delete_review.html @@ -10,7 +10,7 @@ - {% trans 'Nicedb - 删除评论' %} + {% trans 'NiceDB - 删除评论' %} diff --git a/movies/templates/movies/detail.html b/movies/templates/movies/detail.html index 8a011e70..9eec9ee6 100644 --- a/movies/templates/movies/detail.html +++ b/movies/templates/movies/detail.html @@ -1,5 +1,7 @@ {% load static %} {% load i18n %} +{% load l10n %} +{% load humanize %} {% load admin_url %} {% load mastodon %} {% load oauth_token %} @@ -10,18 +12,28 @@ - - + + - {% if movie.author %} - - {% endif %} - {% if movie.isbn %} - - {% endif %} + + + - {% trans 'Nicedb - 电影/剧集详情' %} | {{ movie.title }} + {% if movie.is_series %} + {% trans 'NiceDB - 剧集详情' %} | {{ movie.title }} + {% else %} + {% trans 'NiceDB - 电影详情' %} | {{ movie.title }} + {% endif %} + @@ -47,7 +59,18 @@
- {{ movie.title }} + + {% if movie.season %} + {{ movie.title }} {% trans '第' %}{{ movie.season|apnumber }}{% trans '季' %} {{ movie.orig_title }} Season {{ movie.season }} + + ({{ movie.year }}) + + {% else %} + {{ movie.title }} {{ movie.orig_title }} + + ({{ movie.year }}) + + {% endif %}
@@ -59,28 +82,80 @@ {% trans '评分:暂无评分' %} {% endif %}
-
{% if movie.isbn %}{% trans 'ISBN:' %}{{ movie.isbn }}{% endif %}
-
{% if movie.author %}{% trans '作者:' %} - {% for author in movie.author %} - {{ author }} +
{% if movie.imdb_code %} + {% trans 'IMDb:' %}{{ movie.imdb_code }} + {% endif %} +
+
{% if movie.director %}{% trans '导演:' %} + {% for director in movie.director %} + {{ director }}{% if not forloop.last %} / {% endif %} {% endfor %} {% endif %}
-
{% if movie.pub_house %}{% trans '出版社:' %}{{ movie.pub_house }}{% endif %}
-
{% if movie.subtitle %}{% trans '副标题:' %}{{ movie.subtitle }}{% endif %}
-
{% if movie.translator %}{% trans '译者:' %} - {% for translator in movie.translator %} - {{ translator }} - {% endfor %} - {% endif %}
-
{% if movie.orig_title %}{% trans '原作名:' %}{{ movie.orig_title }}{% endif %}
-
{% if movie.language %}{% trans '语言:' %}{{ movie.language }}{% endif %}
-
{%if movie.pub_year %}{% trans '出版时间:' %}{{ movie.pub_year }}{% trans '年' %}{% if movie.pub_month %}{{ movie.pub_month }}{% trans '月' %}{% endif %}{% endif %}
+
{% if movie.playwright %}{% trans '编剧:' %} + {% for playwright in movie.playwright %} + {{ playwright }}{% if not forloop.last %} / {% endif %} + {% endfor %} + {% endif %}
+
{% if movie.actor %}{% trans '主演:' %} + {% for actor in movie.actor %} + 5 %}style="display: none;"{% endif %}>{{ actor }} + {% if forloop.counter <= 5 %} + {% if not forloop.last %} / {% endif %} + {% endif %} + {% endfor %} + + {% if movie.actor|length > 5 %} + {% trans '更多' %} + + {% endif %} + + {% endif %}
+
{% if movie.genre %}{% trans '类型:' %} + {% for genre in movie.get_genre_display %} + {{ genre }}{% if not forloop.last %} / {% endif %} + {% endfor %} + {% endif %}
+
{% if movie.area %}{% trans '制片国家/地区:' %} + {% for area in movie.area %} + {{ area }}{% if not forloop.last %} / {% endif %} + {% endfor %} + {% endif %}
+
{% if movie.language %}{% trans '语言:' %} + {% for language in movie.language %} + {{ language }}{% if not forloop.last %} / {% endif %} + {% endfor %} + {% endif %}
+
- -
{% if movie.binding %}{% trans '装帧:' %}{{ movie.binding }}{% endif %}
-
{% if movie.price %}{% trans '定价:' %}{{ movie.price }}{% endif %}
-
{% if movie.pages %}{% trans '页数:' %}{{ movie.pages }}{% endif %}
+
{% if movie.duration %}{% trans '片长:' %}{{ movie.duration }}{% endif %}
+
{% if movie.season %}{% trans '季数:' %}{{ movie.season }}{% endif %}
+
{% if movie.episodes %}{% trans '集数:' %}{{ movie.episodes }}{% endif %}
+
{% if movie.single_episode_length %}{% trans '单集长度:' %}{{ movie.single_episode_length }}{% endif %}
+ +
{% if movie.showtime %}{% trans '上映时间:' %} + {% for showtime in movie.showtime %} + {% for time, region in showtime.items %} + {{ time }}({{ region }}) + {% endfor %} + {% if not forloop.last %} / {% endif %} + {% endfor %} + {% endif %}
+
{% if movie.other_title %}{% trans '又名:' %} + {% for other_title in movie.other_title %} + {{ other_title }}{% if not forloop.last %} / {% endif %} + {% endfor %} + {% endif %}
+
{% if movie.site %}{% trans '网站:' %} + {{ movie.site }} + {% endif %}
{% if movie.other_info %} {% for k, v in movie.other_info.items %}
@@ -93,9 +168,13 @@ {% if movie.last_editor %}
{% trans '最近编辑者:' %}{{ movie.last_editor | default:"" }}
{% endif %} - +
- {% trans '编辑这部电影/剧集' %} + {% if movie.is_series %} + {% trans '编辑这部剧集' %} + {% else %} + {% trans '编辑这部电影' %} + {% endif %} {% if user.is_staff %} / {% trans '删除' %} {% endif %} @@ -144,7 +223,12 @@ {% endif %}
-
{% trans '这部电影/剧集的标记' %}
+ + {% if movie.is_series %} +
{% trans '这部剧集的标记' %}
+ {% else %} +
{% trans '这部电影的标记' %}
+ {% endif %} {% if mark_list_more %} {% trans '更多' %} {% endif %} @@ -172,7 +256,12 @@ {% endif %}
-
{% trans '这部电影/剧集的评论' %}
+ {% if movie.is_series %} +
{% trans '这部剧集的评论' %}
+ {% else %} +
{% trans '这部电影的评论' %}
+ {% endif %} + {% if review_list_more %} {% trans '更多' %} {% endif %} @@ -235,7 +324,12 @@
{% else %}
-
{% trans '标记这部电影/剧集' %}
+ + {% if movie.is_series %} +
{% trans '标记这部剧集' %}
+ {% else %} +
{% trans '标记这部电影' %}
+ {% endif %}
@@ -294,11 +388,21 @@
{% if not mark %} + + {% if movie.is_series %} + {% else %} + + {% endif %} + {% else %} {% trans '我的标记' %} diff --git a/movies/templates/movies/list.html b/movies/templates/movies/list.html index 7885b444..3d854710 100644 --- a/movies/templates/movies/list.html +++ b/movies/templates/movies/list.html @@ -1,5 +1,7 @@ {% load static %} {% load i18n %} +{% load l10n %} +{% load humanize %} {% load admin_url %} {% load mastodon %} {% load oauth_token %} @@ -11,7 +13,7 @@ - {% trans 'Nicedb - ' %}{{ user.username }}{{ list_title }} + {% trans 'NiceDB - ' %}{{ user.username }}{{ list_title }} @@ -52,7 +54,18 @@
{% comment %} @@ -66,32 +79,36 @@ {% endif %} --> {% endcomment %} - {% if mark.movie.pub_year %} - {{ mark.movie.pub_year }}{% trans '年' %} / - {% if mark.movie.pub_month %} - {{ mark.movie.pub_month }}{% trans '月' %} / - {% endif %} - {% endif %} + - {% if mark.movie.author %} - {% trans '作者' %} - {% for author in mark.movie.author %} - {{ author }}{% if not forloop.last %},{% endif %} - {% endfor %}/ - {% endif %} + {% if mark.movie.director %}{% trans '导演' %} + {% for director in mark.movie.director %} + {{ director }}{% if not forloop.last %} {% endif %} + {% endfor %}/ + {% endif %} - {% if mark.movie.translator %} - {% trans '译者' %} - {% for translator in mark.movie.translator %} - {{ translator }}{% if not forloop.last %},{% endif %} - {% endfor %}/ - {% endif %} - - {% if mark.movie.orig_title %} -  {% trans '原名' %} - {{ mark.movie.orig_title }} + {% if mark.movie.genre %}{% trans '类型' %} + {% for genre in mark.movie.get_genre_display %} + {{ genre }}{% if not forloop.last %} {% endif %} + {% endfor %}/ + {% endif %} + + {% if mark.movie.other_title %}{% trans '又名' %} + {% for other_title in mark.movie.other_title %} + {{ other_title }}{% if not forloop.last %} {% endif %} + {% endfor %} + {% endif %} + + + {% if mark.movie.actor %}{% trans '主演' %} + {% for actor in mark.movie.actor %} + 5 %}style="display: none;" {% endif %}>{{ actor }} + {% if forloop.counter <= 5 %} + {% if not forloop.last %} / {% endif %} {% endif %} - + {% endfor %} + {% endif %} +

{{ mark.movie.brief | truncate:170 }}

diff --git a/movies/templates/movies/mark_list.html b/movies/templates/movies/mark_list.html index 94eae1af..c5fc3d7f 100644 --- a/movies/templates/movies/mark_list.html +++ b/movies/templates/movies/mark_list.html @@ -1,5 +1,7 @@ {% load static %} {% load i18n %} +{% load l10n %} +{% load humanize %} {% load admin_url %} {% load mastodon %} {% load oauth_token %} @@ -11,7 +13,7 @@ - {% trans 'Nicedb - ' %}{{ movie.title }}{% trans '的标记' %} + {% trans 'NiceDB - ' %}{{ movie.title }}{% trans '的标记' %} @@ -106,13 +108,40 @@
-
{{ movie.title }}
+
+ {% if movie.season %} + {{ movie.title }} {% trans '第' %}{{ movie.season|apnumber }}{% trans '季' %} {{ movie.orig_title }} Season + {{ movie.season }} + + ({{ movie.year }}) + + {% else %} + {{ movie.title }} {{ movie.orig_title }} + + ({{ movie.year }}) + + {% endif %} +
- {% if movie.isbn %} -
ISBN: {{ movie.isbn }}
- {% endif %} - -
{% if movie.pub_house %}{% trans '出版社:' %}{{ movie.pub_house }}{% endif %}
+
{% if movie.director %}{% trans '导演:' %} + {% for director in movie.director %} + {{ director }}{% if not forloop.last %} / {% endif %} + {% endfor %} + {% endif %}
+
{% if movie.genre %}{% trans '类型:' %} + {% for genre in movie.get_genre_display %} + {{ genre }}{% if not forloop.last %} / {% endif %} + {% endfor %} + {% endif %}
+ +
{% if movie.showtime %}{% trans '上映时间:' %} + {% for showtime in movie.showtime %} + {% for time, region in showtime.items %} + {{ time }}({{ region }}) + {% endfor %} + {% if not forloop.last %} / {% endif %} + {% endfor %} + {% endif %}
{% if movie.rating %} {% trans '评分: ' %} {{ movie.rating }} diff --git a/movies/templates/movies/review_detail.html b/movies/templates/movies/review_detail.html index 887548ba..a6e8e998 100644 --- a/movies/templates/movies/review_detail.html +++ b/movies/templates/movies/review_detail.html @@ -1,5 +1,7 @@ {% load static %} {% load i18n %} +{% load l10n %} +{% load humanize %} {% load admin_url %} {% load mastodon %} {% load oauth_token %} @@ -15,7 +17,7 @@ - {% trans 'Nicedb - 评论详情' %} + {% trans 'NiceDB - 评论详情' %} @@ -85,13 +87,40 @@ class="entity-card__img">
-
{{ movie.title }}
- - {% if movie.isbn %} -
ISBN: {{ movie.isbn }}
- {% endif %} - -
{% if movie.pub_house %}{% trans '出版社:' %}{{ movie.pub_house }}{% endif %}
+
+ {% if movie.season %} + {{ movie.title }} {% trans '第' %}{{ movie.season|apnumber }}{% trans '季' %} {{ movie.orig_title }} Season + {{ movie.season }} + + ({{ movie.year }}) + + {% else %} + {{ movie.title }} {{ movie.orig_title }} + + ({{ movie.year }}) + + {% endif %} +
+ +
{% if movie.director %}{% trans '导演:' %} + {% for director in movie.director %} + {{ director }}{% if not forloop.last %} / {% endif %} + {% endfor %} + {% endif %}
+
{% if movie.genre %}{% trans '类型:' %} + {% for genre in movie.get_genre_display %} + {{ genre }}{% if not forloop.last %} / {% endif %} + {% endfor %} + {% endif %}
+ +
{% if movie.showtime %}{% trans '上映时间:' %} + {% for showtime in movie.showtime %} + {% for time, region in showtime.items %} + {{ time }}({{ region }}) + {% endfor %} + {% if not forloop.last %} / {% endif %} + {% endfor %} + {% endif %}
{% if movie.rating %} {% trans '评分: ' %} diff --git a/movies/templates/movies/review_list.html b/movies/templates/movies/review_list.html index 9038f953..fca9832d 100644 --- a/movies/templates/movies/review_list.html +++ b/movies/templates/movies/review_list.html @@ -1,5 +1,7 @@ {% load static %} {% load i18n %} +{% load l10n %} +{% load humanize %} {% load admin_url %} {% load mastodon %} {% load oauth_token %} @@ -11,7 +13,7 @@ - {% trans 'Nicedb - ' %}{{ movie.title }}{% trans '的评论' %} + {% trans 'NiceDB - ' %}{{ movie.title }}{% trans '的评论' %} @@ -92,13 +94,40 @@ class="entity-card__img">
-
{{ movie.title }}
- - {% if movie.isbn %} -
ISBN: {{ movie.isbn }}
- {% endif %} - -
{% if movie.pub_house %}{% trans '出版社:' %}{{ movie.pub_house }}{% endif %}
+
+ {% if movie.season %} + {{ movie.title }} {% trans '第' %}{{ movie.season|apnumber }}{% trans '季' %} {{ movie.orig_title }} Season + {{ movie.season }} + + ({{ movie.year }}) + + {% else %} + {{ movie.title }} {{ movie.orig_title }} + + ({{ movie.year }}) + + {% endif %} +
+ +
{% if movie.director %}{% trans '导演:' %} + {% for director in movie.director %} + {{ director }}{% if not forloop.last %} / {% endif %} + {% endfor %} + {% endif %}
+
{% if movie.genre %}{% trans '类型:' %} + {% for genre in movie.get_genre_display %} + {{ genre }}{% if not forloop.last %} / {% endif %} + {% endfor %} + {% endif %}
+ +
{% if movie.showtime %}{% trans '上映时间:' %} + {% for showtime in movie.showtime %} + {% for time, region in showtime.items %} + {{ time }}({{ region }}) + {% endfor %} + {% if not forloop.last %} / {% endif %} + {% endfor %} + {% endif %}
{% if movie.rating %} {% trans '评分: ' %} diff --git a/movies/templates/movies/scrape.html b/movies/templates/movies/scrape.html index 68ae04fe..9509a6e3 100644 --- a/movies/templates/movies/scrape.html +++ b/movies/templates/movies/scrape.html @@ -10,7 +10,7 @@ - {% trans 'Nicedb - 从豆瓣获取数据' %} + {% trans 'NiceDB - 从豆瓣获取数据' %} @@ -51,7 +51,23 @@
{% csrf_token %} - {{ form }} + + {{ form.media }} + + {% for field in form %} + + {% if field.id_for_label == 'id_is_series' %} + + {{ field }} + {% else %} + {% if field.id_for_label != 'id_id' %} + + {% endif %} + {{ field }} + {% endif %} + + {% endfor %} +
{% trans '剽取!' %}
@@ -80,7 +96,10 @@
diff --git a/movies/views.py b/movies/views.py index 86469073..16941fed 100644 --- a/movies/views.py +++ b/movies/views.py @@ -47,7 +47,7 @@ def create(request): 'movies/create_update.html', { 'form': form, - 'title': _('添加书籍'), + 'title': _('添加电影/剧集'), 'submit_url': reverse("movies:create") } ) @@ -65,7 +65,7 @@ def create(request): 'movies/create_update.html', { 'form': form, - 'title': _('添加书籍'), + 'title': _('添加电影/剧集'), 'submit_url': reverse("movies:create") } ) @@ -80,18 +80,20 @@ def update(request, id): if request.method == 'GET': movie = get_object_or_404(Movie, pk=id) form = MovieForm(instance=movie) + page_title = _('修改剧集') if movie.is_series else _("修改电影") return render( request, 'movies/create_update.html', { 'form': form, - 'title': _('修改书籍'), + 'title': page_title, 'submit_url': reverse("movies:update", args=[movie.id]) } ) elif request.method == 'POST': movie = get_object_or_404(Movie, pk=id) form = MovieForm(request.POST, request.FILES, instance=movie) + page_title = _('修改剧集') if movie.is_series else _("修改电影") if form.is_valid(): form.instance.last_editor = request.user form.instance.edited_time = timezone.now() @@ -102,7 +104,7 @@ def update(request, id): 'movies/create_update.html', { 'form': form, - 'title': _('修改书籍'), + 'title': page_title, 'submit_url': reverse("movies:update", args=[movie.id]) } ) @@ -132,7 +134,7 @@ def retrieve(request, id): except ObjectDoesNotExist: mark = None if mark: - mark_tags = mark.mark_tags.all() + mark_tags = mark.moviemark_tags.all() mark.get_status_display = MovieMarkStatusTranslator(mark.status) mark_form = MovieMarkForm(instance=mark, initial={ 'tags': mark_tags @@ -239,7 +241,7 @@ def create_update_mark(request): if pk: mark = get_object_or_404(MovieMark, pk=pk) old_rating = mark.rating - old_tags = mark.mark_tags.all() + old_tags = mark.moviemark_tags.all() # update form = MovieMarkForm(request.POST, instance=mark) else: @@ -568,10 +570,7 @@ def click_to_scrape(request): form.save() return redirect(reverse('movies:retrieve', args=[form.instance.id])) else: - if 'isbn' in form.errors: - msg = _("ISBN与现有图书重复") - else: - msg = _("爬取数据失败😫") + msg = _("爬取数据失败😫") return render(request, 'common/error.html', {'msg': msg}) else: return HttpResponseBadRequest() diff --git a/users/templates/users/login.html b/users/templates/users/login.html index a99a3de6..f59018dc 100644 --- a/users/templates/users/login.html +++ b/users/templates/users/login.html @@ -6,14 +6,14 @@ - + - {% trans 'Nicedb - 登录' %} + {% trans 'NiceDB - 登录' %}
diff --git a/users/templates/users/manage_report.html b/users/templates/users/manage_report.html index 92ccb807..9a746e86 100644 --- a/users/templates/users/manage_report.html +++ b/users/templates/users/manage_report.html @@ -10,7 +10,7 @@ - {% trans 'Nicedb - 管理举报' %} + {% trans 'NiceDB - 管理举报' %} diff --git a/users/templates/users/register.html b/users/templates/users/register.html index 38c9333a..1ffae6c2 100644 --- a/users/templates/users/register.html +++ b/users/templates/users/register.html @@ -9,7 +9,7 @@ - {% trans 'Nicedb - 注册' %} + {% trans 'NiceDB - 注册' %} diff --git a/users/templates/users/relation_list.html b/users/templates/users/relation_list.html index 098e1337..4b3c51d5 100644 --- a/users/templates/users/relation_list.html +++ b/users/templates/users/relation_list.html @@ -11,9 +11,9 @@ {% if is_followers_page %} - {% trans 'Nicedb - 被他们关注' %} + {% trans 'NiceDB - 被他们关注' %} {% else %} - {% trans 'Nicedb - 关注的人' %} + {% trans 'NiceDB - 关注的人' %} {% endif %} diff --git a/users/templates/users/report.html b/users/templates/users/report.html index b9129341..ac6f66f7 100644 --- a/users/templates/users/report.html +++ b/users/templates/users/report.html @@ -10,7 +10,7 @@ - {% trans 'Nicedb - 举报用户' %} + {% trans 'NiceDB - 举报用户' %} diff --git a/users/urls.py b/users/urls.py index 2d4f1980..e478528c 100644 --- a/users/urls.py +++ b/users/urls.py @@ -12,6 +12,7 @@ urlpatterns = [ path('/followers/', followers, name='followers'), path('/following/', following, name='following'), path('/book//', book_list, name='book_list'), + path('/movie//', movie_list, name='movie_list'), path('report/', report, name='report'), path('manage_report/', manage_report, name='manage_report'), ] diff --git a/users/views.py b/users/views.py index ca4416d4..b525174c 100644 --- a/users/views.py +++ b/users/views.py @@ -12,12 +12,14 @@ from .forms import ReportForm from common.mastodon.auth import * from common.mastodon.api import * from common.mastodon import mastodon_request_included -from common.views import BOOKS_PER_SET, ITEMS_PER_PAGE, PAGE_LINK_NUMBER, TAG_NUMBER_ON_LIST +from common.views import BOOKS_PER_SET, ITEMS_PER_PAGE, PAGE_LINK_NUMBER, TAG_NUMBER_ON_LIST, MOVIES_PER_SET from common.models import MarkStatusEnum from common.utils import PageLinksGenerator from books.models import * +from movies.models import * from boofilsic.settings import MASTODON_DOMAIN_NAME, CLIENT_ID, CLIENT_SECRET from books.forms import BookMarkStatusTranslator +from movies.forms import MovieMarkStatusTranslator # Views @@ -172,6 +174,17 @@ def home(request, id): collect_book_marks = book_marks.filter(status=MarkStatusEnum.COLLECT) collect_books_more = True if collect_book_marks.count() > BOOKS_PER_SET else False + + movie_marks = MovieMark.get_available_user_data(user, relation['following']) + do_movie_marks = movie_marks.filter(status=MarkStatusEnum.DO) + do_movies_more = True if do_movie_marks.count() > BOOKS_PER_SET else False + + wish_movie_marks = movie_marks.filter(status=MarkStatusEnum.WISH) + wish_movies_more = True if wish_movie_marks.count() > BOOKS_PER_SET else False + + collect_movie_marks = movie_marks.filter(status=MarkStatusEnum.COLLECT) + collect_movies_more = True if collect_movie_marks.count() > BOOKS_PER_SET else False + return render( request, 'common/home.html', @@ -183,6 +196,12 @@ def home(request, id): 'do_books_more': do_books_more, 'wish_books_more': wish_books_more, 'collect_books_more': collect_books_more, + 'do_movie_marks': do_movie_marks[:MOVIES_PER_SET], + 'wish_movie_marks': wish_movie_marks[:MOVIES_PER_SET], + 'collect_movie_marks': collect_movie_marks[:MOVIES_PER_SET], + 'do_movies_more': do_movies_more, + 'wish_movies_more': wish_movies_more, + 'collect_movies_more': collect_movies_more, } ) else: @@ -326,6 +345,63 @@ def book_list(request, id, status): ) else: return HttpResponseBadRequest() + + +@mastodon_request_included +@login_required +def movie_list(request, id, status): + if request.method == 'GET': + if not status.upper() in MarkStatusEnum.names: + return HttpResponseBadRequest() + try: + user = User.objects.get(pk=id) + except ObjectDoesNotExist: + msg = _("😖哎呀这位老师还没有注册书影音呢,快去长毛象喊TA来吧!") + sec_msg = _("目前只开放本站用户注册") + return render( + request, + 'common/error.html', + { + 'msg': msg, + 'secondary_msg': sec_msg, + } + ) + if not user == request.user: + # mastodon request + relation = get_relationships([user.mastodon_id], request.session['oauth_token'])[0] + if relation['blocked_by']: + msg = _("你没有访问TA主页的权限😥") + return render( + request, + 'common/error.html', + { + 'msg': msg, + } + ) + queryset = MovieMark.get_available_user_data(user, relation['following']).filter( + status=MarkStatusEnum[status.upper()]).order_by("-edited_time") + else: + queryset = MovieMark.objects.filter( + owner=user, status=MarkStatusEnum[status.upper()]).order_by("-edited_time") + paginator = Paginator(queryset, ITEMS_PER_PAGE) + page_number = request.GET.get('page', default=1) + marks = paginator.get_page(page_number) + for mark in marks: + mark.movie.tag_list = mark.movie.get_tags_manager().values('content').annotate( + tag_frequency=Count('content')).order_by('-tag_frequency')[:TAG_NUMBER_ON_LIST] + marks.pagination = PageLinksGenerator(PAGE_LINK_NUMBER, page_number, paginator.num_pages) + list_title = str(MovieMarkStatusTranslator(MarkStatusEnum[status.upper()])) + str(_("的电影和剧集")) + return render( + request, + 'movies/list.html', + { + 'marks': marks, + 'user': user, + 'list_title' : list_title, + } + ) + else: + return HttpResponseBadRequest() @login_required