From 4345e289e8d363d4b1f3ea960ad1375a8bfaaafe Mon Sep 17 00:00:00 2001 From: DELL Date: Mon, 17 Oct 2022 12:12:20 +0700 Subject: [PATCH 1/5] add edit link to authors --- templates/blog/blog.html | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/templates/blog/blog.html b/templates/blog/blog.html index f35e5c3..e1d2444 100644 --- a/templates/blog/blog.html +++ b/templates/blog/blog.html @@ -27,8 +27,21 @@ {% trans time=post.publish_on|date(_("N j, Y, g:i a")) %} posted on {{ time }}{% endtrans %} {% if post.is_editable_by(request.user) %} - [{{ _('Edit') }}] + [{{ _('Edit') }}] + {% else %} + {% for author in post.authors.all() %} + {% if author.user == request.user %} + {% for post_org in post.organizations.all() %} + {% for org in author.organizations.all() %} + {% if org == post_org %} + [{{ _('Edit') }}] + {% endif %} + {% endfor %} + {% endfor %} + {% endif %} + {% endfor %} {% endif %} +
{% cache 86400 'post_content' post.id MATH_ENGINE %} From f4163fd017b1019028c7efbfb48ede1a03266053 Mon Sep 17 00:00:00 2001 From: DELL Date: Mon, 17 Oct 2022 23:04:39 +0700 Subject: [PATCH 2/5] fix edit link --- judge/views/blog.py | 21 +++++++++++++++++++++ templates/blog/blog.html | 15 +++------------ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/judge/views/blog.py b/judge/views/blog.py index 061fee0..70f4be5 100644 --- a/judge/views/blog.py +++ b/judge/views/blog.py @@ -1,3 +1,4 @@ +from xmlrpc.client import boolean from django.conf import settings from django.db.models import Count, Max, Q from django.http import Http404 @@ -7,6 +8,8 @@ from django.utils.functional import lazy from django.utils.translation import ugettext as _ from django.views.generic import ListView +from itertools import chain + from judge.comments import CommentedDetailView from judge.models import ( BlogPost, @@ -24,6 +27,7 @@ from judge.utils.diggpaginator import DiggPaginator from judge.utils.problems import user_completed_ids from judge.utils.tickets import filter_visible_tickets from judge.utils.views import TitleMixin +from judge.views import organization # General view for all content list on home feed @@ -201,6 +205,23 @@ class PostView(TitleMixin, CommentedDetailView): def get_context_data(self, **kwargs): context = super(PostView, self).get_context_data(**kwargs) context["og_image"] = self.object.og_image + context["valid_user"] = False + context["valid_org"] = [] + for author in self.object.authors.all(): + if self.request.profile.user == author.user: + context["valid_user"] = True + + for valid_org in self.object.organizations.all(): + for admin in valid_org.admins.all(): + if self.request.profile.user == admin.user: + context["valid_user"] = True + + if context["valid_user"]: + for post_org in self.object.organizations.all(): + for org in self.request.profile.organizations.all(): + if post_org == org: + context["valid_org"].append(org) + return context def get_object(self, queryset=None): diff --git a/templates/blog/blog.html b/templates/blog/blog.html index e1d2444..f526732 100644 --- a/templates/blog/blog.html +++ b/templates/blog/blog.html @@ -28,20 +28,11 @@ {% if post.is_editable_by(request.user) %} [{{ _('Edit') }}] - {% else %} - {% for author in post.authors.all() %} - {% if author.user == request.user %} - {% for post_org in post.organizations.all() %} - {% for org in author.organizations.all() %} - {% if org == post_org %} - [{{ _('Edit') }}] - {% endif %} - {% endfor %} - {% endfor %} - {% endif %} + {% elif valid_user %} + {% for org in valid_org %} + [{{ _('Edit in') }} {{org.slug}}] {% endfor %} {% endif %} -
{% cache 86400 'post_content' post.id MATH_ENGINE %} From 70e74fd619793b6ddab18c271b08c0f7e6eeef2d Mon Sep 17 00:00:00 2001 From: DELL Date: Mon, 17 Oct 2022 23:08:37 +0700 Subject: [PATCH 3/5] delete unnecessary import --- judge/views/blog.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/judge/views/blog.py b/judge/views/blog.py index 70f4be5..42cecb7 100644 --- a/judge/views/blog.py +++ b/judge/views/blog.py @@ -1,5 +1,3 @@ -from xmlrpc.client import boolean -from django.conf import settings from django.db.models import Count, Max, Q from django.http import Http404 from django.urls import reverse @@ -8,8 +6,6 @@ from django.utils.functional import lazy from django.utils.translation import ugettext as _ from django.views.generic import ListView -from itertools import chain - from judge.comments import CommentedDetailView from judge.models import ( BlogPost, @@ -27,7 +23,6 @@ from judge.utils.diggpaginator import DiggPaginator from judge.utils.problems import user_completed_ids from judge.utils.tickets import filter_visible_tickets from judge.utils.views import TitleMixin -from judge.views import organization # General view for all content list on home feed From 50bb2c43614f8477168a6e63c2464e703569c50d Mon Sep 17 00:00:00 2001 From: DELL Date: Tue, 18 Oct 2022 01:06:50 +0700 Subject: [PATCH 4/5] add django.po --- judge/views/blog.py | 24 +- locale/vi/LC_MESSAGES/django.po | 4 + locale/vi/LC_MESSAGES/dmoj-user.po | 568 +---------------------------- templates/blog/blog.html | 4 +- 4 files changed, 31 insertions(+), 569 deletions(-) diff --git a/judge/views/blog.py b/judge/views/blog.py index 42cecb7..2398703 100644 --- a/judge/views/blog.py +++ b/judge/views/blog.py @@ -200,22 +200,20 @@ class PostView(TitleMixin, CommentedDetailView): def get_context_data(self, **kwargs): context = super(PostView, self).get_context_data(**kwargs) context["og_image"] = self.object.og_image - context["valid_user"] = False - context["valid_org"] = [] - for author in self.object.authors.all(): - if self.request.profile.user == author.user: - context["valid_user"] = True + context["valid_user_to_show_edit"] = False + context["valid_org_to_show_edit"] = [] + + if self.request.profile in self.object.authors.all(): + context["valid_user_to_show_edit"] = True - for valid_org in self.object.organizations.all(): - for admin in valid_org.admins.all(): - if self.request.profile.user == admin.user: - context["valid_user"] = True + for valid_org_to_show_edit in self.object.organizations.all(): + if self.request.profile in valid_org_to_show_edit.admins.all(): + context["valid_user_to_show_edit"] = True - if context["valid_user"]: + if context["valid_user_to_show_edit"]: for post_org in self.object.organizations.all(): - for org in self.request.profile.organizations.all(): - if post_org == org: - context["valid_org"].append(org) + if post_org in self.request.profile.organizations.all(): + context["valid_org_to_show_edit"].append(post_org) return context diff --git a/locale/vi/LC_MESSAGES/django.po b/locale/vi/LC_MESSAGES/django.po index ac4da17..e89ac73 100644 --- a/locale/vi/LC_MESSAGES/django.po +++ b/locale/vi/LC_MESSAGES/django.po @@ -3361,6 +3361,10 @@ msgstr "đã đăng vào %(time)s" msgid "Edit" msgstr "Chỉnh sửa" +#: templates/blog/blog.html:33 +msgid "Edit in" +msgstr "Chỉnh sửa trong" + #: templates/blog/dashboard.html:21 #, python-format msgid "" diff --git a/locale/vi/LC_MESSAGES/dmoj-user.po b/locale/vi/LC_MESSAGES/dmoj-user.po index 31bcd80..3e14530 100644 --- a/locale/vi/LC_MESSAGES/dmoj-user.po +++ b/locale/vi/LC_MESSAGES/dmoj-user.po @@ -15,6 +15,9 @@ msgstr "Thành viên" msgid "Contests" msgstr "Kỳ thi" +msgid "Chat" +msgstr "" + msgid "Groups" msgstr "Nhóm" @@ -24,563 +27,20 @@ msgstr "Giới thiệu" msgid "Status" msgstr "Máy chấm" -msgid "Suggestions" -msgstr "Đề xuất ý tưởng" - -msgid "Proposal" -msgstr "Đề xuất bài tập" - -msgid "TanKhoa" -msgstr "Tân Khoa" - -msgid "Name" -msgstr "Đăng ký tên" - -msgid "Report" -msgstr "Báo cáo" - -msgid "2sat" -msgstr "" - -msgid "adhoc" -msgstr "" - -msgid "aho-corasick" -msgstr "" - -msgid "articulation-point" -msgstr "" - -msgid "backtrack" -msgstr "" - -msgid "bellman-ford" -msgstr "" - -msgid "bfs-01" -msgstr "" - -msgid "biconnected-component" -msgstr "" - -msgid "bignum" -msgstr "" - -msgid "binary-lifting" -msgstr "" - -msgid "binary-search" -msgstr "" - -msgid "binary-search-parallel" -msgstr "" - -msgid "bit" -msgstr "" - -msgid "bit2d" -msgstr "" - -msgid "bitset" -msgstr "" - -msgid "bitwise" -msgstr "" - -msgid "block-cut-tree" -msgstr "" - -msgid "boruvka" -msgstr "" - -msgid "branch&bound" -msgstr "" - -msgid "bridge" -msgstr "" - -msgid "brute force" -msgstr "" - -msgid "cactus-graph" -msgstr "" - -msgid "casework" -msgstr "" - -msgid "centroid" -msgstr "" - -msgid "chinese-remainder" -msgstr "" - -msgid "combinatorics" -msgstr "" - -msgid "constructive" -msgstr "" - -msgid "convex-hull" -msgstr "" - -msgid "counting" -msgstr "" - -msgid "cycle" -msgstr "" - -msgid "data structures" -msgstr "" - -msgid "deep-optimization" -msgstr "" - -msgid "dfs/bfs/pfs" -msgstr "" - -msgid "dijkstra" -msgstr "" - -msgid "divide and conquer" -msgstr "" - -msgid "dp-alien" -msgstr "" - -msgid "dp-bitmask" -msgstr "" - -msgid "dp-cc" -msgstr "" - -msgid "dp-convexhull" -msgstr "" - -msgid "dp-count" -msgstr "" - -msgid "dp-dag" -msgstr "" - -msgid "dp-digit" -msgstr "" - -msgid "dp-dnc" -msgstr "" - -msgid "dp-general" -msgstr "" - -msgid "dp-knuth" -msgstr "" - -msgid "dp-matrix" -msgstr "" - -msgid "dp-openclose" -msgstr "" - -msgid "dp-permutation" -msgstr "" - -msgid "dp-slope" -msgstr "" - -msgid "dp-sos" -msgstr "" - -msgid "dp-swap-label" -msgstr "" - -msgid "dp-tree" -msgstr "" - -msgid "dsu" -msgstr "" - -msgid "dsu-roll-back" -msgstr "" - -msgid "dynamic programming" -msgstr "" - -msgid "euler-path" -msgstr "" - -msgid "euler-theorem" -msgstr "" - -msgid "euler-tour" -msgstr "" - -msgid "extgcd" -msgstr "" - -msgid "Fenwick Tree (Binary Indexed Tree)" -msgstr "" - -msgid "fft/ntt" -msgstr "" - -msgid "flow-demands" -msgstr "" - -msgid "flow-general" -msgstr "" - -msgid "flow-mincost" -msgstr "" - -msgid "flows" -msgstr "" - -msgid "floyd" -msgstr "" - -msgid "function-graph" -msgstr "" - -msgid "game theory" -msgstr "" - -msgid "game-ad-hoc" -msgstr "" - -msgid "game-minimax" -msgstr "" - -msgid "game-nim" -msgstr "" - -msgid "game-sprague-grundy" -msgstr "" - -msgid "gauss-elim" -msgstr "" - -msgid "genetic" -msgstr "" - -msgid "geometry" -msgstr "" - -msgid "geometry-general" -msgstr "" - -msgid "gomory-hu-tree" -msgstr "" - -msgid "graph" -msgstr "" - -msgid "graph theory" -msgstr "" - -msgid "greedy" -msgstr "" - -msgid "greedy-exchange" -msgstr "" - -msgid "greedy-general" -msgstr "" - -msgid "greedy-moore" -msgstr "" - -msgid "hashing" -msgstr "" - -msgid "heuristic" -msgstr "" - -msgid "hld" -msgstr "" - -msgid "HSG" -msgstr "" - -msgid "ICPC" -msgstr "" - -msgid "implementation" +msgid "Simple Math" msgstr "" -msgid "inclusion-exclusion" -msgstr "" - -msgid "interactive" -msgstr "" - -msgid "inversive-geometry" -msgstr "" - -msgid "kd-tree" -msgstr "" - -msgid "kirchoff" -msgstr "" - -msgid "kmp" -msgstr "" - -msgid "kruskal" -msgstr "" - -msgid "lagrange-inter" -msgstr "" - -msgid "language" -msgstr "" - -msgid "lca" -msgstr "" - -msgid "lichao-tree" -msgstr "" - -msgid "local-search" -msgstr "" +#~ msgid "Suggestions" +#~ msgstr "Đề xuất ý tưởng" -msgid "ltt" -msgstr "" - -msgid "manacher" -msgstr "" - -msgid "matching-bipartie" -msgstr "" - -msgid "matching-general" -msgstr "" - -msgid "matching-hall" -msgstr "" +#~ msgid "Proposal" +#~ msgstr "Đề xuất bài tập" -msgid "matching-hungarian" -msgstr "" - -msgid "matching-konig" -msgstr "" +#~ msgid "TanKhoa" +#~ msgstr "Tân Khoa" -msgid "math" -msgstr "" - -msgid "math-general" -msgstr "" - -msgid "matrix multiplication" -msgstr "" - -msgid "max-clique" -msgstr "" - -msgid "meet-in-the-middle" -msgstr "" - -msgid "Miscellaneous" -msgstr "" +#~ msgid "Name" +#~ msgstr "Đăng ký tên" -msgid "mo-general" -msgstr "" - -msgid "mo-tree" -msgstr "" - -msgid "mo-update" -msgstr "" - -msgid "mobius" -msgstr "" - -msgid "modular" -msgstr "" - -msgid "modular-inverse" -msgstr "" - -msgid "monotonic-queue" -msgstr "" - -msgid "multiplicative" -msgstr "" - -msgid "NEW" -msgstr "" - -msgid "number theory" -msgstr "" - -msgid "offline" -msgstr "" - -msgid "order-statistic" -msgstr "" - -msgid "output-only" -msgstr "" - -msgid "palin-tree" -msgstr "" - -msgid "picks-theorem" -msgstr "" - -msgid "planar-graph" -msgstr "" - -msgid "polygon-triangulation" -msgstr "" - -msgid "precision-issue" -msgstr "" - -msgid "prefix-sum" -msgstr "" - -msgid "primality-test" -msgstr "" - -msgid "probability" -msgstr "" - -msgid "randomized" -msgstr "" - -msgid "Range Queries" -msgstr "" - -msgid "recursion" -msgstr "" - -msgid "rmq" -msgstr "" - -msgid "rmq-2d" -msgstr "" - -msgid "rmq2d" -msgstr "" - -msgid "scc" -msgstr "" - -msgid "scheduling" -msgstr "" - -msgid "search" -msgstr "" - -msgid "segtree-2d" -msgstr "" - -msgid "segtree-beats" -msgstr "" - -msgid "segtree-dynamic" -msgstr "" - -msgid "segtree-general" -msgstr "" - -msgid "segtree-persistent" -msgstr "" - -msgid "segtree-walk" -msgstr "" - -msgid "sequence" -msgstr "" - -msgid "sieve" -msgstr "" - -msgid "sieve-segment" -msgstr "" - -msgid "small-to-large" -msgstr "" - -msgid "sortings" -msgstr "" - -msgid "spanning-tree" -msgstr "" - -msgid "sparse-table" -msgstr "" - -msgid "spfa" -msgstr "" - -msgid "sqrt" -msgstr "" - -msgid "sqrt-babygiant" -msgstr "" - -msgid "sqrt-buckets" -msgstr "" - -msgid "sqrt-buffer" -msgstr "" - -msgid "sqrt-time" -msgstr "" - -msgid "stack-queue" -msgstr "" - -msgid "static-data" -msgstr "" - -msgid "stl" -msgstr "" - -msgid "string" -msgstr "" - -msgid "suffix-array" -msgstr "" - -msgid "sweep-line" -msgstr "" - -msgid "ternary-search" -msgstr "" - -msgid "topo-sort" -msgstr "" - -msgid "tortoise-hare" -msgstr "" - -msgid "treap/splay" -msgstr "" - -msgid "Tree - general" -msgstr "" - -msgid "tree-isomorphism" -msgstr "" - -msgid "trie" -msgstr "" - -msgid "TSP" -msgstr "" - -msgid "TST" -msgstr "" - -msgid "two-pointers" -msgstr "" - -msgid "VOI" -msgstr "" - -msgid "voronoi" -msgstr "" - -msgid "z-function" -msgstr "" +#~ msgid "Report" +#~ msgstr "Báo cáo" diff --git a/templates/blog/blog.html b/templates/blog/blog.html index f526732..9cbfecb 100644 --- a/templates/blog/blog.html +++ b/templates/blog/blog.html @@ -28,8 +28,8 @@ {% if post.is_editable_by(request.user) %} [{{ _('Edit') }}] - {% elif valid_user %} - {% for org in valid_org %} + {% elif valid_user_to_show_edit %} + {% for org in valid_org_to_show_edit %} [{{ _('Edit in') }} {{org.slug}}] {% endfor %} {% endif %} From 21ca51650c2f94f56409307160df0f2f2d5c7b1d Mon Sep 17 00:00:00 2001 From: DELL Date: Tue, 18 Oct 2022 07:25:14 +0700 Subject: [PATCH 5/5] fix po again --- locale/vi/LC_MESSAGES/django.po | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/locale/vi/LC_MESSAGES/django.po b/locale/vi/LC_MESSAGES/django.po index e89ac73..6fe2940 100644 --- a/locale/vi/LC_MESSAGES/django.po +++ b/locale/vi/LC_MESSAGES/django.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: lqdoj2\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-10-16 00:26+0700\n" +"POT-Creation-Date: 2022-10-18 07:19+0700\n" "PO-Revision-Date: 2021-07-20 03:44\n" "Last-Translator: Icyene\n" "Language-Team: Vietnamese\n" @@ -2448,16 +2448,16 @@ msgstr "Giới thiệu" msgid "Custom Checker Sample" msgstr "Hướng dẫn viết trình chấm" -#: judge/views/blog.py:111 +#: judge/views/blog.py:110 #, python-format msgid "Page %d of Posts" msgstr "Trang %d" -#: judge/views/blog.py:166 +#: judge/views/blog.py:165 msgid "Ticket feed" msgstr "Báo cáo" -#: judge/views/blog.py:184 +#: judge/views/blog.py:183 msgid "Comment feed" msgstr "Bình luận" @@ -3363,7 +3363,7 @@ msgstr "Chỉnh sửa" #: templates/blog/blog.html:33 msgid "Edit in" -msgstr "Chỉnh sửa trong" +msgstr "Chỉnh sửa" #: templates/blog/dashboard.html:21 #, python-format @@ -5521,6 +5521,10 @@ msgstr "Thông tin" msgid "Check all" msgstr "Chọn tất cả" +#, python-format +#~ msgid "Edit in %(org_slug)s" +#~ msgstr "Chỉnh sửa trong %(org_slug)s" + #~ msgid "Name and School" #~ msgstr "Họ tên và Trường"