Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- clear
- printf "# Simple Bash Script\n"
- printf "# Purpose : Create Virtualenv, Update pip, install django, start django project\n"
- printf "# Recomend : terminal / console background color dark (black)\n"
- printf "# kael\n"
- printf " \n"
- printf " \n"
- # cek virtualenv install or not
- PIP="which pip"
- if [ $(exec $PIP) ];
- then
- printf "[+] pip Installed"
- printf "\n"
- else
- printf "[+] Installing pip\n"
- sudo apt-get install python-pip
- printf "\n"
- fi
- VENV="virtualenv --version"
- if [ $(exec $VENV) ];
- then
- printf "[+] Virtualenv Installed Version : "
- printf $(exec $VENV)
- printf "\n"
- else
- printf "[+] Installing Virtualenv\n"
- pip install virtualenv
- printf "\n"
- printf "[+] Update Virtualenv\n"
- pip install --upgrade virtualenv
- printf "\n"
- fi
- NPMV="npm --version"
- if [ $(exec $NPMV) ];
- then
- printf "[+] npm Installed"
- printf "\n"
- else
- printf "[+] Installing NPM\n"
- NPM="sudo apt-get install npm"
- exec $NPM
- printf "\n"
- fi
- BV="bower --version"
- if [ ! $(exec $BV) ];
- then
- printf "[+] Installing Bower\n"
- BOWER="npm install -g bower"
- exec $BOWER
- printf "\n"
- else
- printf "[+] Bower Installed Version "
- printf $(exec $BV)
- printf "\n"
- fi
- WDIR=pwd
- printf "[-] working directory : "
- $WDIR
- printf "[-] Masukkan Nama Virtualenv : "
- read venv
- echo "[-] Creating Virtualev : " $venv
- virtualenv $venv
- printf "\n"
- printf "[-] Moving To Virtualenv Directory \n"
- cd $venv
- printf "[-] working directory"
- pwd
- printf "\n"
- printf "[-] Activating Virtualenv" $venv
- source bin/activate
- printf "\n"
- printf "[-] Upgrade PIP\n"
- pip install --upgrade pip
- printf "[-] Installing Django\n"
- pip install django
- printf "\n\n"
- printf "[+] Virtualelnv (Finished)\n"
- printf "[+] Upgrade Pip (Finished)\n"
- printf "[+] Django Install (Finished)\n"
- printf "[+] To enter the new virtualenv follow this steps :\n"
- printf "[-] cd "
- pwd
- printf "\n"
- printf "[-] sudo su \n"
- printf "[-] source bin/activate\n"
- printf "\n"
- mn="Masukkan Pilihan Anda : "
- pil=("[ 1 ] Create New Django Project"
- "[ 2 ] Create New Django App"
- "[ 3 ] Run Server ( 0.0.0.0:8000)"
- "Quit"
- )
- select pl in "${pil[@]}"
- do
- case $pl in
- "[ 1 ] Create New Django Project")
- printf "[-] Enter Django Project Name : "
- read newp
- python bin/django-admin.py startproject $newp
- printf "[+] Create Django Project : " $newp "\n"
- printf "[-] Moving To Project Directory\n"
- cd $newp
- printf "[ Success !! ]\n"
- printf "[+] Tambahkan 'DIRS': [BASE_DIR+'/templates',] pada \"settings.py > TEMPLATES\" \n"
- printf "[+] Put - STATICFILES_DIR (settings.py)\n"
- echo -e "#STATICFILES_DIRS = (" >> $newp/settings.py
- echo -e "# os.path.join(BASE_DIR,'static')," >> $newp/settings.py
- echo -e "#)" >> $newp/settings.py
- #printf "[+] Put - static directory\n"
- #mkdir static
- printf "[+] Put - templates directory\n"
- mkdir templates
- printf "[+] Installing Bootstrap from Bower \n"
- bower install bootstrap
- printf "[+] Creating Static Folder\n"
- mv bower_components/bootstrap/dist static
- rm -rf bower_components
- # cp -R ~/Desktop/static/css static/css
- # cp -R ~/Desktop/static/fonts static/fonts
- # cp -R ~/Desktop/static/js static/js
- printf "[+] Generating base.html templates\n"
- echo -e "{% load staticfiles %}" >> templates/base.html
- echo -e "<html>" >> templates/base.html
- echo -e "<head>" >> templates/base.html
- echo -e " <script type=\"text/javascript\" src=\"{% static 'js/bootstrap.min.js' %}\"></script>" >> templates/base.html
- echo -e " <link rel=\"stylesheet\" type=\"text/css\" href=\"{% static 'css/bootstrap.min.css' %}\" />" >> templates/base.html
- echo -e " <title>List Event</title>" >> templates/base.html
- echo -e "</head>" >> templates/base.html
- echo -e "<body>" >> templates/base.html
- echo -e "<div class=\"container\">" >> templates/base.html
- echo -e " <div class=\"row\">" >> templates/base.html
- echo -e " <div class=\"col-sm-12\">" >> templates/base.html
- echo -e " <nav class=\"navbar\">" >> templates/base.html
- echo -e " <ul class=\"nav navbar-nav\">" >> templates/base.html
- echo -e " <li class=\"active\"><a href=\"/class\">Home</a></li>" >> templates/base.html
- echo -e " <li><a href=\"/class/artikel\">Artikel</a></li>" >> templates/base.html
- echo -e " </ul>" >> templates/base.html
- echo -e " </nav>" >> templates/base.html
- echo -e "" >> templates/base.html
- echo -e " {% block content %}" >> templates/base.html
- echo -e " {% endblock %}" >> templates/base.html
- echo -e " </div>" >> templates/base.html
- echo -e " </div>" >> templates/base.html
- echo -e "</div>" >> templates/base.html
- echo -e "</body>" >> templates/base.html
- echo -e "</html>" >> templates/base.html
- printf "[+] Generating form.html templates\n"
- echo -e "{% extends 'base.html' %}" >> templates/form.html
- echo -e "{% load cb_extras %}" >> templates/form.html
- echo -e "<div class=\"col-sm-12\">" >> templates/form.html
- echo -e " {% block content %}" >> templates/form.html
- echo -e "<form action=\"/class/update/{{ id }}/\" method=\"POST\">" >> templates/form.html
- echo -e "{% csrf_token %}" >> templates/form.html
- echo -e " {% for frm in form %}" >> templates/form.html
- echo -e " <div class=\"form-group\">" >> templates/form.html
- echo -e " {{ frm.label }}" >> templates/form.html
- echo -e " {{ frm|addcss:"form-control" }}" >> templates/form.html
- echo -e " </div>" >> templates/form.html
- echo -e " {% endfor %}" >> templates/form.html
- echo -e " <div class=\"pull-right\">" >> templates/form.html
- echo -e " <input type=\"submit\" class=\"btn btn-primary\" value=\"Simpan\"> " >> templates/form.html
- echo -e " <a href=\"/class\" class=\"btn btn-default\">Batal</a> " >> templates/form.html
- echo -e " </div>" >> templates/form.html
- echo -e "</form>" >> templates/form.html
- echo -e "</div>" >> templates/form.html
- echo -e "{% endblock %}" >> templates/form.html
- printf "\n\n"
- printf "Press Enter To Show Options !! \n \n"
- ;;
- "[ 2 ] Create New Django App")
- clear
- printf "#==\n"
- printf "# Create Django App\n"
- printf "#==\n"
- printf "\n"
- printf "Enter Django App Name : "
- read AppName
- python manage.py startapp $AppName
- printf "[ Create Success !! ]\n"
- printf "[+] Generating Models.py \n"
- echo -e "# Sample Class Models\n" >> $AppName/models.py
- echo -e "#class <<NamaModel>>(models.Models):" >> $AppName/models.py
- echo -e "# field..1 = models.CharField(max_length=80)" >> $AppName/models.py
- echo -e "# field..2 = models.TextField()" >> $AppName/models.py
- echo -e "# class meta:" >> $AppName/models.py
- echo -e "# # app_label:'labelName'" >> $AppName/models.py
- printf "[+] Generating Forms.py\n"
- echo -e "from django import forms" >> $AppName/forms.py
- echo -e "from .models import <<NamaModel>>" >> $AppName/forms.py
- echo -e "class ArtikelForm(forms.ModelForm):" >> $AppName/forms.py
- echo -e " class Meta:" >> $AppName/forms.py
- echo -e " model = <<NamaModels>>" >> $AppName/forms.py
- echo -e " fields = ['<<field..1>>', '<<field..n>>']" >> $AppName/forms.py
- printf "[+] Generating Views.py \n"
- echo -e "#Sample View Include pagination list content, detail content" >> $AppName/views.py
- echo -e "#from django.http import HttpResponse" >> $AppName/views.py
- echo -e "from django.shortcuts import render_to_response, redirect, render" >> $AppName/views.py
- echo -e "from django.views.generic import View, CreateView, TemplateView, UpdateView, DetailView" >> $AppName/views.py
- echo -e "#from django.template import RequestContext" >> $AppName/views.py
- echo -e "#from cbase.forms import *" >> $AppName/views.py
- echo -e "#from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger" >> $AppName/views.py
- echo -e "#from django.core.context_processors import csrf" >> $AppName/views.py
- echo -e "#from django.core.exceptions import ObjectDoesNotExist" >> $AppName/views.py
- echo -e "#from django.core.urlresolvers import reverse_lazy" >> $AppName/views.py
- echo -e "#" >> $AppName/views.py
- echo -e "#class MyView(View):" >> $AppName/views.py
- echo -e "# def get(self, request):" >> $AppName/views.py
- echo -e "# list_artikel = Artikel.objects.all()" >> $AppName/views.py
- echo -e "# paginator = Paginator(list_artikel,3)" >> $AppName/views.py
- echo -e "# page = request.GET.get('page')" >> $AppName/views.py
- echo -e "# try:" >> $AppName/views.py
- echo -e "# lst_artikel = paginator.page(page)" >> $AppName/views.py
- echo -e "# except PageNotAnInteger:" >> $AppName/views.py
- echo -e "# lst_artikel = paginator.page(1)" >> $AppName/views.py
- echo -e "# except EmptyPage:" >> $AppName/views.py
- echo -e "# lst_artikel = paginator.page(paginator.num_pages)" >> $AppName/views.py
- echo -e "# return render_to_response('home.html',{'list_artikel': lst_artikel})" >> $AppName/views.py
- echo -e "#" >> $AppName/views.py
- echo -e "#class AboutMe(View):" >> $AppName/views.py
- echo -e "# nama = \"Eldo Greshard\"" >> $AppName/views.py
- echo -e "#" >> $AppName/views.py
- echo -e "# def get(self, request):" >> $AppName/views.py
- echo -e "# return render_to_response('about.html',{'nama': self.nama,})" >> $AppName/views.py
- echo -e "#" >> $AppName/views.py
- echo -e "#class UbahAbout(AboutMe):" >> $AppName/views.py
- echo -e "# nama = \"Diubah\"" >> $AppName/views.py
- echo -e "#" >> $AppName/views.py
- echo -e "#class Artikel_view(View):" >> $AppName/views.py
- echo -e "# form_c = ArtikelForm" >> $AppName/views.py
- echo -e "# model_c = Artikel" >> $AppName/views.py
- echo -e "# def get(self, request):" >> $AppName/views.py
- echo -e "# context = RequestContext(request,{})" >> $AppName/views.py
- echo -e "# context['form'] = self.form_c" >> $AppName/views.py
- echo -e "# return render_to_response('artikel.html', context)" >> $AppName/views.py
- echo -e "#" >> $AppName/views.py
- echo -e "#class UbahArtikel(View):" >> $AppName/views.py
- echo -e "# form_c = ArtikelForm" >> $AppName/views.py
- echo -e "# model_c = Artikel" >> $AppName/views.py
- echo -e "# def get(self,request, id):" >> $AppName/views.py
- echo -e "# data = self.model_c.objects.get(id = int(id))" >> $AppName/views.py
- echo -e "# context = RequestContext(request, {})" >> $AppName/views.py
- echo -e "# context['form'] = self.form_c(" >> $AppName/views.py
- echo -e "# initial={" >> $AppName/views.py
- echo -e "# 'judul': data.judul," >> $AppName/views.py
- echo -e "# 'author': data.author," >> $AppName/views.py
- echo -e "# 'artikel': data.artikel," >> $AppName/views.py
- echo -e "# }" >> $AppName/views.py
- echo -e "# ) " >> $AppName/views.py
- echo -e "# context['id'] = int(id)" >> $AppName/views.py
- echo -e "# return render_to_response(\"ubah.html\",context)" >> $AppName/views.py
- echo -e "#" >> $AppName/views.py
- echo -e "#class CgCreate(CreateView):" >> $AppName/views.py
- echo -e "# model = Artikel" >> $AppName/views.py
- echo -e "# fields = ['judul','author','artikel']" >> $AppName/views.py
- echo -e "# success_url=\"/class/artikel\"" >> $AppName/views.py
- echo -e "# template_name=\"artikel.html\"" >> $AppName/views.py
- echo -e "# def form_invalid(self, form):" >> $AppName/views.py
- echo -e "# return super(CgCreate, self).form_invalid(form)" >> $AppName/views.py
- echo -e "#" >> $AppName/views.py
- echo -e "#class CgUpdate(UpdateView):" >> $AppName/views.py
- echo -e "# model = Artikel" >> $AppName/views.py
- echo -e "# slug_field = 'id'" >> $AppName/views.py
- echo -e "# fields = ['judul','author','artikel']" >> $AppName/views.py
- echo -e "# success_url=\"/class/artikel\"" >> $AppName/views.py
- echo -e "#" >> $AppName/views.py
- echo -e "#class CgDetail(DetailView):" >> $AppName/views.py
- echo -e "# model = Artikel" >> $AppName/views.py
- echo -e "# template_name = 'detail.html'" >> $AppName/views.py
- echo -e "#" >> $AppName/views.py
- echo -e "# def get_context_data(self, **kwargs):" >> $AppName/views.py
- echo -e "# context = super(CgDetail, self).get_context_data(**kwargs)" >> $AppName/views.py
- echo -e "# return context" >> $AppName/views.py
- printf "[+] Generating Custom Template Tags.py \n"
- mkdir $AppName/templatetags
- touch $AppName/templatetags/__init__.py
- touch $AppName/templatetags/ct_$AppName.py
- echo -e "#Sample Template Tags" >> $AppName/templatetags/ct_$AppName.py
- echo -e "#from django import template" >> $AppName/templatetags/ct_$AppName.py
- echo -e "#" >> $AppName/templatetags/ct_$AppName.py
- echo -e "#register = template.Library()" >> $AppName/templatetags/ct_$AppName.py
- echo -e "#" >> $AppName/templatetags/ct_$AppName.py
- echo -e "#@register.filter(name='addcss')" >> $AppName/templatetags/ct_$AppName.py
- echo -e "#def addcss(field, css):" >> $AppName/templatetags/ct_$AppName.py
- echo -e "# return field.as_widget(attrs={"class":css})" >> $AppName/templatetags/ct_$AppName.py
- printf "[+] Generating urls.py \n"
- echo -e "#Sample urls.py" >> $AppName/urls.py
- echo -e "#from django.conf.urls import url" >> $AppName/urls.py
- echo -e "#from cbase.views import *" >> $AppName/urls.py
- echo -e "#" >> $AppName/urls.py
- echo -e "#urlpatterns = [" >> $AppName/urls.py
- echo -e "# url(r'^$', MyView.as_view() , name=\"index\")," >> $AppName/urls.py
- echo -e "# url(r'^about', UbahAbout.as_view(), name=\"about\")," >> $AppName/urls.py
- echo -e "# url(r'^artikel', Artikel_view.as_view(), name=\"artikel\")," >> $AppName/urls.py
- echo -e "# url(r'^simpan', CgCreate.as_view(), name=\"Create\")," >> $AppName/urls.py
- echo -e "# url(r'^ubah/(\d+)', UbahArtikel.as_view(),name=\"update\")," >> $AppName/urls.py
- echo -e "# url(r'^update/(?P<pk>\d+)/$', CgUpdate.as_view(), name=\"ubah\")," >> $AppName/urls.py
- echo -e "# url(r'^detail/(?P<pk>\d+)/$', CgDetail.as_view(), name='detail')," >> $AppName/urls.py
- echo -e "#]" >> $AppName/urls.py
- printf "\n\n"
- printf "Press Enter To Show Options !! \n \n"
- ;;
- "[ 3 ] Run Server ( 0.0.0.0:8000)")
- printf "Starting Django Server http://localhost:8000\n"
- fuser -k 8000/tcp
- gnome-terminal -x sh -c "python manage.py runserver | less" &
- ;;
- "Quit")
- clear
- break
- ;;
- *)
- echo Pilihan Tidak Ditemukan
- ;;
- esac
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement