Commit 884b3da5 authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

Merge branch 'flake8_f401_webapp_main' into 'master'

flake8_f401_webapp_main

See merge request noc/noc!1974
parents 426a8f00 526ad6fb
......@@ -2,12 +2,12 @@
# ---------------------------------------------------------------------
# main.pool application
# ---------------------------------------------------------------------
# Copyright (C) 2007-2015 The NOC Project
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# NOC modules
from noc.lib.app.extdocapplication import ExtDocApplication, view
from noc.lib.app.extdocapplication import ExtDocApplication
from noc.main.models.pool import Pool
from noc.core.translation import ugettext as _
......
......@@ -2,7 +2,7 @@
# ---------------------------------------------------------------------
# main.refbook application
# ---------------------------------------------------------------------
# Copyright (C) 2007-2016 The NOC Project
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
......@@ -10,7 +10,7 @@
from django.views.generic import list_detail
from django.shortcuts import get_object_or_404
# NOC modules
from noc.lib.app.application import Application, view, HasPerm
from noc.lib.app.application import Application, view
from noc.main.models.permission import Permission
from noc.main.models.refbook import RefBook
from noc.main.models.refbookdata import RefBookData
......@@ -20,20 +20,17 @@ from noc.core.translation import ugettext as _
class RefBookAppplication(Application):
title = _("Reference Books")
@view(url=r"^$", url_name="index",
menu=[_("Setup"), _("Reference Books")], access="view")
@view(url=r"^$", url_name="index", menu=[_("Setup"), _("Reference Books")], access="view")
def view_index(self, request):
"""
Render list of refbooks
:param request:
:return:
"""
ref_books = RefBook.objects.filter(is_enabled=True).order_by(
"name")
ref_books = RefBook.objects.filter(is_enabled=True).order_by("name")
return self.render(request, "index.html", ref_books=ref_books)
@view(url=r"^(?P<refbook_id>\d+)/$",
url_name="view", access="view")
@view(url=r"^(?P<refbook_id>\d+)/$", url_name="view", access="view")
def view_view(self, request, refbook_id):
"""
Refbook preview
......@@ -42,19 +39,15 @@ class RefBookAppplication(Application):
:return:
"""
rb = get_object_or_404(RefBook, id=int(refbook_id))
can_edit = (not rb.is_builtin and
Permission.has_perm(request.user,
"main.change_refbookdata"))
can_edit = (not rb.is_builtin and Permission.has_perm(request.user, "main.change_refbookdata"))
queryset = rb.refbookdata_set.all()
# Search
if (request.GET and
"query" in request.GET and request.GET["query"]):
if (request.GET and "query" in request.GET and request.GET["query"]):
query = request.GET["query"]
# Build query clause
w = []
p = []
for f in rb.refbookfield_set.filter(
search_method__isnull=False):
for f in rb.refbookfield_set.filter(search_method__isnull=False):
x = f.get_extra(query)
if not x:
continue
......@@ -74,8 +67,7 @@ class RefBookAppplication(Application):
paginate_by=100,
)
@view(url=r"^(?P<refbook_id>\d+)/(?P<record_id>\d+)/$",
url_name="item", access="view")
@view(url=r"^(?P<refbook_id>\d+)/(?P<record_id>\d+)/$", url_name="item", access="view")
def view_item(self, request, refbook_id, record_id):
"""
Item preview
......@@ -85,16 +77,11 @@ class RefBookAppplication(Application):
:return:
"""
rb = get_object_or_404(RefBook, id=int(refbook_id))
rbr = get_object_or_404(RefBookData, id=int(record_id),
ref_book=rb)
can_edit = (not rb.is_builtin and
Permission.has_perm(request.user,
"main.change_refbookdata"))
return self.render(request, "item.html",
{"rb": rb, "record": rbr, "can_edit": can_edit})
rbr = get_object_or_404(RefBookData, id=int(record_id), ref_book=rb)
can_edit = (not rb.is_builtin and Permission.has_perm(request.user, "main.change_refbookdata"))
return self.render(request, "item.html", {"rb": rb, "record": rbr, "can_edit": can_edit})
@view(url=r"^(?P<refbook_id>\d+)/(?P<record_id>\d+)/edit/$",
url_name="edit", access="change")
@view(url=r"^(?P<refbook_id>\d+)/(?P<record_id>\d+)/edit/$", url_name="edit", access="change")
def view_edit(self, request, refbook_id, record_id=0):
"""
Edit item
......@@ -104,11 +91,8 @@ class RefBookAppplication(Application):
:return:
"""
rb = get_object_or_404(RefBook, id=int(refbook_id))
rbr = get_object_or_404(RefBookData, id=int(record_id),
ref_book=rb)
can_edit = (not rb.is_builtin and
Permission.has_perm(request.user,
"main.change_refbookdata"))
rbr = get_object_or_404(RefBookData, id=int(record_id), ref_book=rb)
can_edit = (not rb.is_builtin and Permission.has_perm(request.user, "main.change_refbookdata"))
if not can_edit:
return self.response_forbidden("Read-only refbook")
if request.POST: # Edit refbook
......@@ -123,13 +107,10 @@ class RefBookAppplication(Application):
rbr.value = data
rbr.save()
self.message_user(request, "Record updated successfully")
return self.response_redirect("main:refbook:item", rb.id,
rbr.id)
return self.render(request, "edit.html",
{"rb": rb, "record": rbr})
return self.response_redirect("main:refbook:item", rb.id, rbr.id)
return self.render(request, "edit.html", {"rb": rb, "record": rbr})
@view(url=r"^(?P<refbook_id>\d+)/(?P<record_id>\d+)/delete/$",
url_name="delete", access="delete")
@view(url=r"^(?P<refbook_id>\d+)/(?P<record_id>\d+)/delete/$", url_name="delete", access="delete")
def view_delete(self, request, refbook_id, record_id):
"""
Delete refbook record
......@@ -139,19 +120,15 @@ class RefBookAppplication(Application):
:return:
"""
rb = get_object_or_404(RefBook, id=int(refbook_id))
can_edit = (not rb.is_builtin and
Permission.has_perm(request.user,
"main.change_refbookdata"))
can_edit = (not rb.is_builtin and Permission.has_perm(request.user, "main.change_refbookdata"))
if not can_edit:
return self.response_forbidden()
rbd = get_object_or_404(RefBookData, ref_book=rb,
id=int(record_id))
rbd = get_object_or_404(RefBookData, ref_book=rb, id=int(record_id))
rbd.delete()
self.message_user(request, "Record deleted")
return self.response_redirect("main:refbook:view", rb.id)
@view(url=r"^(?P<refbook_id>\d+)/new/$", url_name="new",
access="add")
@view(url=r"^(?P<refbook_id>\d+)/new/$", url_name="new", access="add")
def view_new(self, request, refbook_id):
"""
Create refbook record
......@@ -160,9 +137,7 @@ class RefBookAppplication(Application):
:return:
"""
rb = get_object_or_404(RefBook, id=int(refbook_id))
can_edit = (not rb.is_builtin and
Permission.has_perm(request.user,
"main.change_refbookdata"))
can_edit = (not rb.is_builtin and Permission.has_perm(request.user, "main.change_refbookdata"))
if not can_edit:
return self.response_forbidden("Read-only refbook")
if request.POST: # Edit refbook
......@@ -177,6 +152,5 @@ class RefBookAppplication(Application):
rbr = RefBookData(ref_book=rb, value=data)
rbr.save()
self.message_user(request, "Record added")
return self.response_redirect("main:refbook:item", rb.id,
rbr.id)
return self.response_redirect("main:refbook:item", rb.id, rbr.id)
return self.render(request, "new.html", {"rb": rb})
......@@ -2,12 +2,12 @@
# ---------------------------------------------------------------------
# main.reportsubscription application
# ---------------------------------------------------------------------
# Copyright (C) 2007-2016 The NOC Project
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# NOC modules
from noc.lib.app.extdocapplication import ExtDocApplication, view
from noc.lib.app.extdocapplication import ExtDocApplication
from noc.lib.app.site import site
from noc.main.models.reportsubscription import ReportSubscription
from noc.core.translation import ugettext as _
......
......@@ -2,12 +2,12 @@
# ---------------------------------------------------------------------
# main.resourcestate application
# ---------------------------------------------------------------------
# Copyright (C) 2007-2012 The NOC Project
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# NOC modules
from noc.lib.app.extmodelapplication import ExtModelApplication, view
from noc.lib.app.extmodelapplication import ExtModelApplication
from noc.main.models import ResourceState
from noc.core.translation import ugettext as _
......
......@@ -2,12 +2,12 @@
# ---------------------------------------------------------------------
# main.template application
# ---------------------------------------------------------------------
# Copyright (C) 2007-2012 The NOC Project
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# NOC modules
from noc.lib.app.extmodelapplication import ExtModelApplication, view
from noc.lib.app.extmodelapplication import ExtModelApplication
from noc.main.models.template import Template
from noc.core.translation import ugettext as _
......@@ -20,4 +20,3 @@ class TemplateApplication(ExtModelApplication):
menu = [_("Setup"), _("Templates")]
model = Template
query_fields = ["name__icontains", "subject__icontains"]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment