def edit_topic(request, id): topic = get_object_or_404(Topic, pk=id) if topic.user != request.user: return HttpResponseForbidden('<h1>您没有这个权限!</h1>') parents = get_parents(Catalog, topic.catalog.id) ip = ylinux_get_ip(request) form = build_form(EditTopicForm, request, text=topic.body, user_ip=ip, instance=topic) if form.is_valid(): topic = form.save() url = reverse('wiki:show_topic', args=[id]) return HttpResponseRedirect(url) attachments = Attachment.objects.filter(topic=topic) return { 'form': form, 'parents': parents, 'topic': topic, 'attachments': attachments }
def add_topic(request, id): ''' id 是 Catalog ''' if not id: return {'errors': '没有指定 Catalog'} catalog = get_object_or_404(Catalog, pk=id) if not catalog.has_access(request.user): return HttpResponseForbidden(u'<h2>你没有权限在此组中发贴!</h2>') parents = get_parents(Catalog, id) ip = ylinux_get_ip(request) form = build_form(AddTopicForm, request, catalog=catalog, user=request.user, user_ip=ip) if form.is_valid(): topic = form.save() # set last topic catalog.last_topic = topic catalog.save() url = reverse('wiki:show_topic', args=[topic.id]) return HttpResponseRedirect(url) return {'parents': parents, 'form': form}
def ajax_topic(request, id): try: topic = Topic.objects.get(pk=id) except Topic.DoesNotExist: url = reverse("wiki:topic_not_exist", args=[id]) return HttpResponseRedirect(url) parents = get_parents(Catalog, topic.catalog.id) edit_topic_perm = request.user.has_perm("ydata.edit_topic") return {"parents": parents, "topic": topic, "edit_topic_perm": edit_topic_perm}
def del_catalog(request, id): catalog = get_object_or_404(Catalog, pk=id) subcatalogs = Catalog.objects.filter(parent=id) if subcatalogs: parents = get_parents(Catalog, id) return {"catalog": catalog, "parents": parents, "subcatalogs": subcatalogs} catalog.delete() return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/"))
def catalog_forum(request, id): try: catalog = Catalog.objects.get(pk=id) except Catalog.DoesNotExist: url = reverse("wiki:catalog_not_exist", args=[id]) return HttpResponseRedirect(url) parents = get_parents(Catalog, id) catalogs = Catalog.objects.filter(parent=id) topics = Topic.objects.filter(catalog=id).exclude(hidden=1).exclude(recycled=1) return {"title": catalog.name, "parents": parents, "catalogs": catalogs, "topics": topics}
def catalog(request, id): try: catalog = Catalog.objects.get(pk=id) except Catalog.DoesNotExist: url = reverse('bbs:forum_not_exist', args=[id]) return HttpResponseRedirect(url) parents = get_parents(Catalog, id) topics = Topic.objects.filter(catalog=catalog) return {'catalog': catalog, 'parents': parents, 'topics': topics}
def catalog(request, id): try: catalog = Catalog.objects.get(pk=id) except Catalog.DoesNotExist: url = reverse("bbs:forum_not_exist", args=[id]) return HttpResponseRedirect(url) parents = get_parents(Catalog, id) topics = Topic.objects.filter(catalog=catalog) return {"catalog": catalog, "parents": parents, "topics": topics}
def topic(request, id): try: topic = Topic.objects.get(pk=id) except Topic.DoesNotExist: url = reverse('bbs:topic_not_exist', args=[id]) return HttpResponseRedirect(url) parents = get_parents(Catalog, topic.catalog.id) posts = Post.objects.filter(topic=topic) return {'topic': topic, 'parents': parents, 'posts': posts}
def topic(request, id): try: topic = Topic.objects.get(pk=id) except Topic.DoesNotExist: url = reverse("bbs:topic_not_exist", args=[id]) return HttpResponseRedirect(url) parents = get_parents(Catalog, topic.catalog.id) posts = Post.objects.filter(topic=topic) return {"topic": topic, "parents": parents, "posts": posts}
def edit_catalog(request, id): catalog = get_object_or_404(Catalog, pk=id) parents = get_parents(Catalog, id) form = build_form(EditCatalogForm, request, parent=catalog.parent, instance=catalog) if form.is_valid(): catalog = form.save() url = reverse("admin:show_catalog", args=[catalog.id]) return HttpResponseRedirect(url) return {"form": form, "parents": parents, "catalog": catalog}
def ajax_add_topic(request, id): if not id: return {"errors": "没有指定 Catalog"} catalog = get_object_or_404(Catalog, pk=id) if not catalog.has_access(request.user): return HttpResponseForbidden(u"<h2>你没有权限在此组中发贴!</h2>") parents = get_parents(Catalog, id) ip = ylinux_get_ip(request) form = build_form(AddTopicForm, request, catalog=catalog, user=request.user, user_ip=ip) return {"parents": parents, "form": form, "id": id}
def del_catalog(request, id): catalog = get_object_or_404(Catalog, pk=id) subcatalogs = Catalog.objects.filter(parent=id) if subcatalogs: parents = get_parents(Catalog, id) return { 'catalog': catalog, 'parents': parents, 'subcatalogs': subcatalogs } catalog.delete() return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
def ajax_topic(request, id): try: topic = Topic.objects.get(pk=id) except Topic.DoesNotExist: url = reverse('wiki:topic_not_exist', args=[id]) return HttpResponseRedirect(url) parents = get_parents(Catalog, topic.catalog.id) edit_topic_perm = request.user.has_perm('ydata.edit_topic') return { 'parents': parents, 'topic': topic, 'edit_topic_perm': edit_topic_perm }
def edit_catalog(request, id): catalog = get_object_or_404(Catalog, pk=id) parents = get_parents(Catalog, id) form = build_form(EditCatalogForm, request, parent=catalog.parent, instance=catalog) if form.is_valid(): catalog = form.save() url = reverse('admin:show_catalog', args=[catalog.id]) return HttpResponseRedirect(url) return {'form': form, 'parents': parents, 'catalog': catalog}
def show_catalog(request, id): catalog = get_object_or_404(Catalog, pk=id) subcatalogs = Catalog.objects.filter(parent=id) parents = get_parents(Catalog, id) if hasattr(request, 'user'): create_catalog = request.user.has_perm('ydata.create_catalog') edit_catalog = request.user.has_perm('ydata.edit_catalog') delete_catalog = request.user.has_perm('ydata.delete_catalog') return { 'catalog': catalog, 'parents': parents, 'subcatalogs': subcatalogs, 'create_catalog': create_catalog, 'edit_catalog': edit_catalog, 'delete_catalog': delete_catalog }
def ajax_add_topic(request, id): if not id: return {'errors': '没有指定 Catalog'} catalog = get_object_or_404(Catalog, pk=id) if not catalog.has_access(request.user): return HttpResponseForbidden(u'<h2>你没有权限在此组中发贴!</h2>') parents = get_parents(Catalog, id) ip = ylinux_get_ip(request) form = build_form(AddTopicForm, request, catalog=catalog, user=request.user, user_ip=ip) return {'parents': parents, 'form': form, 'id': id}
def show_catalog(request, id): catalog = get_object_or_404(Catalog, pk=id) subcatalogs = Catalog.objects.filter(parent=id) parents = get_parents(Catalog, id) if hasattr(request, "user"): create_catalog = request.user.has_perm("ydata.create_catalog") edit_catalog = request.user.has_perm("ydata.edit_catalog") delete_catalog = request.user.has_perm("ydata.delete_catalog") return { "catalog": catalog, "parents": parents, "subcatalogs": subcatalogs, "create_catalog": create_catalog, "edit_catalog": edit_catalog, "delete_catalog": delete_catalog, }
def catalog_forum(request, id): try: catalog = Catalog.objects.get(pk=id) except Catalog.DoesNotExist: url = reverse('wiki:catalog_not_exist', args=[id]) return HttpResponseRedirect(url) parents = get_parents(Catalog, id) catalogs = Catalog.objects.filter(parent=id) topics = Topic.objects.filter(catalog=id).exclude(hidden=1).exclude( recycled=1) return { 'title': catalog.name, 'parents': parents, 'catalogs': catalogs, 'topics': topics }
def edit_topic(request, id): topic = get_object_or_404(Topic, pk=id) if topic.user != request.user: return HttpResponseForbidden("<h1>您没有这个权限!</h1>") parents = get_parents(Catalog, topic.catalog.id) ip = ylinux_get_ip(request) form = build_form(EditTopicForm, request, text=topic.body, user_ip=ip, instance=topic) if form.is_valid(): topic = form.save() url = reverse("wiki:show_topic", args=[id]) return HttpResponseRedirect(url) attachments = Attachment.objects.filter(topic=topic) return {"form": form, "parents": parents, "topic": topic, "attachments": attachments}
def add_catalog(request, parent_id=None): if parent_id: catalog = get_object_or_404(Catalog, pk=parent_id) parents = get_parents(Catalog, catalog.id) form = build_form(AddCatalogForm, request, parent=catalog) else: form = build_form(AddCatalogForm, request) if form.is_valid(): catalog = form.save() url = reverse("admin:show_catalog", args=[catalog.id]) return HttpResponseRedirect(url) if parent_id: return {"catalog": catalog, "form": form, "parents": parents} else: return {"form": form}
def ajax_show_catalog(request, id): try: catalog = Catalog.objects.get(pk=id) except Catalog.DoesNotExist: # url = reverse ('wiki:catalog_not_exist', args=[id]) # return HttpResponseRedirect(url) return {"error": u"此目录不存在: %s" % id} parents = get_parents(Catalog, id) topics = Topic.objects.filter(catalog=id).exclude(hidden=1).exclude(recycled=1).order_by("-updated")[:5] edit_topic_perm = request.user.has_perm("ydata.edit_topic") return { "catalog": catalog, "parents": parents, "topics": topics, "title": u"[知识库] 目录浏览", "edit_topic_perm": edit_topic_perm, }
def catalog(request, id=None, curpage=0): PERPAGE = 20 if id: try: catalog = Catalog.objects.get(pk=id) except Catalog.DoesNotExist: url = reverse("wiki:catalog_not_exist", args=[id]) return HttpResponseRedirect(url) parents = get_parents(Catalog, id) else: catalog = None parents = None subcatalogs = Catalog.objects.filter(parent=id) topics = Topic.objects.filter(catalog=id).exclude(hidden=1).exclude(recycled=1).order_by("-updated")[curpage:20] pages = [ i + 1 for i in range( int( math.ceil( Topic.objects.filter(catalog=id).exclude(hidden=1).exclude(recycled=1).count() / float(PERPAGE) ) ) ) ] edit_topic_perm = request.user.has_perm("ydata.edit_topic") return { "catalog": catalog, "parents": parents, "subcatalogs": subcatalogs, "topics": topics, "title": u"[知识库] 目录浏览", "edit_topic_perm": edit_topic_perm, "curpage": curpage + 1, "pages": pages, }
def ajax_show_catalog(request, id): try: catalog = Catalog.objects.get(pk=id) except Catalog.DoesNotExist: #url = reverse ('wiki:catalog_not_exist', args=[id]) #return HttpResponseRedirect(url) return {'error': u'此目录不存在: %s' % id} parents = get_parents(Catalog, id) topics = Topic.objects.filter(catalog=id).exclude(hidden=1).exclude( recycled=1).order_by('-updated')[:5] edit_topic_perm = request.user.has_perm('ydata.edit_topic') return { 'catalog': catalog, 'parents': parents, 'topics': topics, 'title': u'[知识库] 目录浏览', 'edit_topic_perm': edit_topic_perm }
def add_topic(request, id): """ id 是 Catalog """ if not id: return {"errors": "没有指定 Catalog"} catalog = get_object_or_404(Catalog, pk=id) if not catalog.has_access(request.user): return HttpResponseForbidden(u"<h2>你没有权限在此组中发贴!</h2>") parents = get_parents(Catalog, id) ip = ylinux_get_ip(request) form = build_form(AddTopicForm, request, catalog=catalog, user=request.user, user_ip=ip) if form.is_valid(): topic = form.save() # set last topic catalog.last_topic = topic catalog.save() url = reverse("wiki:show_topic", args=[topic.id]) return HttpResponseRedirect(url) return {"parents": parents, "form": form}
def catalog(request, id=None, curpage=0): PERPAGE = 20 if id: try: catalog = Catalog.objects.get(pk=id) except Catalog.DoesNotExist: url = reverse('wiki:catalog_not_exist', args=[id]) return HttpResponseRedirect(url) parents = get_parents(Catalog, id) else: catalog = None parents = None subcatalogs = Catalog.objects.filter(parent=id) topics = Topic.objects.filter(catalog=id).exclude(hidden=1).exclude( recycled=1).order_by('-updated')[curpage:20] pages = [ i + 1 for i in range( int( math.ceil( Topic.objects.filter(catalog=id).exclude(hidden=1).exclude( recycled=1).count() / float(PERPAGE)))) ] edit_topic_perm = request.user.has_perm('ydata.edit_topic') return { 'catalog': catalog, 'parents': parents, 'subcatalogs': subcatalogs, 'topics': topics, 'title': u'[知识库] 目录浏览', 'edit_topic_perm': edit_topic_perm, 'curpage': curpage + 1, 'pages': pages }
def topic(request, id): try: topic = Topic.objects.get(pk=id) except Topic.DoesNotExist: url = reverse('wiki:topic_not_exist', args=[id]) return HttpResponseRedirect(url) parents = get_parents(Catalog, topic.catalog.id) edit_topic_perm = request.user.has_perm('ydata.edit_topic') posts = Post.objects.filter(topic=id, parent=None).order_by('created') POST_HTML = '' for p in posts: POST_HTML += render_post(request.user, p) return { 'parents': parents, 'topic': topic, 'edit_topic_perm': edit_topic_perm, 'title': u"[知识库]%s" % topic.name, 'POST_HTML': POST_HTML, 'posts': posts }
def add_catalog(request, parent_id=None): if parent_id: catalog = get_object_or_404(Catalog, pk=parent_id) parents = get_parents(Catalog, catalog.id) form = build_form(AddCatalogForm, request, parent=catalog) else: form = build_form(AddCatalogForm, request) if form.is_valid(): catalog = form.save() url = reverse('admin:show_catalog', args=[catalog.id]) return HttpResponseRedirect(url) if parent_id: return { 'catalog': catalog, 'form': form, 'parents': parents, } else: return {'form': form}
def topic(request, id): try: topic = Topic.objects.get(pk=id) except Topic.DoesNotExist: url = reverse("wiki:topic_not_exist", args=[id]) return HttpResponseRedirect(url) parents = get_parents(Catalog, topic.catalog.id) edit_topic_perm = request.user.has_perm("ydata.edit_topic") posts = Post.objects.filter(topic=id, parent=None).order_by("created") POST_HTML = "" for p in posts: POST_HTML += render_post(request.user, p) return { "parents": parents, "topic": topic, "edit_topic_perm": edit_topic_perm, "title": u"[知识库]%s" % topic.name, "POST_HTML": POST_HTML, "posts": posts, }