Commit 111f0c51 by nesta

Full Project TA2 Kelompok 20 D3TI2018

parents
from django.contrib import admin
from .models import Matkul
from .models import Kelas
from .models import Sesi
from .models import Akun
from .models import Hari
from .models import Pengajar
from .models import Pengajar_Matkul_Kelas
from .models import Kategori
admin.site.register(Kategori)
admin.site.register(Matkul)
admin.site.register(Kelas)
admin.site.register(Pengajar)
admin.site.register(Sesi)
admin.site.register(Akun)
admin.site.register(Pengajar_Matkul_Kelas)
admin.site.register(Hari)
\ No newline at end of file
from django.apps import AppConfig
class PenjadwalanConfig(AppConfig):
name = 'App'
from django import forms
from .models import Kelas
from .models import Sesi
from .models import Matkul
from .models import Pengajar
from .models import Akun
class KelasForm(forms.ModelForm):
class Meta:
model=Kelas
fields = [
'nama',
'kapasitas',
]
labels = {
'nama' : 'Nama Kelas',
'kapasitas' : 'Jumlah mahasiswa'
}
widgets = {
'nama' : forms.TextInput(
attrs={
'class': 'form-control',
'placeholder':'Masukkan nama kelas.....'
}
),
'kapasitas' : forms.NumberInput(
attrs={
'class':'form-control',
'placeholder':'Masukkan jumlah mahasiwa....'
}
)
}
class SesiForm(forms.ModelForm):
class Meta:
model=Sesi
fields = [
'nama',
]
labels = {
'nama' : 'Nama Sesi'
}
widgets = {
'nama' : forms.TextInput(
attrs={
'class': 'form-control',
'placeholder':'Masukkan Sesi.....'
}
)
}
class PengajarForm(forms.ModelForm):
class Meta:
model=Pengajar
fields = [
'nama',
'kategori'
]
labels = {
'nama' : 'Nama Dosen',
'kategori' : 'Kategori'
}
widgets = {
'nama' : forms.TextInput(
attrs={
'class': 'form-control',
'placeholder':'Masukkan nama Dosen.....'
}
),
'kategori' : forms.NumberInput(
attrs={
'class':'form-control',
'placeholder':'Masukkan kategori'
}
)
}
class AkunForm(forms.ModelForm):
class Meta:
model=Akun
fields = [
'nama',
'kapasitas',
]
labels = {
'nama' : 'Nama Akun',
'kapasitas' : 'Jumlah kapasitas Partisipan'
}
widgets = {
'nama' : forms.TextInput(
attrs={
'class': 'form-control',
'placeholder':'Masukkan nama akun.....'
}
),
'kapasitas' : forms.NumberInput(
attrs={
'class':'form-control',
'placeholder':'Masukkan kapasitas partisipan akun....'
}
)
}
class MatkulForm(forms.ModelForm):
class Meta:
model=Matkul
fields = [
'kode',
'nama',
'sks',
'kategori',
]
labels = {
'kode':'Masukkan Kode Matakuliah',
'nama' : 'Nama Mata Kuliah',
'sks' : 'Jumlah SKS',
'kategori' : 'kategori'
}
widgets = {
'kode' : forms.TextInput(
attrs={
'class': 'form-control',
'placeholder':'Masukkan Kode Mata Kuliah'
}
),
'nama' : forms.TextInput(
attrs={
'class': 'form-control',
'placeholder':'Masukkan nama mata kuliah.....'
}
),
'sks' : forms.NumberInput(
attrs={
'class':'form-control',
'placeholder':'Masukkan jumlah sks...'
}
),
'kategori' : forms.NumberInput(
attrs={
'class':'form-control',
'placeholder':'Masukkan kategori'
}
)
}
\ No newline at end of file
# Generated by Django 3.2.5 on 2021-08-09 08:49
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Akun',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('nama', models.CharField(max_length=255)),
('kapasitas', models.IntegerField()),
],
),
migrations.CreateModel(
name='Hari',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('nama', models.CharField(max_length=10)),
],
),
migrations.CreateModel(
name='Kategori',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('nama', models.CharField(max_length=255)),
],
),
migrations.CreateModel(
name='Kelas',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('nama', models.CharField(max_length=8)),
('kapasitas', models.IntegerField(default=0)),
],
),
migrations.CreateModel(
name='Matkul',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('kode', models.CharField(max_length=255)),
('nama', models.CharField(max_length=255)),
('sks', models.IntegerField()),
('kategori', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='App.kategori')),
],
),
migrations.CreateModel(
name='Pengajar',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('nama', models.CharField(max_length=255)),
('kategori', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='App.kategori')),
],
),
migrations.CreateModel(
name='Sesi',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('nama', models.CharField(max_length=255)),
],
),
migrations.CreateModel(
name='Pengajar_Matkul_Kelas',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('no_kelas', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='App.kelas')),
('no_matkul', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='App.matkul')),
('no_pengajar', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='App.pengajar')),
],
),
migrations.CreateModel(
name='Jadwal',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('no_Akun', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='App.akun')),
('no_Hari', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='App.hari')),
('no_Kelas', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='App.kelas')),
('no_Matkul', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='App.matkul')),
('no_Pengajar', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='App.pengajar')),
('no_Sesi', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='App.sesi')),
],
),
]
from django.db import models
class Kelas(models.Model):
nama = models.CharField(max_length=8)
kapasitas=models.IntegerField(default=0)
def __str__(self):
return "{}....{}".format(self.nama,self.kapasitas)
class Sesi(models.Model):
nama=models.CharField(max_length=255)
def __str__(self):
return "{}".format(self.nama)
class Kategori(models.Model):
nama=models.CharField(max_length=255)
def __str__(self):
return "{}".format(self.nama)
class Pengajar(models.Model):
nama=models.CharField(max_length=255)
kategori=models.ForeignKey(Kategori,on_delete=models.CASCADE)
def __str__(self):
return "{}".format(self.nama)
class Matkul(models.Model):
kode=models.CharField(max_length=255)
nama=models.CharField(max_length=255)
sks=models.IntegerField()
kategori=models.ForeignKey(Kategori,on_delete=models.CASCADE)
def __str__(self):
return "{}....{}....kategori=>{}".format(self.kode,self.nama,self.kategori)
class Akun(models.Model):
nama=models.CharField(max_length=255)
kapasitas=models.IntegerField()
def __str__(self):
return "{}".format(self.nama)
class Pengajar_Matkul_Kelas(models.Model):
no_pengajar=models.ForeignKey(Pengajar,on_delete=models.CASCADE)
no_matkul=models.ForeignKey(Matkul,on_delete=models.CASCADE)
no_kelas=models.ForeignKey(Kelas,on_delete=models.CASCADE)
def __str__(self):
return "{}....{}".format(self.no_pengajar,self.no_matkul)
class Hari(models.Model):
nama=models.CharField(max_length=10)
def __str__(self):
return "{}".format(self.nama)
class Jadwal(models.Model):
no_Pengajar=models.ForeignKey(Pengajar,on_delete=models.CASCADE)
no_Hari=models.ForeignKey(Hari,on_delete=models.CASCADE)
no_Sesi=models.ForeignKey(Sesi,on_delete=models.CASCADE)
no_Matkul=models.ForeignKey(Matkul,on_delete=models.CASCADE)
no_Kelas=models.ForeignKey(Kelas,on_delete=models.CASCADE)
no_Akun=models.ForeignKey(Akun,on_delete=models.CASCADE, null=True)
class JadwalKuliah(models.Model):
matkul=models.CharField(max_length=255)
pengajar=models.CharField(max_length=255)
kelas=models.CharField(max_length=255)
hari=models.CharField(max_length=255)
sesi=models.CharField(max_length=255)
akun=models.CharField(max_length=255)
class Meta:
db_table="jadwalperkuliahan"
{% extends "base.html" %}
{% block title %}
{{page_title}}
{% endblock title %}
{% block contents %}
<div class="container shadow-lg p-3 mb-5 bg-white rounded" style="margin-top:50px">
<h3 style="text-align:center ;">Data Akun</h3>
<form method="POST">
{% csrf_token %}
<div class="form-group">
{{akun_form.nama.label}}
{{akun_form.nama}}
</div>
<div class="form-group">
{{akun_form.kapasitas.label}}
{{akun_form.kapasitas}}
</div>
<div class="d-grid gap-2 d-md-block">
<button type="submit" class="btn btn-primary btn-block">Kirim</button>
</div>
</form>
</div>
{% endblock contents %}
\ No newline at end of file
{% extends "base.html" %}
{% block title %}
{{page_title}}
{% endblock title %}
{% block contents %}
<div class="container shadow-lg p-3 mb-5 bg-white rounded" style="margin-top:50px">
<h3 style="text-align:center ;">Data Akun</h3>
<a href="{% url 'App:createakun' %}" class="btn btn-primary" role="button" aria-disabled="true">Create</a>
<table class="table" style="margin-top:10px">
<thead style="text-align:center ;">
<tr>
<th style="width: 30%;">Nama Akun</th>
<th style="width: 30%;">Jumlah Kapasitas</th>
<th style="width: 30%;">Action</th>
</tr>
</thead>
<tbody style="text-align:center ;">
{% for akun in semua_akun %}
<tr>
<td style="width: 30%;">{{akun.nama}}</td>
<td style="width: 30%;">{{akun.kapasitas}}</td>
<td style="width: 15%;">
<a href="{% url 'App:deleteakun' akun.id %}" class="btn btn-danger" role="button" aria-disabled="true">Delete</a>
<a href="{% url 'App:updateakun' akun.id %}" class="btn btn-success" role="button" aria-disabled="true">Update</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock contents %}
\ No newline at end of file
{% extends "base.html" %}
{% block title %}
{{page_title}}
{% endblock title %}
{% block contents %}
<div class="container shadow-lg p-3 mb-5 bg-white rounded" style="margin-top:50px">
<h3 style="text-align:center ;">Data Penjadwalan Prodi D3TK </h3>
<table class="table" style="margin-top:10px">
<thead style="text-align:center ;">
<tr>
<th style="width: 30%;">Mata kuliah</th>
<th style="width: 30%;">Pengajar</th>
<th style="width: 30%;">Kelas</th>
<th style="width: 30%;">Sesi</th>
<th style="width: 30%;">Hari</th>
<th style="width: 30%;">Akun</th>
</tr>
</thead>
<tbody style="text-align:center ;">
{% for jdw in semua_jadwal %}
<tr>
<td style="width: 30%;">{{jdw.pengajar}}</td>
<td style="width: 30%;">{{jdw.matkul}}</td>
<td style="width: 30%;">{{jdw.kelas}}</td>
<td style="width: 30%;">{{jdw.sesi}}</td>
<td style="width: 30%;">{{jdw.hari}}</td>
<td style="width: 30%;">{{jdw.akun}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock contents %}
{% extends "base.html" %}
{% block title %}
{{page_title}}
{% endblock title %}
{% block contents %}
<div class="container shadow-lg p-3 mb-5 bg-white rounded" style="margin-top:50px">
<h3 style="text-align:center ;">Data Kelas</h3>
<form method="POST">
{% csrf_token %}
<div class="form-group">
{{kelas_form.nama.label}}
{{kelas_form.nama}}
</div>
<div class="form-group">
{{kelas_form.kapasitas.label}}
{{kelas_form.kapasitas}}
</div>
<div class="d-grid gap-2 d-md-block">
<button type="submit" class="btn btn-primary btn-block">Kirim</button>
</div>
</form>
</div>
{% endblock contents %}
{% extends "base.html" %}
{% block title %}
{{page_title}}
{% endblock title %}
{% block contents %}
<div class="container shadow-lg p-3 mb-5 bg-white rounded" style="margin-top:50px">
<h3 style="text-align:center ;">Data Kelas</h3>
<a href="{% url 'App:createkelas' %}" class="btn btn-primary" role="button" aria-disabled="true">Create</a>
<table class="table" style="margin-top:10px">
<thead style="text-align:center ;">
<tr>
<th style="width: 30%;">Kelas</th>
<th style="width: 30%;">Jumlah</th>
<th style="width: 30%;">Action</th>
</tr>
</thead>
<tbody style="text-align:center ;">
{% for kelas in semua_kelas %}
<tr>
<td style="width: 30%;">{{kelas.nama}}</td>
<td style="width: 30%;">{{kelas.kapasitas}}</td>
<td style="width: 15%;">
<a href="{% url 'App:deletekelas' kelas.id %}" class="btn btn-danger" role="button" aria-disabled="true">Delete</a>
<a href="{% url 'App:updatekelas' kelas.id %}" class="btn btn-success" role="button" aria-disabled="true">Update</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock contents %}
{% extends "base.html" %}
{% block title %}
{{page_title}}
{% endblock title %}
{% block contents %}
<div class="container shadow-lg p-3 mb-5 bg-white rounded" style="margin-top:50px">
<h3 style="text-align:center ;">Data Mata Kuliah</h3>
<form method="POST">
{% csrf_token %}
<div class="form-group">
{{matakuliah_form.kode.label}}
{{matakuliah_form.kode}}
</div>
<div class="form-group">
{{matakuliah_form.nama.label}}
{{matakuliah_form.nama}}
</div>
<div class="form-group">
{{matakuliah_form.sks.label}}
{{matakuliah_form.sks}}
</div>
<div class="form-grup">
{{matakuliah_form.kategori.label}}
{{matakuliah_form.kategori}}
</div>
<div class="d-grid gap-2 d-md-block">
<button type="submit" class="btn btn-primary btn-block">Kirim</button>
</div>
</form>
</div>
{% endblock contents %}
{% extends "base.html" %}
{% block title %}
{{page_title}}
{% endblock title %}
{% block contents %}
<div class="container shadow-lg p-3 mb-5 bg-white rounded" style="margin-top:50px">
<h3 style="text-align:center ;">Data Mata Kuliah</h3>
<a href="{% url 'App:creatematakuliah' %}" class="btn btn-primary" role="button" aria-disabled="true">Create</a>
<table class="table" style="margin-top:10px">
<thead style="text-align:center ;">
<tr>
<th style="width: 10%;">Kode Matakuliah</th>
<th style="width: 10%;">Nama Matakuliah</th>
<th style="width: 10%;">SKS</th>
<th style="width: 10%;">Kategori</th>
<th style="width: 10%;">Action</th>
</tr>
</thead>
<tbody style="text-align:center ;">
{% for matkul in semua_matkul %}
<tr>
<td style="width: 10%;">{{matkul.kode}}</td>
<td style="width: 10%;">{{matkul.nama}}</td>
<td style="width: 10%;">{{matkul.sks}}</td>
<td style="width: 10%;">{{matkul.kategori}}</td>
<td style="width: 10%;">
<a href="{% url 'App:deletematakuliah' matkul.id %}"class="btn btn-danger" role="button" aria-disabled="true">Delete</a>
<a href="{% url 'App:updatematakuliah' matkul.id %}"class="btn btn-success" role="button" aria-disabled="true">Update</a>
</td>
</tr>
{% endfor %}
</ol>
</tbody>
</table>
</div>
{% endblock contents %}
{% extends "base.html" %}
{% block title %}
{{page_title}}
{% endblock title %}
{% block contents %}
<div class="container shadow-lg p-3 mb-5 bg-white rounded" style="margin-top:50px">
<h3 style="text-align:center ;">Data Pengajar</h3>
<form method="POST">
{% csrf_token %}
<div class="form-group">
{{pengajar_form.nama.label}}
{{pengajar_form.nama}}
</div>
<div class="form-group">
{{pengajar_form.kategori.label}}
{{pengajar_form.kategori}}
</div>
<div class="d-grid gap-2 d-md-block">
<button type="submit" class="btn btn-primary btn-block">Kirim</button>
</div>
</form>
</div>
{% endblock contents %}
{% extends "base.html" %}
{% block title %}
{{page_title}}
{% endblock title %}
{% block contents %}
<div class="container shadow-lg p-3 mb-5 bg-white rounded" style="margin-top:50px">
<h3 style="text-align:center ;">Data Pengajar</h3>
<a href="{% url 'App:createpengajar' %}" class="btn btn-primary" role="button" aria-disabled="true">Create</a>
<table class="table" style="margin-top:10px">
<thead style="text-align:center ;">
<tr>
<th style="width: 30%;">Nama</th>
<th style="width: 30%;">Kategori</th>
<th style="width: 30%;">Action</th>
</tr>
</thead>
<tbody style="text-align:center ;">
{% for pengajar in semua_pengajar %}
<tr>
<td style="width: 30%;">{{pengajar.nama}}</td>
<td style="width: 30%;">{{pengajar.kategori}}</td>
<td style="width: 15%;">
<a href="{% url 'App:deletepengajar' pengajar.id %}" class="btn btn-danger" role="button" aria-disabled="true">Delete</a>
<a href="{% url 'App:updatepengajar' pengajar.id %}"class="btn btn-success" role="button" aria-disabled="true">Update</a>
</td>
</tr>
{% endfor %}
</ol>
</tbody>
</table>
</div>
{% endblock contents %}
{% extends "base.html" %}
{% block title %}
{{page_title}}
{% endblock title %}
{% block contents %}
<div class="container shadow-lg p-3 mb-5 bg-white rounded" style="margin-top:50px">
<h3 style="text-align:center ;">Data Sesi</h3>
<form method="POST">
{% csrf_token %}
<div class="form-group">
{{sesi_form.nama.label}}
{{sesi_form.nama}}
</div>
<div class="d-grid gap-2 d-md-block">
<button type="submit" class="btn btn-primary btn-block">Kirim</button>
</div>
</form>
</div>
{% endblock contents %}
{% extends "base.html" %}
{% block title %}
{{page_title}}
{% endblock title %}
{% block contents %}
<div class="container shadow-lg p-3 mb-5 bg-white rounded" style="margin-top:50px">
<h3 style="text-align:center ;">Data Sesi</h3>
<a href="{% url 'App:create' %}" class="btn btn-primary" role="button" aria-disabled="true">Create</a>
<table class="table" style="margin-top:10px">
<thead style="text-align:center ;">
<tr>
<th style="width: 30%;">Sesi</th>
<th style="width: 30%;">Action</th>
</tr>
</thead>
<tbody style="text-align:center ;">
{% for sesi in semua_sesi %}
<tr>
<td style="width: 30%;">{{sesi.nama}}</td>
<td style="width: 15%;">
<a href="{% url 'App:delete' sesi.id %}" class="btn btn-danger" role="button" aria-disabled="true">Delete</a>
<a href="{% url 'App:update' sesi.id %}" class="btn btn-success" role="button" aria-disabled="true">Update</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock contents %}
from django.test import TestCase
# Create your tests here.
from django.conf.urls import url
from django.urls import path
from . import views
urlpatterns = [
url(r'^Jadwal/$',views.listjadwal,name='listjadwal'),
url(r'^Sesi/$',views.list,name='list'),
url(r'^Sesi/create/$',views.create,name='create'),
path('Sesi/delete/<int:delete_id>',views.delete,name='delete'),
path('Sesi/update/<int:update_id>',views.update,name='update'),
url(r'^Pengajar/$',views.listpengajar,name='listpengajar'),
url(r'^Pengajar/create/$',views.createpengajar,name='createpengajar'),
path('Pengajar/delete/<int:delete_id>',views.deletepengajar,name='deletepengajar'),
path('Pengajar/update/<int:update_id>',views.deletepengajar,name='updatepengajar'),
url(r'^Kelas/$',views.listkelas,name='listkelas'),
url(r'^Kelas/create/$',views.createkelas,name='createkelas'),
path('Kelas/delete/<int:delete_id>',views.deletekelas,name='deletekelas'),
path('Kelas/update/<int:update_id>',views.updatekelas,name='updatekelas'),
url(r'^Matkul/$',views.listmatakuliah,name='listmatakuliah'),
url(r'^Matkul/create/$',views.creatematakuliah,name='creatematakuliah'),
path('Matkul/delete/<int:delete_id>',views.deletematakuliah,name='deletematakuliah'),
path('Matkul/update/<int:update_id>',views.updatematakuliah,name='updatematakuliah'),
url(r'^Akun/$',views.listakun,name='listakun'),
url(r'^Akun/create/$',views.createakun,name='createakun'),
path('Akun/delete/<int:delete_id>',views.deleteakun,name='deleteakun'),
path('Akun/update/<int:update_id>',views.updateakun,name='updateakun'),
]
from django.db import connection
from django.shortcuts import render,redirect
from django.db import connection
from django.db.models import Q
from mysql.connector import cursor
from .models import Kelas, Pengajar
from .forms import KelasForm
from .models import Sesi
from .forms import SesiForm
from .models import Pengajar
from .forms import PengajarForm
from .models import Matkul
from .forms import MatkulForm
from .models import Akun
from .forms import AkunForm
from .models import JadwalKuliah
def listjadwal(request):
# |Q(kelas='44trpl')
results=JadwalKuliah.objects.all().filter(Q(kelas='31tk')|Q(kelas='32tk')|Q(kelas='33tk')).order_by('-hari','sesi')
context={
'page_title':'List Seluruh Jadwal TRPL',
'semua_jadwal':results,
}
return render(request,'jadwal/list.html',context)
def list(request):
semua_sesi= Sesi.objects.all()
context={
'page_title':'List Seluruh Sesi',
'semua_sesi':semua_sesi,
}
return render(request,'sesi/list.html',context)
def delete(request,delete_id):
Sesi.objects.filter(id=delete_id).delete()
return redirect('App:list')
def update(request,update_id):
sesi_update=Sesi.objects.get(id=update_id)
data={
'nama':sesi_update.nama,
}
sesi_form=SesiForm(request.POST or None,initial=data,instance=sesi_update)
if request.method=='POST':
if sesi_form.is_valid:
sesi_form.save()
return redirect('App:list')
context= {
"page_title":"Update Sesi",
"sesi_form":sesi_form,
}
return render(request,'sesi/create.html',context)
def create(request):
sesi_form= SesiForm(request.POST or None)
if request.method=='POST':
if sesi_form.is_valid:
sesi_form.save()
return redirect('App:list')
context= {
"page_title":"Tambah Sesi",
"sesi_form":sesi_form,
}
return render(request,'sesi/create.html',context)
def listpengajar(request):
semua_pengajar= Pengajar.objects.all().order_by('kategori_id')
context={
'page_title':'List Seluruh Pengajaran',
'semua_pengajar':semua_pengajar,
}
return render(request,'pengajar/list.html',context)
def deletepengajar(request,delete_id):
Pengajar.objects.filter(id=delete_id).delete()
return redirect('App:listpengajar')
def updatepengajar(request,update_id):
pengajar_update=Pengajar.objects.get(id=update_id)
data={
'nama':pengajar_update.nama,
'kategori':pengajar_update.kategori
}
pengajar_form=PengajarForm(request.POST or None,initial=data,instance=pengajar_update)
if request.method=='POST':
if pengajar_form.is_valid:
pengajar_form.save()
return redirect('App:listpengajar')
context= {
"page_title":"Update Pengajar",
"pengajar_form":pengajar_form,
}
return render(request,'pengajar/create.html',context)
def createpengajar(request):
pengajar_form= PengajarForm(request.POST or None)
if request.method=='POST':
if pengajar_form.is_valid:
pengajar_form.save()
return redirect('App:listpengajar')
context= {
"page_title":"Tambah Pengajar",
"pengajar_form":pengajar_form,
}
return render(request,'pengajar/create.html',context)
def listkelas(request):
semua_kelas= Kelas.objects.all()
context={
'page_title':'List Seluruh Kelas',
'semua_kelas':semua_kelas,
}
return render(request,'kelas/list.html',context)
def deletekelas(request,delete_id):
Kelas.objects.filter(id=delete_id).delete()
return redirect('App:listkelas')
def updatekelas(request,update_id):
kelas_update=Kelas.objects.get(id=update_id)
data={
'nama':kelas_update.nama,
'kapasitas':kelas_update.kapasitas,
}
kelas_form=KelasForm(request.POST or None,initial=data,instance=kelas_update)
if request.method=='POST':
if kelas_form.is_valid:
kelas_form.save()
return redirect('App:listkelas')
context= {
"page_title":"Update Kelas",
"kelas_form":kelas_form,
}
return render(request,'kelas/create.html',context)
def createkelas(request):
kelas_form= KelasForm(request.POST or None)
if request.method=='POST':
if kelas_form.is_valid:
kelas_form.save()
return redirect('App:listkelas')
context= {
"page_title":"Tambah Kelas",
"kelas_form":kelas_form,
}
return render(request,'kelas/create.html',context)
def listmatakuliah(request):
semua_matakuliah= Matkul.objects.all().order_by('kategori_id')
context={
'page_title':'List Seluruh Mata Kuliah',
'semua_matkul':semua_matakuliah,
}
return render(request,'matakuliah/list.html',context)
def deletematakuliah(request,delete_id):
Matkul.objects.filter(id=delete_id).delete()
return redirect('App:listmatakuliah')
def updatematakuliah(request,update_id):
matakuliah_update=Matkul.objects.get(id=update_id)
data={
'nama':matakuliah_update.nama,
'sks':matakuliah_update.sks,
'kategori':matakuliah_update.kategori,
}
matakuliah_form=MatkulForm(request.POST or None,initial=data,instance=matakuliah_update)
if request.method=='POST':
if matakuliah_form.is_valid:
matakuliah_form.save()
return redirect('App:listmatakuliah')
context= {
"page_title":"Update Mata Kuliah",
"matakuliah_form":matakuliah_form,
}
return render(request,'matakuliah/create.html',context)
def creatematakuliah(request):
matakuliah_form= MatkulForm(request.POST or None)
if request.method=='POST':
if matakuliah_form.is_valid:
matakuliah_form.save()
return redirect('App:listmatakuliah')
context= {
"page_title":"Tambah Mata Kuliah",
"matakuliah_form":matakuliah_form,
}
return render(request,'matakuliah/create.html',context)
def listakun(request):
semua_akun= Akun.objects.all()
context={
'page_title':'List Seluruh Akun',
'semua_akun':semua_akun,
}
return render(request,'akun/list.html',context)
def deleteakun(request,delete_id):
Akun.objects.filter(id=delete_id).delete()
return redirect('App:listakun')
def updateakun(request,update_id):
akun_update=Akun.objects.get(id=update_id)
data={
'nama':akun_update.nama,
'kapasitas':akun_update.kapasitas,
}
akun_form=AkunForm(request.POST or None,initial=data,instance=akun_update)
if request.method=='POST':
if akun_form.is_valid:
akun_form.save()
return redirect('App:listakun')
context= {
"page_title":"Update Akun",
"akun_form":akun_form,
}
return render(request,'akun/create.html',context)
def createakun(request):
akun_form= AkunForm(request.POST or None)
if request.method=='POST':
if akun_form.is_valid:
akun_form.save()
return redirect('App:listakun')
context= {
"page_title":"Tambah Akun",
"akun_form":akun_form,
}
return render(request,'akun/create.html',context)
\ No newline at end of file
"""
ASGI config for CRUD project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'CRUD.settings')
application = get_asgi_application()
"""
Django settings for CRUD project.
Generated by 'django-admin startproject' using Django 3.1.7.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'ofa(1ue80oz=p-zrgxn401tnxo$74%z2u_lps51(j%9&789s94'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'App',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'CRUD.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'CRUD.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'ta2',
'USER': 'root',
'PASSWORD': '',
'HOST':'localhost',
'PORT':'3306',
'OPTIONS':{
'init_command':"SET sql_mode='STRICT_TRANS_TABLES'"
}
}
}
# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL = '/static/'
from django.contrib import admin
from django.conf.urls import url,include
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^App/', include(('App.urls', 'App'), namespace='App')),
]
"""
WSGI config for CRUD project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'CRUD.settings')
application = get_wsgi_application()
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'CRUD.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
<!DOCTYPE html>
<html lang="en">
<head>
<title>
{% block title %}
{% endblock title %}
</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Penjadwalan</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="{% url 'App:listmatakuliah' %}">Matakuliah</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'App:listkelas' %}">Kelas</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'App:listpengajar' %}">Pengajar</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'App:list' %}">Sesi</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'App:listakun' %}">Akun</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'App:listjadwal' %}">Jadwal</a>
</li>
</ul>
</div>
</div>
</nav>
{% block contents %}
{% endblock contents %}
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.1/dist/umd/popper.min.js" integrity="sha384-SR1sx49pcuLnqZUnnPwx6FCym0wLsk5JZuNx2bPPENzswTNFaQU1RDvt3wT4gWFG" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.min.js" integrity="sha384-j0CNLUeiqtyaRmlzUHCPZ+Gy5fQu0dQ6eZ/xAww941Ai1SxSY+0EQqNXNE6DZiVc" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.bundle.min.js" integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf" crossorigin="anonymous"></script>
</body>
</html>
\ No newline at end of file
{% extends "base.html" %}
{% block title %}
{{page_title}}
{% endblock title %}
{% block contents %}
<h1>{{page_title}}</h1>
{% endblock contents %}
\ No newline at end of file
from re import L
from csp import Constraint, CSP
from typing import Dict, List, NamedTuple, Optional, Tuple
import mysql.connector as mysql
db = mysql.connect(
host = "localhost",
user = "root",
passwd = "",
database="ta2",
)
cursor = db.cursor()
akun="select * from app_akun"
cursor.execute(akun)
akuns = cursor.fetchall()
dosen="select * from pmk"
cursor.execute(dosen)
dosens = cursor.fetchall()
hari="select * from app_hari"
cursor.execute(hari)
haris = cursor.fetchall()
kelas="select * from app_kelas"
cursor.execute(kelas)
kelass = cursor.fetchall()
matkul="select * from app_matkul"
cursor.execute(matkul)
matkuls = cursor.fetchall()
sesi="select * from app_sesi"
cursor.execute(sesi)
sesis = cursor.fetchall()
Grid = List[List[List[Tuple]]]
class GridSchedule(NamedTuple):
row: int
column: int
akun: int
def generate_grid(rows: int, columns: int, akuns: int)->Grid:
return [[[[] for j in range(akuns)] for i in range(rows)]for a in range(columns)]
def display_grid(grid: Grid)->None:
for row in grid:
print("".join(row))
def generate_domain(dms:Tuple,grid: Grid) -> List[List[List[GridSchedule]]]:
domain: List[List[List[GridSchedule]]] = []
height: int = len(grid)
width: int = len(grid[0])
akuns: int = len(grid[0][0])
for col in range(height):
for row in range(width):
for akun in range(akuns):
domain.append([GridSchedule(row,col,akun)])
return domain
class GenerateConstraint(Constraint[Tuple, List[GridSchedule]]):
def _init_(self, dms: List[Tuple]) -> None:
super()._init_(dms)
self.dms: List[Tuple] = dms
def satisfied(self, assignment: Dict[Tuple, List[GridSchedule]]) -> bool:
for dms,grid in assignment.items():
for dms1,grid1 in assignment.items():
if dms==dms1:
break
else:
if dms[0]==dms1[0] and grid[0][0:2]==grid1[0][0:2]:
return False
elif dms[1]==dms1[1] and grid[0][0:2]==grid1[0][0:2]:
return False
elif dms[1:3]==dms1[1:3] and grid[0][1]==grid1[0][1]:
return False
elif dms[4]==1 and grid[0][2]==0 or dms1[4]==1 and grid1[0][2]==0:
return False
elif dms[4]==2 and grid[0][2]!=0 or dms1[4]==2 and grid1[0][2]!=0:
return False
elif dms[4]==1 or dms1[4]==1:
if grid[0][0:2]==grid1[0][0:2] and grid[0][2]==grid1[0][2]:
return False
return True
if __name__ == "__main__":
jumlah_sesi = len(sesis)
jumlah_hari = len(haris)
jumlah_akun =len(akuns)
grid: Grid=generate_grid( jumlah_sesi, jumlah_hari, jumlah_akun)
dms : List[Tuple] = [row for row in dosens]
location: Dict[Tuple, List[List[List[GridSchedule]]]] = {}
for items in dms:
location[items]= generate_domain(items,grid)
csp: CSP[Tuple, List[GridSchedule]] = CSP(dms, location)
csp.add_constraint(GenerateConstraint(dms))
solution: Optional[Dict[Tuple, List[GridSchedule]]] = csp.backtracking_search()
if solution is None:
print("No solution found!")
else:
truncate="TRUNCATE TABLE app_jadwal"
cursor.execute(truncate)
for dms, grid_locations in solution.items():
insert="INSERT INTO app_jadwal(no_Akun_id,no_Hari_id,no_Kelas_id,no_Matkul_id,no_Pengajar_id,no_Sesi_id) VALUES(%s,%s,%s,%s,%s,%s)"
val = (( grid_locations[0][2]+1),( grid_locations[0][1]+1),dms[1],dms[5],dms[0],(grid_locations[0][0]+1))
cursor.execute(insert,val)
db.commit()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment