Skip to content

Commit

Permalink
new delivery app
Browse files Browse the repository at this point in the history
  • Loading branch information
guohongze committed Aug 7, 2017
1 parent 96ed24c commit 86bccc4
Show file tree
Hide file tree
Showing 17 changed files with 369 additions and 2 deletions.
1 change: 1 addition & 0 deletions adminset/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
'accounts',
'monitor',
'appconf',
'delivery',
'django_celery_results',
'django_celery_beat',
'django.contrib.admin',
Expand Down
1 change: 1 addition & 0 deletions adminset/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
url(r'^config/', include('config.urls')),
url(r'^accounts/', include('accounts.urls')),
url(r'^appconf/', include('appconf.urls')),
url(r'^delivery/', include('delivery.urls')),
]
3 changes: 3 additions & 0 deletions appconf/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ class Project(models.Model):
verbose_name=u"服务器"
)

def __unicode__(self):
return self.name




Expand Down
2 changes: 1 addition & 1 deletion appconf/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import project

urlpatterns = [
url(r'^/$', product.product_list, name='appconf'),
url(r'^$', product.product_list, name='appconf'),
url(r'^appowner/add/$', appowner.appowner_add, name='appowner_add'),
url(r'^appowner/list/$', appowner.appowner_list, name='appowner_list'),
url(r'^appowner/edit/(?P<appowner_id>\d+)/$', appowner.appowner_edit, name='appowner_edit'),
Expand Down
Empty file added delivery/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions delivery/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
7 changes: 7 additions & 0 deletions delivery/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from __future__ import unicode_literals

from django.apps import AppConfig


class DeliveryConfig(AppConfig):
name = 'delivery'
80 changes: 80 additions & 0 deletions delivery/delivery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-

from django.shortcuts import render, HttpResponseRedirect, RequestContext
from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required
from models import Delivery
from forms import DeliveryFrom
from accounts.permission import permission_verify


@login_required()
@permission_verify()
def delivery_list(request):
temp_name = "delivery/delivery-header.html"
all_project = Delivery.objects.all()
results = {
'temp_name': temp_name,
'all_project': all_project,
}
return render(request, 'delivery/delivery_list.html', results)


@login_required
@permission_verify()
def delivery_del(request):
project_id = request.GET.get('project_id', '')
if project_id:
Delivery.objects.filter(id=project_id).delete()

project_id_all = str(request.POST.get('project_id_all', ''))
if project_id_all:
for project_id in project_id_all.split(','):
Delivery.objects.filter(id=project_id).delete()

return HttpResponseRedirect(reverse('delivery_list'), RequestContext(request))


@login_required
@permission_verify()
def delivery_add(request):
temp_name = "delivery/delivery-header.html"
if request.method == 'POST':
form = DeliveryFrom(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('delivery_list'), RequestContext(request))
else:
form = DeliveryFrom()

results = {
'form': form,
'request': request,
'temp_name': temp_name,
}
return render(request, 'delivery/delivery_base.html', results)


@login_required
@permission_verify()
def delivery_edit(request, project_id):
project = Delivery.objects.get(id=project_id)
temp_name = "delivery/delivery-header.html"
if request.method == 'POST':
form = DeliveryFrom(request.POST, instance=project)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('project_list'), RequestContext(request))
else:
form = DeliveryFrom(instance=project)

results = {
'form': form,
'project_id': project_id,
'request': request,
'temp_name': temp_name,
}
return render(request, 'delivery/delivery_base.html', results)


22 changes: 22 additions & 0 deletions delivery/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from django import forms
from django.forms import widgets
from models import Delivery


class DeliveryFrom(forms.ModelForm):

class Meta:
model = Delivery
exclude = ("id",)

widgets = {
'job_name': widgets.Select(attrs={'class': 'form-control','style': 'width:450px;'}),
'description': widgets.Textarea(attrs={'class': 'form-control','style': 'width:450px; height:100px'}),
'deploy_policy': widgets.Select(attrs={'class': 'form-control','style': 'width:450px;'}),
'source_type': widgets.Select(attrs={'class': 'form-control','style': 'width:450px;'}),
'source_address': widgets.TextInput(attrs={'class': 'form-control','style': 'width:450px;'}),
'destination_address': widgets.TextInput(attrs={'class': 'form-control','style': 'width:450px;'}),
'shell': widgets.Select(attrs={'class': 'form-control','style': 'width:450px;'}),
}
Empty file added delivery/migrations/__init__.py
Empty file.
30 changes: 30 additions & 0 deletions delivery/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models
from appconf.models import Project
# Create your models here.
DEPLOY_POLICY = (
("Direct", "Direct"),
("BlueGreen", "BlueGreen"),
)

SOURCE_TYPE = (
("svn", "svn"),
("git", "git"),
("file", "file"),
)


class Delivery(models.Model):
job_name = models.ForeignKey(Project, null=False, verbose_name=u"项目名")
description = models.CharField(max_length=255, verbose_name=u"描述", null=True, blank=True)
source_type = models.CharField(max_length=255, choices=SOURCE_TYPE, verbose_name=u"源类型")
source_address = models.CharField(max_length=255, verbose_name=u"源地址")
destination_address = models.CharField(max_length=255, verbose_name=u"目标地址")
deploy_policy = models.CharField(max_length=255, choices=DEPLOY_POLICY, verbose_name=u"部署策略")
shell = models.CharField(max_length=255, verbose_name=u"shell", null=True, blank=True)

def __unicode__(self):
return self.job_name
12 changes: 12 additions & 0 deletions delivery/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from django.conf.urls import url, include
import delivery

urlpatterns = [
url(r'^$', delivery.delivery_list, name='delivery'),
url(r'^delivery/add/$', delivery.delivery_add, name='delivery_add'),
url(r'^delivery/list/$', delivery.delivery_list, name='delivery_list'),
url(r'^delivery/edit/(?P<project_id>\d+)/$', delivery.delivery_edit, name='delivery_edit'),
url(r'^delivery/delete/$', delivery.delivery_del, name='delivery_del'),
]
12 changes: 12 additions & 0 deletions delivery/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from django.http import HttpResponse
from django.views.generic.base import TemplateView
from django.shortcuts import render
from models import Delivery


def index(request):
temp_name = "delivery/delivery-header.html"
projects = Delivery.objects.all()
return render(request, "delivery/index.html", locals())
24 changes: 24 additions & 0 deletions templates/delivery/delivery-header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<header class="main-header">

<!-- Logo -->
<a href="{% url 'index' %}" class="logo">
<!-- mini logo for sidebar mini 50x50 pixels -->
<span class="logo-mini"><b>AST</b></span>
<!-- logo for regular state and mobile devices -->
<span class="logo-lg"><b>AdminSet</b></span>
</a>

<!-- Header Navbar -->
<nav class="navbar navbar-static-top" role="navigation">
<!-- Sidebar toggle button-->
<a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
<span class="sr-only">Toggle navigation</span>
</a>
<div class="collapse navbar-collapse pull-left" id="navbar-collapse">
<ul class="nav navbar-nav">
</ul>
</div>
<!-- Navbar Right Menu -->
{% include 'navbar-custom-menu.html' %}
</nav>
</header>
63 changes: 63 additions & 0 deletions templates/delivery/delivery_base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{% extends 'base.html' %}
{% block self_head_css_js %}
<script src="/static/layer/layer.js"></script>
<script src="/static/js/jquery.bootstrap-duallistbox.js"></script>
<link rel="stylesheet" type="text/css" href="/static/css/bootstrap-duallistbox.css">
{% endblock %}
{% block content %}

<script>
window.onload=init;
function init() {
var box = document.getElementById("delivery");
box.className="active";
var box = document.getElementById("delivery_list");
box.className="active";
}
</script>

<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
</section>

<!-- Main content -->

<section class="content">

<!-- Default box -->
<div class="box">
<div class="box-header with-border">
</div>
<div class="box-body">
{% if project_id %}
<form action="{% url 'delivery_edit' project_id %}" method="post">
{% else %}
<form action="{% url 'delivery_add' %}" method="post">
{% endif %}
{% csrf_token %}
{{ form.as_p }}
<input type="submit" class="btn btn-primary" style="width: 60pt" value="提交">&nbsp;&nbsp;&nbsp;&nbsp;
<a href="{% url 'delivery_list' %}"><li style="width: 60pt" class="btn btn-primary" value="">返回</li></a><br>
</form>
</div>
<!-- /.box-body -->
<div class="box-footer">
<i class="fa fa-info-circle"></i> 请勿重复添加条目
</div>
<!-- /.box-footer-->
</div>
<!-- /.box -->
</section>

</div>
{# <script>#}
{# var demo1 = $('select[name="serverList"]').bootstrapDualListbox({#}
{# nonSelectedListLabel: '可选择服务器',#}
{# selectedListLabel: '已选择服务器',#}
{# preserveSelectionOnMove: 'moved',#}
{# moveOnSelect: false,#}
{# });#}
{# </script>#}

{% endblock %}
Loading

0 comments on commit 86bccc4

Please sign in to comment.