Add parts application to django and start basic template
This commit is contained in:
0
shimatta_kenkyusho/parts/__init__.py
Normal file
0
shimatta_kenkyusho/parts/__init__.py
Normal file
3
shimatta_kenkyusho/parts/admin.py
Normal file
3
shimatta_kenkyusho/parts/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
6
shimatta_kenkyusho/parts/apps.py
Normal file
6
shimatta_kenkyusho/parts/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class PartsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'parts'
|
0
shimatta_kenkyusho/parts/migrations/__init__.py
Normal file
0
shimatta_kenkyusho/parts/migrations/__init__.py
Normal file
3
shimatta_kenkyusho/parts/models.py
Normal file
3
shimatta_kenkyusho/parts/models.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
69
shimatta_kenkyusho/parts/navbar.py
Normal file
69
shimatta_kenkyusho/parts/navbar.py
Normal file
@@ -0,0 +1,69 @@
|
||||
from django.urls import reverse
|
||||
from django.conf import settings
|
||||
|
||||
class BsNavBarItem():
|
||||
link = ''
|
||||
name = ''
|
||||
active = True
|
||||
|
||||
def __init__(self, name, link, active):
|
||||
self.link = link
|
||||
self.name = name
|
||||
self.active = active
|
||||
|
||||
def active_class(self):
|
||||
if self.active:
|
||||
return "active"
|
||||
else:
|
||||
return ""
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class NavBar():
|
||||
|
||||
brand = ''
|
||||
navitems = []
|
||||
|
||||
has_user = False
|
||||
username = ''
|
||||
show_admin = False
|
||||
|
||||
@staticmethod
|
||||
def get_navbar(active_entry, user = None):
|
||||
items = {
|
||||
'Main': BsNavBarItem('Main', reverse('parts-main'), False),
|
||||
'Components':BsNavBarItem('Components', reverse('parts-main'), False),
|
||||
'Stocks':BsNavBarItem('Stocks', reverse('parts-main'), False),
|
||||
'Login':BsNavBarItem('Login', reverse('parts-main'), False),
|
||||
}
|
||||
|
||||
try:
|
||||
items[active_entry].active = True
|
||||
except:
|
||||
pass
|
||||
|
||||
navitems = [
|
||||
items['Main'],
|
||||
items['Components'],
|
||||
items['Stocks'],
|
||||
#items['Login'],
|
||||
]
|
||||
nb = NavBar()
|
||||
nb.has_user = False
|
||||
nb.show_admin = False
|
||||
if user is not None:
|
||||
if user.is_authenticated:
|
||||
nb.has_user = True
|
||||
nb.username = user.username
|
||||
if user.is_superuser:
|
||||
nb.show_admin = True
|
||||
|
||||
nb.navitems = navitems
|
||||
nb.brand = NavBar.get_brand()
|
||||
|
||||
return nb
|
||||
|
||||
@staticmethod
|
||||
def get_brand():
|
||||
return getattr(settings, "SHIMATTA_KENKYUSHO_TITLE", 'Lab System')
|
3
shimatta_kenkyusho/parts/tests.py
Normal file
3
shimatta_kenkyusho/parts/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
6
shimatta_kenkyusho/parts/urls.py
Normal file
6
shimatta_kenkyusho/parts/urls.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.urls import path, include
|
||||
from . import views as parts_views
|
||||
|
||||
urlpatterns = [
|
||||
path('', parts_views.main_view, name='parts-main')
|
||||
]
|
20
shimatta_kenkyusho/parts/views.py
Normal file
20
shimatta_kenkyusho/parts/views.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from django.shortcuts import render, redirect
|
||||
from django.urls import resolve, reverse
|
||||
|
||||
from django.http import HttpResponse
|
||||
from .navbar import NavBar
|
||||
|
||||
def main_view(request):
|
||||
|
||||
|
||||
base_context = {
|
||||
'navbar': NavBar.get_navbar('Main', request.user),
|
||||
'title': NavBar.get_brand()+' / '+'Main',
|
||||
}
|
||||
context = {
|
||||
'base': base_context,
|
||||
}
|
||||
|
||||
return render(request, 'parts/main.html', context)
|
||||
|
||||
# Create your views here.
|
Reference in New Issue
Block a user