fix edit link
This commit is contained in:
parent
4345e289e8
commit
f4163fd017
2 changed files with 24 additions and 12 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
from xmlrpc.client import boolean
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db.models import Count, Max, Q
|
from django.db.models import Count, Max, Q
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
|
@ -7,6 +8,8 @@ from django.utils.functional import lazy
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
from django.views.generic import ListView
|
from django.views.generic import ListView
|
||||||
|
|
||||||
|
from itertools import chain
|
||||||
|
|
||||||
from judge.comments import CommentedDetailView
|
from judge.comments import CommentedDetailView
|
||||||
from judge.models import (
|
from judge.models import (
|
||||||
BlogPost,
|
BlogPost,
|
||||||
|
@ -24,6 +27,7 @@ from judge.utils.diggpaginator import DiggPaginator
|
||||||
from judge.utils.problems import user_completed_ids
|
from judge.utils.problems import user_completed_ids
|
||||||
from judge.utils.tickets import filter_visible_tickets
|
from judge.utils.tickets import filter_visible_tickets
|
||||||
from judge.utils.views import TitleMixin
|
from judge.utils.views import TitleMixin
|
||||||
|
from judge.views import organization
|
||||||
|
|
||||||
|
|
||||||
# General view for all content list on home feed
|
# General view for all content list on home feed
|
||||||
|
@ -201,6 +205,23 @@ class PostView(TitleMixin, CommentedDetailView):
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(PostView, self).get_context_data(**kwargs)
|
context = super(PostView, self).get_context_data(**kwargs)
|
||||||
context["og_image"] = self.object.og_image
|
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
|
return context
|
||||||
|
|
||||||
def get_object(self, queryset=None):
|
def get_object(self, queryset=None):
|
||||||
|
|
|
@ -28,20 +28,11 @@
|
||||||
</span>
|
</span>
|
||||||
{% if post.is_editable_by(request.user) %}
|
{% if post.is_editable_by(request.user) %}
|
||||||
<span> [<a href="{{ url('admin:judge_blogpost_change', post.id) }}">{{ _('Edit') }}</a>]</span>
|
<span> [<a href="{{ url('admin:judge_blogpost_change', post.id) }}">{{ _('Edit') }}</a>]</span>
|
||||||
{% else %}
|
{% elif valid_user %}
|
||||||
{% for author in post.authors.all() %}
|
{% for org in valid_org %}
|
||||||
{% if author.user == request.user %}
|
<span> [<a href="{{ url('edit_organization_blog', org.id , org.slug , post.id) }}">{{ _('Edit in') }} {{org.slug}}</a>]</span>
|
||||||
{% for post_org in post.organizations.all() %}
|
|
||||||
{% for org in author.organizations.all() %}
|
|
||||||
{% if org == post_org %}
|
|
||||||
<span> [<a href="{{ url('edit_organization_blog', org.id , org.slug , post.id) }}">{{ _('Edit') }}</a>]</span>
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="body content-description">
|
<div class="body content-description">
|
||||||
{% cache 86400 'post_content' post.id MATH_ENGINE %}
|
{% cache 86400 'post_content' post.id MATH_ENGINE %}
|
||||||
|
|
Loading…
Reference in a new issue