forked from RobbieHan/sandboxMP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
687 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# @Time : 2018/12/19 16:13 | ||
# @Author : RobbieHan | ||
# @File : forms.py | ||
|
||
from django import forms | ||
|
||
from .models import Code | ||
|
||
|
||
class CodeCreateForm(forms.ModelForm): | ||
class Meta: | ||
model = Code | ||
fields = '__all__' | ||
|
||
error_messages = { | ||
'key': {'required': 'key不能为空'}, | ||
'value': {'required': 'value不能为空'} | ||
} | ||
|
||
def clean(self): | ||
cleaned_data = super(CodeCreateForm, self).clean() | ||
key = cleaned_data.get('key') | ||
value = cleaned_data.get('value') | ||
|
||
if Code.objects.filter(key=key).count(): | ||
raise forms.ValidationError('key:{}已存在'.format(key)) | ||
|
||
if Code.objects.filter(value=value).count(): | ||
raise forms.ValidationError('value: {}已存在'.format(value)) | ||
|
||
|
||
class CodeUpdateForm(CodeCreateForm): | ||
|
||
def clean(self): | ||
cleaned_data = self.cleaned_data | ||
key = cleaned_data.get('key') | ||
value = cleaned_data.get('value') | ||
|
||
if self.instance: | ||
matching_code = Code.objects.exclude(pk=self.instance.pk) | ||
if matching_code.filter(key=key).exists(): | ||
msg = 'key:{} 已经存在'.format(key) | ||
raise forms.ValidationError(msg) | ||
if matching_code.filter(value=value).exists(): | ||
msg = 'value:{} 已经存在'.format(value) | ||
raise forms.ValidationError(msg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
from django.urls import path | ||
|
||
from .views import CmdbView | ||
from . import views_code | ||
|
||
app_name = 'cmdb' | ||
|
||
urlpatterns = [ | ||
path('', CmdbView.as_view(), name='index'), | ||
path('portal/code/', views_code.CodeView.as_view(), name='portal-code'), | ||
path('portal/code/create/', views_code.CodeCreateView.as_view(), name='portal-code-create'), | ||
path('portal/code/list/', views_code.CodeListView.as_view(), name='portal-code-list'), | ||
path('portal/code/update/', views_code.CodeUpdateView.as_view(), name='portal-code-update'), | ||
path('portal/code/delete/', views_code.CodeDeleteView.as_view(), name='portal-code-delete'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# @Time : 2018/12/19 13:31 | ||
# @Author : RobbieHan | ||
# @File : views_code.py.py | ||
|
||
from django.views.generic import TemplateView | ||
|
||
from system.mixin import LoginRequiredMixin | ||
from custom import (BreadcrumbMixin, SandboxCreateView, | ||
SandboxListView, SandboxUpdateView, SandboxDeleteView) | ||
from .models import Code | ||
from .forms import CodeCreateForm, CodeUpdateForm | ||
|
||
|
||
class CodeView(LoginRequiredMixin, BreadcrumbMixin, TemplateView): | ||
template_name = 'cmdb/code.html' | ||
|
||
def get_context_data(self): | ||
context = dict(code_parent=Code.objects.filter(parent=None)) | ||
return context | ||
|
||
|
||
class CodeCreateView(SandboxCreateView): | ||
model = Code | ||
form_class = CodeCreateForm | ||
template_name_suffix = '_create' | ||
|
||
def get_context_data(self, **kwargs): | ||
kwargs['code_parent'] = Code.objects.filter(parent=None) | ||
return super().get_context_data(**kwargs) | ||
|
||
|
||
class CodeListView(SandboxListView): | ||
model = Code | ||
fields = ['id', 'key', 'value', 'parent__value'] | ||
|
||
def get(self, request): | ||
if 'parent' in request.GET and request.GET['parent']: | ||
self.filters = dict(parent__key=request.GET['parent']) | ||
return super().get(request) | ||
|
||
|
||
class CodeUpdateView(SandboxUpdateView): | ||
model = Code | ||
form_class = CodeUpdateForm | ||
template_name_suffix = '_update' | ||
|
||
def get_context_data(self, **kwargs): | ||
kwargs['code_parent'] = Code.objects.filter(parent=None) | ||
return super().get_context_data(**kwargs) | ||
|
||
|
||
class CodeDeleteView(SandboxDeleteView): | ||
model = Code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
django==2.1.2 | ||
pillow==5.3.0 | ||
-r pro.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,14 @@ | ||
django==2.1.2 | ||
pillow==5.3.0 | ||
pillow==5.3.0 | ||
mysqlclient==1.3.13 | ||
ipython==7.1.1 | ||
pyyaml==3.13 | ||
ruamel.yaml==0.15.80 | ||
python-nmap==0.6.1 | ||
redis==3.0.1 | ||
pymongo==3.7.1 | ||
paramiko==2.4.2 | ||
pycrypto==2.6.1 | ||
celery==4.2.1 | ||
celery-once==2.0.0 | ||
flower==0.9.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.