Apply pycodestyle recommendations on template tags
This commit is contained in:
parent
8693d9e095
commit
e123331b02
4 changed files with 51 additions and 9 deletions
|
@ -4,59 +4,78 @@ from django.contrib.auth.models import User
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
def abcSort(inlist):
|
def abcSort(inlist):
|
||||||
return sorted(inlist, key=lambda x: str(x))
|
return sorted(inlist, key=lambda x: str(x))
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def allOrgas():
|
def allOrgas():
|
||||||
return abcSort(Organization.objects.all())
|
return abcSort(Organization.objects.all())
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def allNets():
|
def allNets():
|
||||||
return abcSort(Network.objects.all())
|
return abcSort(Network.objects.all())
|
||||||
|
|
||||||
|
|
||||||
def orgaObjects(cls, orga):
|
def orgaObjects(cls, orga):
|
||||||
return abcSort(set(cls.objects.filter(organization__in=orga)))
|
return abcSort(set(cls.objects.filter(organization__in=orga)))
|
||||||
|
|
||||||
|
|
||||||
def directUserOrgas(user):
|
def directUserOrgas(user):
|
||||||
return abcSort(user.organization_set.all())
|
return abcSort(user.organization_set.all())
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def directOrgaString(user):
|
def directOrgaString(user):
|
||||||
return ", ".join(str(orga) for orga in directUserOrgas(user))
|
return ", ".join(str(orga) for orga in directUserOrgas(user))
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def directOrgaAjax(user):
|
def directOrgaAjax(user):
|
||||||
return "[" + ",".join(str(orga.id) for orga in directUserOrgas(user)) + "]"
|
return "[" + ",".join(str(orga.id) for orga in directUserOrgas(user)) + "]"
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True)
|
@register.simple_tag(takes_context=True)
|
||||||
def userOrgas(context):
|
def userOrgas(context):
|
||||||
return directUserOrgas(context.request.user)
|
return directUserOrgas(context.request.user)
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True)
|
@register.simple_tag(takes_context=True)
|
||||||
def orgaString(context):
|
def orgaString(context):
|
||||||
return directOrgaString(context.request.user)
|
return directOrgaString(context.request.user)
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True)
|
@register.simple_tag(takes_context=True)
|
||||||
def userDevices(context):
|
def userDevices(context):
|
||||||
return orgaObjects(Device, userOrgas(context))
|
return orgaObjects(Device, userOrgas(context))
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True)
|
@register.simple_tag(takes_context=True)
|
||||||
def userWifis(context):
|
def userWifis(context):
|
||||||
return orgaObjects(Wifi, userOrgas(context))
|
return orgaObjects(Wifi, userOrgas(context))
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True)
|
@register.simple_tag(takes_context=True)
|
||||||
def userUsers(context):
|
def userUsers(context):
|
||||||
return orgaObjects(User, userOrgas(context))
|
return orgaObjects(User, userOrgas(context))
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True)
|
@register.simple_tag(takes_context=True)
|
||||||
def userNets(context):
|
def userNets(context):
|
||||||
return orgaObjects(Network, userOrgas(context))
|
return orgaObjects(Network, userOrgas(context))
|
||||||
|
|
||||||
|
|
||||||
|
def netOrgas(network):
|
||||||
|
return network.organization.all()
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def netOrgaString(network):
|
def netOrgaString(network):
|
||||||
return ", ".join(str(orga) for orga in network.organization.all())
|
return ", ".join(str(orga) for orga in netOrgas(network))
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def netOrgaAjax(network):
|
def netOrgaAjax(network):
|
||||||
return "[" + ",".join(str(orga.id) for orga in network.organization.all()) + "]"
|
return "[" + ",".join(str(orga.id) for orga in netOrgas(network)) + "]"
|
||||||
|
|
|
@ -5,14 +5,27 @@ from django.db.models import Q
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag('manager/notifications.html', takes_context=True)
|
@register.inclusion_tag('manager/notifications.html', takes_context=True)
|
||||||
def getNotifications(context, login=False):
|
def getNotifications(context, login=False):
|
||||||
notifications = [notification for notification in Notification.objects.filter(Q(expiry__gte = timezone.now()) | Q(expiry = None)) if (notification.on_login or (not login)) ]
|
notfilter = Notification.objects.filter
|
||||||
|
filtered = notfilter(Q(expiry__gte=timezone.now()) | Q(expiry=None))
|
||||||
|
|
||||||
|
notifications = []
|
||||||
|
|
||||||
|
for notification in filtered:
|
||||||
|
if notification.on_login or not login:
|
||||||
|
notifications.append(notification)
|
||||||
|
|
||||||
if context.dicts[3]["exception"]:
|
if context.dicts[3]["exception"]:
|
||||||
exception = Notification()
|
exception = Notification()
|
||||||
exception.status = 2
|
exception.status = 2
|
||||||
exception.text = context.dicts[3]["exception"].human
|
exception.text = context.dicts[3]["exception"].human
|
||||||
if context.dicts[3]["user"].is_superuser:
|
if context.dicts[3]["user"].is_superuser:
|
||||||
exception.text += "<br><br><code>" + str(context.dicts[3]["exception"]) + "</code>"
|
exception.text += (
|
||||||
|
"<br><br><code>"
|
||||||
|
str(context.dicts[3]["exception"])
|
||||||
|
"</code>"
|
||||||
|
)
|
||||||
notifications = [exception] + notifications
|
notifications = [exception] + notifications
|
||||||
return {'notifications': notifications}
|
return {'notifications': notifications}
|
||||||
|
|
|
@ -4,16 +4,24 @@ from git import Repo
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def getCommit():
|
def getCommit():
|
||||||
repo = Repo(settings.BASE_DIR)
|
repo = Repo(settings.BASE_DIR)
|
||||||
return "%s (%s)" % (str(repo.head.commit)[:7], str(repo.head.commit.committed_datetime))
|
return "%s (%s)" % (
|
||||||
|
str(repo.head.commit)[:7],
|
||||||
|
str(repo.head.commit.committed_datetime)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def isLatestCommit():
|
def isLatestCommit():
|
||||||
repo = Repo(settings.BASE_DIR)
|
repo = Repo(settings.BASE_DIR)
|
||||||
origin = repo.remotes[0].refs[0]
|
origin = repo.remotes[0].refs[0]
|
||||||
return "" if origin.commit.committed_datetime <= repo.head.commit.committed_datetime else " – Update available!"
|
if origin.commit.committed_datetime <= repo.head.commit.committed_datetime:
|
||||||
|
return ""
|
||||||
|
return " – Update available!"
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def isDirty():
|
def isDirty():
|
||||||
|
|
|
@ -5,6 +5,7 @@ from django.utils import timezone
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def updateUserStatus(user, sec=False):
|
def updateUserStatus(user, sec=False):
|
||||||
if user.is_authenticated:
|
if user.is_authenticated:
|
||||||
|
@ -22,6 +23,7 @@ def updateUserStatus(user, sec = False):
|
||||||
return "<!-- %s -->" % str(e)
|
return "<!-- %s -->" % str(e)
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True)
|
@register.simple_tag(takes_context=True)
|
||||||
def setUser(context):
|
def setUser(context):
|
||||||
return context.request.user
|
return context.request.user
|
||||||
|
|
Loading…
Reference in a new issue