From b3eda54f5cb96800a73a4f186886d1018c02a8ff Mon Sep 17 00:00:00 2001 From: saras355 Date: Thu, 2 May 2024 09:50:13 +0700 Subject: [PATCH 01/13] ada beberapa views dan navbar --- akun/__init__.py | 0 akun/admin.py | 3 + akun/apps.py | 6 + akun/deskripsi.txt | 2 + akun/migrations/__init__.py | 0 akun/models.py | 3 + akun/tests.py | 3 + akun/views.py | 3 + album_song_royalti/__init__.py | 0 album_song_royalti/admin.py | 3 + album_song_royalti/apps.py | 6 + album_song_royalti/migrations/__init__.py | 0 album_song_royalti/models.py | 3 + album_song_royalti/templates/cek_royalti.html | 72 +++ .../templates/kelola_album_song.html | 192 ++++++++ .../templates/rd_kelola_album_and_song.html | 95 ++++ album_song_royalti/templates/styles.css | 104 +++++ album_song_royalti/tests.py | 3 + album_song_royalti/views.py | 3 + artist_songwriter/__init__.py | 0 artist_songwriter/admin.py | 3 + artist_songwriter/apps.py | 6 + artist_songwriter/migrations/__init__.py | 0 artist_songwriter/models.py | 3 + artist_songwriter/tests.py | 3 + artist_songwriter/views.py | 3 + auth/__init__.py | 0 auth/admin.py | 3 + auth/apps.py | 6 + auth/migrations/__init__.py | 0 auth/models.py | 3 + auth/templates/dashboard.html | 97 ++++ auth/templates/dashboard_label_tk3.html | 68 +++ auth/templates/dashboard_untuk_tk3.html | 57 +++ auth/templates/home.html | 20 + auth/templates/home_untuk_tk3.html | 28 ++ auth/templates/is_label_register.html | 53 +++ auth/templates/is_pengguna_register.html | 147 ++++++ auth/templates/login.html | 25 + auth/templates/login_untuk_tk3.html | 58 +++ auth/templates/register.html | 0 auth/templates/register_untuk_tk3.html | 45 ++ auth/templates/style2.css | 63 +++ auth/templates/styles.css | 111 +++++ auth/tests.py | 3 + auth/urls.py | 12 + auth/views.py | 433 ++++++++++++++++++ label/__init__.py | 0 label/admin.py | 3 + label/apps.py | 6 + label/migrations/__init__.py | 0 label/models.py | 3 + label/templates/label_dashboard.html | 58 +++ label/templates/style2.css | 63 +++ label/tests.py | 3 + label/views.py | 6 + pengguna_biasa/__init__.py | 0 pengguna_biasa/admin.py | 3 + pengguna_biasa/apps.py | 6 + pengguna_biasa/migrations/__init__.py | 0 pengguna_biasa/models.py | 3 + pengguna_biasa/tests.py | 3 + pengguna_biasa/views.py | 3 + podcaster/__init__.py | 0 podcaster/admin.py | 3 + podcaster/apps.py | 6 + podcaster/migrations/__init__.py | 0 podcaster/models.py | 3 + podcaster/tests.py | 3 + podcaster/views.py | 3 + templates/base.html | 12 + templates/nav.html | 70 +++ 72 files changed, 2011 insertions(+) create mode 100644 akun/__init__.py create mode 100644 akun/admin.py create mode 100644 akun/apps.py create mode 100644 akun/deskripsi.txt create mode 100644 akun/migrations/__init__.py create mode 100644 akun/models.py create mode 100644 akun/tests.py create mode 100644 akun/views.py create mode 100644 album_song_royalti/__init__.py create mode 100644 album_song_royalti/admin.py create mode 100644 album_song_royalti/apps.py create mode 100644 album_song_royalti/migrations/__init__.py create mode 100644 album_song_royalti/models.py create mode 100644 album_song_royalti/templates/cek_royalti.html create mode 100644 album_song_royalti/templates/kelola_album_song.html create mode 100644 album_song_royalti/templates/rd_kelola_album_and_song.html create mode 100644 album_song_royalti/templates/styles.css create mode 100644 album_song_royalti/tests.py create mode 100644 album_song_royalti/views.py create mode 100644 artist_songwriter/__init__.py create mode 100644 artist_songwriter/admin.py create mode 100644 artist_songwriter/apps.py create mode 100644 artist_songwriter/migrations/__init__.py create mode 100644 artist_songwriter/models.py create mode 100644 artist_songwriter/tests.py create mode 100644 artist_songwriter/views.py create mode 100644 auth/__init__.py create mode 100644 auth/admin.py create mode 100644 auth/apps.py create mode 100644 auth/migrations/__init__.py create mode 100644 auth/models.py create mode 100644 auth/templates/dashboard.html create mode 100644 auth/templates/dashboard_label_tk3.html create mode 100644 auth/templates/dashboard_untuk_tk3.html create mode 100644 auth/templates/home.html create mode 100644 auth/templates/home_untuk_tk3.html create mode 100644 auth/templates/is_label_register.html create mode 100644 auth/templates/is_pengguna_register.html create mode 100644 auth/templates/login.html create mode 100644 auth/templates/login_untuk_tk3.html create mode 100644 auth/templates/register.html create mode 100644 auth/templates/register_untuk_tk3.html create mode 100644 auth/templates/style2.css create mode 100644 auth/templates/styles.css create mode 100644 auth/tests.py create mode 100644 auth/urls.py create mode 100644 auth/views.py create mode 100644 label/__init__.py create mode 100644 label/admin.py create mode 100644 label/apps.py create mode 100644 label/migrations/__init__.py create mode 100644 label/models.py create mode 100644 label/templates/label_dashboard.html create mode 100644 label/templates/style2.css create mode 100644 label/tests.py create mode 100644 label/views.py create mode 100644 pengguna_biasa/__init__.py create mode 100644 pengguna_biasa/admin.py create mode 100644 pengguna_biasa/apps.py create mode 100644 pengguna_biasa/migrations/__init__.py create mode 100644 pengguna_biasa/models.py create mode 100644 pengguna_biasa/tests.py create mode 100644 pengguna_biasa/views.py create mode 100644 podcaster/__init__.py create mode 100644 podcaster/admin.py create mode 100644 podcaster/apps.py create mode 100644 podcaster/migrations/__init__.py create mode 100644 podcaster/models.py create mode 100644 podcaster/tests.py create mode 100644 podcaster/views.py create mode 100644 templates/base.html create mode 100644 templates/nav.html diff --git a/akun/__init__.py b/akun/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/akun/admin.py b/akun/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/akun/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/akun/apps.py b/akun/apps.py new file mode 100644 index 0000000..8ed3838 --- /dev/null +++ b/akun/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class AkunConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "akun" diff --git a/akun/deskripsi.txt b/akun/deskripsi.txt new file mode 100644 index 0000000..15bad12 --- /dev/null +++ b/akun/deskripsi.txt @@ -0,0 +1,2 @@ +akun ini untuk nampilin dashboard-> kan ada beberapa role yang kenak -> tpai tetep pengguna +ini fungsinya. \ No newline at end of file diff --git a/akun/migrations/__init__.py b/akun/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/akun/models.py b/akun/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/akun/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/akun/tests.py b/akun/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/akun/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/akun/views.py b/akun/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/akun/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/album_song_royalti/__init__.py b/album_song_royalti/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/album_song_royalti/admin.py b/album_song_royalti/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/album_song_royalti/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/album_song_royalti/apps.py b/album_song_royalti/apps.py new file mode 100644 index 0000000..fe3645c --- /dev/null +++ b/album_song_royalti/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class AlbumSongRoyaltiConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "album_song_royalti" diff --git a/album_song_royalti/migrations/__init__.py b/album_song_royalti/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/album_song_royalti/models.py b/album_song_royalti/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/album_song_royalti/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/album_song_royalti/templates/cek_royalti.html b/album_song_royalti/templates/cek_royalti.html new file mode 100644 index 0000000..cf07b92 --- /dev/null +++ b/album_song_royalti/templates/cek_royalti.html @@ -0,0 +1,72 @@ + + + + + + Cek Royalti + + + + + + + + + + + +

LIST ROYALTI

+ + + + + + + + + + + + + + + + + + + + + + + + +
Judul LaguJudul AlbumTotal PlayTotal DownloadTotal Royalti Didapat
Lagu1Album130Rp 450000
Lagu2Album222Rp 520000
+ + diff --git a/album_song_royalti/templates/kelola_album_song.html b/album_song_royalti/templates/kelola_album_song.html new file mode 100644 index 0000000..a962cae --- /dev/null +++ b/album_song_royalti/templates/kelola_album_song.html @@ -0,0 +1,192 @@ + + + + + + + + + CRUD Kelola Album & Song + + + + + +

CREATE ALBUM

+
+
+
+
+

+ +
+ + +

LIST ALBUM

+ + + + + + + + + + + + + + + + + + + + + + + + +
JudulLabelJumlah LaguTotal DurasiAction
Album1LabelA00 menit + Lihat Daftar Lagu + Tambah Lagu + Hapus +
Album2LabelB24 menit + Lihat Daftar Lagu + Tambah Lagu + Hapus +
+ + +

CREATE LAGU

+
+
+
+
+
+
+
+
+ +
+ Pilih artist + +
+
+
+ + +
+
+ + +
+ +
+
+
+
+
+
+ +
+ Pilih songwriter + +
+
+
+ + +
+
+ + +
+ +
+
+
+
+
+
+ +
+ Pilih genre + +
+
+
+ + +
+
+ + +
+ +
+
+
+
+

+ +
+ + +

DAFTAR LAGU PADA ALBUM1

+ + + + + + + + + + + + + + + + + + + + + + + + +
JudulDurasiTotal PlayTotal DownloadAction
Lagu12 menit30 + Lihat Detail + Hapus +
Lagu23 menit22 + Lihat Detail + Hapus +
+ + diff --git a/album_song_royalti/templates/rd_kelola_album_and_song.html b/album_song_royalti/templates/rd_kelola_album_and_song.html new file mode 100644 index 0000000..388a9b4 --- /dev/null +++ b/album_song_royalti/templates/rd_kelola_album_and_song.html @@ -0,0 +1,95 @@ + + + + + + + + CRUD Kelola Album & Song + + + + + + + + + + Kelola Album + + + + + +

LIST ALBUM

+ + + + + + + + + + + + + + + + + + + + + +
JudulJumlah LaguTotal DurasiAction
Album100 menit + Lihat Daftar Lagu + Hapus +
Album224 menit + Lihat Daftar Lagu + Hapus +
+ + +

DAFTAR LAGU PADA ALBUM1

+ + + + + + + + + + + + + + + + + + + + + + + + +
JudulDurasiTotal PlayTotal DownloadAction
Lagu12 menit30 + Lihat Detail + Hapus +
Lagu23 menit22 + Lihat Detail + Hapus +
+ + diff --git a/album_song_royalti/templates/styles.css b/album_song_royalti/templates/styles.css new file mode 100644 index 0000000..77ee017 --- /dev/null +++ b/album_song_royalti/templates/styles.css @@ -0,0 +1,104 @@ +.navbar { + background-color: #007bff; /* Warna latar belakang navbar */ + overflow: hidden; +} + +.navbar ul { + list-style-type: none; /* Menghilangkan bullet list */ + margin: 0; + padding: 0; +} + +.navbar li { + float: left; +} + +.navbar li a { + display: block; + color: white; + text-align: center; + padding: 14px 16px; + text-decoration: none; +} + +.navbar li a:hover { + background-color: #0056b3; /* Warna latar belakang saat mouse hover */ +} + + + +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +body { + font-family: Arial, sans-serif; + line-height: 1.6; + background-color: #f4f4f4; + padding: 20px; +} + +.container { + max-width: 1200px; + margin: 0 auto; +} + +h2 { + margin-bottom: 20px; +} + +form { + background: #fff; + padding: 20px; + border-radius: 5px; + box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); +} + +form label { + font-weight: bold; + display: block; + margin-bottom: 5px; +} + +form input[type="text"], +form select { + width: 100%; + padding: 10px; + margin-bottom: 10px; + border: 1px solid #ccc; + border-radius: 5px; +} + +form input[type="submit"] { + background: #007bff; + color: #fff; + border: none; + padding: 10px 20px; + cursor: pointer; + border-radius: 5px; +} + +table { + width: 100%; + border-collapse: collapse; + margin-top: 20px; +} + +table th, +table td { + padding: 10px; + border: 1px solid #ccc; + text-align: left; +} + +table th { + background-color: #f2f2f2; +} + +a { + text-decoration: none; + color: #007bff; + margin-right: 10px; +} diff --git a/album_song_royalti/tests.py b/album_song_royalti/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/album_song_royalti/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/album_song_royalti/views.py b/album_song_royalti/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/album_song_royalti/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/artist_songwriter/__init__.py b/artist_songwriter/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/artist_songwriter/admin.py b/artist_songwriter/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/artist_songwriter/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/artist_songwriter/apps.py b/artist_songwriter/apps.py new file mode 100644 index 0000000..33fbabf --- /dev/null +++ b/artist_songwriter/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ArtistSongwriterConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "artist_songwriter" diff --git a/artist_songwriter/migrations/__init__.py b/artist_songwriter/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/artist_songwriter/models.py b/artist_songwriter/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/artist_songwriter/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/artist_songwriter/tests.py b/artist_songwriter/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/artist_songwriter/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/artist_songwriter/views.py b/artist_songwriter/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/artist_songwriter/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/auth/__init__.py b/auth/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/auth/admin.py b/auth/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/auth/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/auth/apps.py b/auth/apps.py new file mode 100644 index 0000000..6a09aaa --- /dev/null +++ b/auth/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class AuthConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "auth" diff --git a/auth/migrations/__init__.py b/auth/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/auth/models.py b/auth/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/auth/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/auth/templates/dashboard.html b/auth/templates/dashboard.html new file mode 100644 index 0000000..f7550f7 --- /dev/null +++ b/auth/templates/dashboard.html @@ -0,0 +1,97 @@ + + +{% extends 'base.html' %} + + +

Dashboard

+

Informasi Profil Pengguna:

+

Nama: {{ user_data.nama }}

+

Email: {{ user_data.email }}

+ {% if user_data.kota_asal %} +

Kota Asal: {{ user_data.kota_asal }}

+ {% endif %} + {% if user_data.gender %} +

Gender: {{ user_data.gender }}

+ {% endif %} + {% if user_data.tempat_lahir %} +

Tempat Lahir: {{ user_data.tempat_lahir }}

+ {% endif %} + {% if user_data.tanggal_lahir %} +

Tanggal Lahir: {{ user_data.tanggal_lahir }}

+ {% endif %} + {% if user_data.role %} +

Role: {{ user_data.role }}

+ {% endif %} + + + + + {% if not user_data.is_artist and not user_data.is_podcaster and not user_data.is_songwriter %} + + {% if playlists %} +

Daftar Playlist

+ + {% else %} +

Belum memiliki playlist.

+ {% endif %} + {% endif %} + + + {% if user_data.is_artist or user_data.is_songwriter %} + + {% if songs %} +

Daftar Lagu

+ + {% else %} +

Belum memiliki lagu.

+ {% endif %} + {% endif %} + + + {% if user_data.is_podcaster %} + + {% if podcasts %} +

Daftar Podcast

+ + {% else %} +

Belum memiliki podcast.

+ {% endif %} + {% endif %} + + + + + + + \ No newline at end of file diff --git a/auth/templates/dashboard_label_tk3.html b/auth/templates/dashboard_label_tk3.html new file mode 100644 index 0000000..b5fdc33 --- /dev/null +++ b/auth/templates/dashboard_label_tk3.html @@ -0,0 +1,68 @@ + + + + + + + Dashboard + + + + + + + +

Dashboard

+

Informasi Profil Pengguna:

+

Nama: John Doe

+

Email: john@example.com

+

Kota Asal: New York

+

Role: Label

+ + + + +

Belum memiliki album.

+ + + + diff --git a/auth/templates/dashboard_untuk_tk3.html b/auth/templates/dashboard_untuk_tk3.html new file mode 100644 index 0000000..bf3ed7c --- /dev/null +++ b/auth/templates/dashboard_untuk_tk3.html @@ -0,0 +1,57 @@ + + + + + + Dashboard + + + + + + + + +

Dashboard

+

Informasi Profil Pengguna:

+

Nama: John Doe

+

Email: john@example.com

+

Kota Asal: New York

+

Gender: Laki-laki

+

Tempat Lahir: Jakarta

+

Tanggal Lahir: 1990-01-01

+

Role: Podcaster, Artist, Songwriter

+ + + +

Daftar Playlist

+

Belum memiliki playlist.

+ + + +

Daftar Lagu

+

Belum memiliki lagu.

+ + + +

Daftar Podcast

+

Belum memiliki lagu.

+ + diff --git a/auth/templates/home.html b/auth/templates/home.html new file mode 100644 index 0000000..6593d21 --- /dev/null +++ b/auth/templates/home.html @@ -0,0 +1,20 @@ +{% extends 'base.html' %} + +{% block content %} + {% include 'nav.html' %} + +
+
+
+

Marmut - KODE KELOMPOK

+
+
+
+
+ Login + Register +
+
+
+{% endblock content %} + diff --git a/auth/templates/home_untuk_tk3.html b/auth/templates/home_untuk_tk3.html new file mode 100644 index 0000000..b2464d6 --- /dev/null +++ b/auth/templates/home_untuk_tk3.html @@ -0,0 +1,28 @@ + + + + + + + +
+
+
+

Marmut - 1

+
+
+
+
+ Login + Register +
+
+
+ + diff --git a/auth/templates/is_label_register.html b/auth/templates/is_label_register.html new file mode 100644 index 0000000..d66df31 --- /dev/null +++ b/auth/templates/is_label_register.html @@ -0,0 +1,53 @@ + + + + + + Register as Label + + + + + + +
+

FORM REGISTRASI

+
+ + + + + + + + + + + + + +
+
+ + diff --git a/auth/templates/is_pengguna_register.html b/auth/templates/is_pengguna_register.html new file mode 100644 index 0000000..1bbd270 --- /dev/null +++ b/auth/templates/is_pengguna_register.html @@ -0,0 +1,147 @@ + + + + + + Register + + + + + +
+

FORM REGISTRASI

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + diff --git a/auth/templates/login.html b/auth/templates/login.html new file mode 100644 index 0000000..47f5e0c --- /dev/null +++ b/auth/templates/login.html @@ -0,0 +1,25 @@ +{% extends 'base.html' %} + +{% block content %} + {% include 'nav.html' %} + +
+
+
+

FORM LOGIN

+
+ {% csrf_token %} +
+ + +
+
+ + +
+ +
+
+
+
+{% endblock content %} diff --git a/auth/templates/login_untuk_tk3.html b/auth/templates/login_untuk_tk3.html new file mode 100644 index 0000000..97e6577 --- /dev/null +++ b/auth/templates/login_untuk_tk3.html @@ -0,0 +1,58 @@ + + + + + + Login + + + + + + +
+

FORM LOGIN

+
+
+
+
+

+ +
+
+ + diff --git a/auth/templates/register.html b/auth/templates/register.html new file mode 100644 index 0000000..e69de29 diff --git a/auth/templates/register_untuk_tk3.html b/auth/templates/register_untuk_tk3.html new file mode 100644 index 0000000..1d15693 --- /dev/null +++ b/auth/templates/register_untuk_tk3.html @@ -0,0 +1,45 @@ + + + + + + Register + + + + + + + +
+

Register

+ + +
+ + + + diff --git a/auth/templates/style2.css b/auth/templates/style2.css new file mode 100644 index 0000000..02428fe --- /dev/null +++ b/auth/templates/style2.css @@ -0,0 +1,63 @@ +/* CSS untuk style2.css */ + +body { + margin: 0; + font-family: Arial, sans-serif; +} + +.navbar { + background-color:#007bff; + overflow: hidden; +} + +.navbar ul { + list-style-type: none; + margin: 0; + padding: 0; +} + +.navbar li { + float: left; +} + +.navbar li a { + display: block; + color: white; + text-align: center; + padding: 14px 16px; + text-decoration: none; +} + +.navbar li a:hover { + background-color: #007bff; +} + +.navbar .search-bar { + margin-left: auto; +} + +.navbar form { + display: flex; + align-items: center; +} + +.navbar input[type="search"] { + padding: 8px; + border: none; + border-radius: 5px 0 0 5px; + margin-right: 0; + background-color: #fff; /* Tambahkan warna latar belakang */ +} + +.navbar button[type="submit"] { + padding: 8px 12px; + background-color: #007bff; + color: white; + border: none; + border-radius: 0 5px 5px 0; + cursor: pointer; +} + +.navbar button[type="submit"]:hover { + background-color: #007bff; +} diff --git a/auth/templates/styles.css b/auth/templates/styles.css new file mode 100644 index 0000000..3897e3e --- /dev/null +++ b/auth/templates/styles.css @@ -0,0 +1,111 @@ +.navbar { + background-color: #007bff; /* Warna latar belakang navbar */ + overflow: hidden; +} + +.navbar ul { + list-style-type: none; /* Menghilangkan bullet list */ + margin: 0; + padding: 0; +} + +.navbar li { + float: left; +} +.container { + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + text-align: center; +} + +.navbar li a { + display: block; + color: white; + text-align: center; + padding: 14px 16px; + text-decoration: none; +} + +.navbar li a:hover { + background-color: #0056b3; /* Warna latar belakang saat mouse hover */ +} + + + +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +body { + font-family: Arial, sans-serif; + line-height: 1.6; + background-color: #f4f4f4; + padding: 20px; +} + +.container { + max-width: 1200px; + margin: 0 auto; +} + +h2 { + margin-bottom: 20px; +} + +form { + background: #fff; + padding: 20px; + border-radius: 5px; + box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); +} + +form label { + font-weight: bold; + display: block; + margin-bottom: 5px; +} + +form input[type="text"], +form select { + width: 100%; + padding: 10px; + margin-bottom: 10px; + border: 1px solid #ccc; + border-radius: 5px; +} + +form input[type="submit"] { + background: #007bff; + color: #fff; + border: none; + padding: 10px 20px; + cursor: pointer; + border-radius: 5px; +} + +table { + width: 100%; + border-collapse: collapse; + margin-top: 20px; +} + +table th, +table td { + padding: 10px; + border: 1px solid #ccc; + text-align: left; +} + +table th { + background-color: #f2f2f2; +} + +a { + text-decoration: none; + color: #007bff; + margin-right: 10px; +} diff --git a/auth/tests.py b/auth/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/auth/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/auth/urls.py b/auth/urls.py new file mode 100644 index 0000000..e5d2102 --- /dev/null +++ b/auth/urls.py @@ -0,0 +1,12 @@ +from django.urls import path +from .views import * +app_name = 'auth' + + +urlpatterns = [ + path('', show_home, name='home'), + path('register/', register_with_postgres, name='register' ), + path('login/', login_with_postgres, name='login' ), + path('logout/', logout_with_postgres, name='logout'), + path('dashboard/', dashboard_view, name='dashboard'), +] \ No newline at end of file diff --git a/auth/views.py b/auth/views.py new file mode 100644 index 0000000..51b66aa --- /dev/null +++ b/auth/views.py @@ -0,0 +1,433 @@ +from django.shortcuts import render, redirect +from django.contrib.auth import authenticate, login +from django.contrib import messages +# from .forms import LoginForm -> ga usah pakai form langsung dari login.html aja(?) +import json +from django.db import connection +from connect_postgres import execute_sql_query +from django.shortcuts import render, redirect +from django.http import JsonResponse,HttpResponseRedirect +import datetime +import uuid +from django.views.decorators.csrf import csrf_exempt +from django.contrib import messages +from django.contrib.auth.hashers import check_password +from django.urls import reverse +import psycopg2 + +def show_home(request): + return render(request, "home.html") + +def show_register(request): + return render(request, "register.html") + +def show_login(request): + return render(request, "login.html") +#next blm ganti + + +@csrf_exempt +def logout_with_postgres(request): + # Hapus data sesi pengguna + if 'user_data' in request.session: + del request.session['user_data'] + + # Lakukan logout pengguna menggunakan fungsi bawaan Django + + # Redirect ke halaman login atau halaman lain yang sesuai + return redirect('home') #based dari nama yang dibentuk di urls.py + +@csrf_exempt +def register_with_postgres(request): + if request.method == 'POST': + # SAMA --------------------------- + email = request.POST.get('email') + password = request.POST.get('password') + confirm_password = request.POST.get('confirm_password') + fname = request.POST.get('fname') + lname = request.POST.get('lname') + phone_num = request.POST.get('phone_num') + # SAMA ------------------------------------- + # HANYA CUSTOMER --------------------------- + nik = request.POST.get('nik') + # HANYA HOTEL ------------------------------ + hotel_name = request.POST.get('hotel_name') + hotel_branch = request.POST.get('hotel_branch') + nib = request.POST.get('nib') + star = request.POST.get('star') + street = request.POST.get('street') + district = request.POST.get('district') + city = request.POST.get('city') + province = request.POST.get('province') + description = request.POST.get('description') + min_checkout = request.POST.get('min_checkout') + max_checkout = request.POST.get('max_checkout') + print(hotel_name) + + # CEK REGISTER CUSTOMER ATAU HOTEL + is_customer = True if nik is not None else False + + # CEK CUSTOMER + if is_customer and not all([email.strip(), password.strip(), confirm_password.strip(), fname.strip(), lname.strip(), nik.strip(), phone_num.strip()]): + messages.error(request, 'Mohon lengkapi field yang kosong dalam mendaftarkan customer.') + # CEK HOTEL + elif not is_customer and not all([email.strip(), password.strip(), + confirm_password.strip(), fname.strip(), lname.strip(), + hotel_name.strip(), hotel_branch.strip(), nib.strip(), star, + street.strip(),district.strip(),city.strip(), + province.strip(), description.strip(), + min_checkout.strip(), max_checkout.strip(), phone_num.strip()]): + messages.error(request, 'Mohon lengkapi field yang kosong dalam mendaftarkan hotel.') + # CEK BINTANG + elif not is_customer and not star.isdigit(): + messages.error(request, 'Maaf, bintang hotel harus bilangan bulat.') + # CEK RANGE BINTANG + elif not is_customer and (float(star) < 1 or float(star) > 5): + messages.error(request, 'Maaf, bintang hotel harus ada di range 1 sampai 5.') + # CEK PASSWORD + elif password != confirm_password: + messages.error(request, 'Password dan konfirmasi password tidak cocok.') + else: + if is_customer: + query= f""" + + INSERT INTO sistel.user (email, password, fname, lname) VALUES ('{email}','{password}', '{fname}', '{lname}'); + INSERT INTO reservation_actor (email, phonenum) VALUES ('{email}','{phone_num}'); + INSERT INTO customer (email, nik) VALUES ('{email}','{nik}') + RETURNING email; + + """ + else: + query = f""" + INSERT INTO sistel.user (email, password, fname, lname) VALUES ('{email}','{password}', '{fname}', '{lname}'); + INSERT INTO reservation_actor (email, phonenum) VALUES ('{email}','{phone_num}'); + INSERT INTO hotel + (email, hotel_name, hotel_branch, nib, star, street, district, city, + province, description, max_checkout, min_checkout) VALUES ( + '{email}', '{hotel_name}', '{hotel_branch}', '{nib}', + {star}, '{street}', '{district}', '{city}', '{province}', + '{description}', '{max_checkout}', '{min_checkout}' + ) + RETURNING email; + + """ + try: + execute_sql_query(query=query) + return HttpResponseRedirect('/login/') + except psycopg2.Error as error: + messages.error(request, f'{error}') + except Exception as error: + messages.error(request, f'{error}') + return render(request,"register.html") + + + +#LOGINNNNNNNNNNN + # ketika masuk pertama kali berarti -> ada dua kemungkinan bisa label atau bisa saja pengguna . + # ketika masuk sebagai pengguna maka ada kombinasi dair 3 kemungkiann -> bisa podcaster artsit atau songwriter + # nah ini caranya denagn loop ke semua table terkait saja lalu pakekkan is untuk setiap + + + # is_user -> kalau dia ada di akun + # is_premium + # is_artist + # is_songwriter + # is_podcaster + # is_label + + #cek dulu apakah emailnya ada di akun (is_user jadi true kalau ada ) atau ada di table label (is_label jadi true kalau ada ) + # kalau misalnya ada ga ada di keduanya maka berikan mesage error pengguna tidak ditemukan. + + #kalau email ditemukan entah salah satu di table akun atau di table label + #maka cek apakah passwordnya benar -> kalau passwordnya benar + #kalau passwordnya salah berikan pesan error bahwa password salah + #kalau passwordnya benar lalu selanjutnya akan ke dashboard.html tetapi sebelumnya skenarionya speerti ini + + + #sekanrionya pasti salah satu entah is_user true atau is_label yang true + #kalau is_user true, ambil nama, email, kota asal, gender, tempat lahir, tanggal lahir yang dipunya user + #ini kayaknya ga ada hubungan dulu ke user premium atau ga -> tapi yg penting megang email bisa disearch dia premium atau ga + #nah ada role -> ini ntar diisi dengan is aja , kalau cmn is_user saja yg true maka jadi pengguna biasa, kalau yang lainnya ada + #is_podcaster gtgt masuk berarti nanti tinggal ditambhin aja di rolenya saja-> di kode htmlnya saja. (pakai if) + + #kalau dia is_user nya true dan is_labelnya false, maka unutk isi tiap kemungkinan is + #kita cek apakah email user tersebut ada atau tidak di table artist, table songwriter, dan tabel podcaster + + + #kalau dia is_user false dan is_label true -> maka kita ambil nama, email, kontak, dan + #dan dari ambil id_label nya buat nanti mencari semua album yang id_label sama dengan label.id dari user yang log in ini. + #dan nanti di htmlnya ada menampilkan kode untuk nampilin album id ini -> next atau hmm buat views baru aja + #kalau ternyata id labelnya tidak ada di table album maka tampilan pesan nanti di htmlnya belum memproduksi album + +@csrf_exempt +def login_with_postgres(request): + is_premium = False + is_artist = False + is_songwriter = False + is_podcaster = False + is_label = False + + if request.method == 'POST': + email = request.POST.get('email') + password = request.POST.get('password') + + # Query untuk mencari pengguna berdasarkan email di tabel akun + query_akun = f""" + SELECT *, + CASE WHEN EXISTS ( + SELECT 1 FROM marmut.akun u + WHERE u.email = '{email}' + ) THEN 'true' + ELSE 'false' END AS is_user + FROM marmut.akun WHERE email = '{email}' + """ + # Eksekusi query tabel akun + matching_users_akun = execute_sql_query(query=query_akun) + + # Query untuk mencari pengguna berdasarkan email di tabel label + query_label = f""" + SELECT *, + CASE WHEN EXISTS ( + SELECT 1 FROM marmut.label l + WHERE l.email = '{email}' + ) THEN 'true' + ELSE 'false' END AS is_label + FROM marmut.label WHERE email = '{email}' + """ + # Eksekusi query tabel label + matching_users_label = execute_sql_query(query=query_label) + + if len(matching_users_akun) == 0 and len(matching_users_label) == 0: + # Jika email tidak ditemukan di kedua tabel + messages.error(request, 'Pengguna tidak ditemukan.') + else: + # Jika email ditemukan di salah satu atau kedua tabel + user_data = {} + + if len(matching_users_akun) > 0: + # Jika pengguna ada di tabel akun + user_akun = matching_users_akun[0] + if user_akun['password'] == password: + # Jika password sesuai, ambil informasi pengguna dari tabel akun + user_data['email'] = user_akun['email'] + user_data['nama'] = user_akun['nama'] + user_data['kota_asal'] = user_akun['kota_asal'] + user_data['gender'] = user_akun['gender'] + user_data['tempat_lahir'] = user_akun['tempat_lahir'] + user_data['tanggal_lahir'] = user_akun['tanggal_lahir'] + + + roles = [] + # Cek role pengguna + # Cek apakah email pengguna ada di tabel Premium + query_premium = f""" + SELECT * FROM marmut.premium + WHERE email = '{user_akun['email']}' + """ + matching_premium = execute_sql_query(query=query_premium) + if len(matching_premium) > 0: + roles.append('Premium') + is_premium = True + + # Cek apakah email pengguna ada di tabel Artist + query_artist = f""" + SELECT * FROM marmut.artist + WHERE email = '{user_akun['email']}' + """ + matching_artist = execute_sql_query(query=query_artist) + if len(matching_artist) > 0: + roles.append('Artist') + is_artist = True + + # Cek apakah email pengguna ada di tabel Songwriter + query_songwriter = f""" + SELECT * FROM marmut.songwriter + WHERE email = '{user_akun['email']}' + """ + matching_songwriter = execute_sql_query(query=query_songwriter) + if len(matching_songwriter) > 0: + roles.append('Songwriter') + is_songwriter = True + + # Cek apakah email pengguna ada di tabel Podcaster + query_podcaster = f""" + SELECT * FROM marmut.podcaster + WHERE email = '{user_akun['email']}' + """ + matching_podcaster = execute_sql_query(query=query_podcaster) + if len(matching_podcaster) > 0: + roles.append('Podcaster') + is_podcaster = True + + + user_data['role'] = ', '.join(roles) + #berarti pengguna biasa ga ada is_pengguna biasa tapi cek aja is dari tiap role + request.session['user_data'] = { + 'email': email, + 'nama': user_akun.get('nama', ''), + 'password': password, + 'is_premium' : is_premium, + 'is_artist' : is_artist, + 'is_songwriter' : is_songwriter , + 'is_podcaster' : is_podcaster, + 'is_label' : is_label + } + + # Redirect ke halaman dashboard pengguna + return HttpResponseRedirect('/dashboard/') + else: + messages.error(request, 'Maaf, password yang Anda masukkan salah.') + + if len(matching_users_label) > 0: + # Jika pengguna ada di tabel label + user_label = matching_users_label[0] + # Ambil informasi pengguna dari tabel label + if user_label['password'] == password: + user_data['email'] = user_label['email'] + user_data['nama'] = user_label['nama'] + user_data['kontak'] = user_label['kontak'] + + + # request.session['user_data'] = { + # 'email': email, + # 'nama': user_akun.get('nama', ''), + # 'password': password + # } + + request.session['user_data'] = { + 'email': email, + 'nama': user_akun.get('nama', ''), + 'password': password, + 'is_premium' : is_premium, + 'is_artist' : is_artist, + 'is_songwriter' : is_songwriter , + 'is_podcaster' : is_podcaster, + 'is_label' : is_label + } + + #next -> blm tambahin di views(?) + return HttpResponseRedirect('label/label_dashboard/') + else: + messages.error(request, 'Maaf, password yang Anda masukkan salah.') + #next : ini bisa ditaruh di views.py untuk di app label aja -> buat nampilin semua album yang dimiliki oleh label teresebut + # # Query untuk mencari album milik label + # query_album = f""" + # SELECT * FROM marmut.album + # WHERE id_label = '{user_label['id']}' + # """ + # # Eksekusi query album + # # matching_albums = execute_sql_query(query=query_album) + # if len(matching_albums) == 0: + # messages.info(request, 'Belum Memproduksi Album') + + # Redirect ke halaman dashboard label + + + return render(request, "login.html") + +#khusus pengguna +#next cek dulu ini bener atau ga +@csrf_exempt +def dashboard_view(request): + user_data = request.session.get('user_data') + if not user_data: + messages.error(request, 'Anda harus login terlebih dahulu.') + return render(request, 'login.html') + + playlists = [] + songs = [] + podcasts = [] + + if not user_data.get('is_artist') and not user_data.get('is_podcaster') and not user_data.get('is_songwriter'): + # Jika pengguna bukan artist, podcaster, atau songwriter, maka cari playlistnya + with connection.cursor() as cursor: + cursor.execute("SELECT * FROM marmut.user_playlist WHERE email_pembuat = %s", [user_data['email']]) + playlists = cursor.fetchall() + + if user_data.get('is_artist') or user_data.get('is_songwriter'): + # Jika pengguna adalah artist atau songwriter, maka cari lagu yang dimilikinya + with connection.cursor() as cursor: + cursor.execute("SELECT * FROM marmut.song WHERE id_artist = %s", [user_data['email']]) + songs = cursor.fetchall() + + if user_data.get('is_podcaster'): + # Jika pengguna adalah podcaster, maka cari podcast yang dimilikinya + with connection.cursor() as cursor: + cursor.execute("SELECT * FROM marmut.podcast WHERE email_podcaster = %s", [user_data['email']]) + podcasts = cursor.fetchall() + + context = { + 'user_data': user_data, + 'playlists': playlists, + 'songs': songs, + 'podcasts': podcasts, + } + + return render(request, 'dashboard.html', context) +# @csrf_exempt +# def login_with_postgres(request): +# if request.method == 'POST': +# email = request.POST.get('email') +# password = request.POST.get('password') + +# query = f""" +# SELECT *, +# CASE WHEN EXISTS ( +# SELECT 1 FROM sistel.user u +# INNER JOIN hotel ON u.email = hotel.email +# WHERE u.email = '{email}' +# ) THEN 'false' +# ELSE 'true' END AS is_pengguna +# FROM sistel.user WHERE email = '{email}' +# """ +# matching_users = execute_sql_query(query=query) + +# # print(matching_users) +# if len(matching_users) == 0: +# messages.error(request, 'Pengguna tidak ditemukan.') +# else: +# # print(matching_users) +# selected_user = matching_users[0] +# user_store_password = selected_user[1] +# user_fname = selected_user[2] +# user_lname = selected_user[3] +# is_user = selected_user[4] +# if user_store_password == password: +# request.session['user_data'] = { +# 'email': email, +# 'fname': user_fname, +# 'lname': user_lname, +# 'is_hotel': is_user == 'false' +# } +# print(request.session['user_data']) +# # TODO: ganti redirect ke dashboard +# if is_user == 'false': +# return HttpResponseRedirect('/hotel/dashboard/') +# return HttpResponseRedirect('/reservasi/dashboard/') +# messages.error(request, 'Maaf, password yang kamu masukkan salah.') +# return render(request,"login.html") + + +# def login_view(request): +# if request.method == 'POST': +# form = LoginForm(request.POST) +# if form.is_valid(): +# email = form.cleaned_data['email'] +# password = form.cleaned_data['password'] +# user = authenticate(request, username=email, password=password) +# if user is not None: +# login(request, user) +# # Redirect ke halaman Dashboard sesuai peran pengguna +# if user.is_artist: +# return redirect('artist_dashboard') +# elif user.is_songwriter: +# return redirect('songwriter_dashboard') +# elif user.is_podcaster: +# return redirect('podcaster_dashboard') +# else: +# return redirect('user_dashboard') +# else: +# messages.error(request, 'Email atau password salah.') +# else: +# form = LoginForm() +# return render(request, 'login.html', {'form': form}) diff --git a/label/__init__.py b/label/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/label/admin.py b/label/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/label/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/label/apps.py b/label/apps.py new file mode 100644 index 0000000..e8b8293 --- /dev/null +++ b/label/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class LabelConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "label" diff --git a/label/migrations/__init__.py b/label/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/label/models.py b/label/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/label/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/label/templates/label_dashboard.html b/label/templates/label_dashboard.html new file mode 100644 index 0000000..733133a --- /dev/null +++ b/label/templates/label_dashboard.html @@ -0,0 +1,58 @@ + + + + + + + Dashboard + + + + + + + + + +

Dashboard

+

Informasi Profil Pengguna:

+ +

Nama: kiki

+

Email: email@gmail.com

+ +

Kontak: 435463653

+ +

Role: Label

+ + + + +

Daftar Album

+

Belum memiliki album.

+ + + + diff --git a/label/templates/style2.css b/label/templates/style2.css new file mode 100644 index 0000000..02428fe --- /dev/null +++ b/label/templates/style2.css @@ -0,0 +1,63 @@ +/* CSS untuk style2.css */ + +body { + margin: 0; + font-family: Arial, sans-serif; +} + +.navbar { + background-color:#007bff; + overflow: hidden; +} + +.navbar ul { + list-style-type: none; + margin: 0; + padding: 0; +} + +.navbar li { + float: left; +} + +.navbar li a { + display: block; + color: white; + text-align: center; + padding: 14px 16px; + text-decoration: none; +} + +.navbar li a:hover { + background-color: #007bff; +} + +.navbar .search-bar { + margin-left: auto; +} + +.navbar form { + display: flex; + align-items: center; +} + +.navbar input[type="search"] { + padding: 8px; + border: none; + border-radius: 5px 0 0 5px; + margin-right: 0; + background-color: #fff; /* Tambahkan warna latar belakang */ +} + +.navbar button[type="submit"] { + padding: 8px 12px; + background-color: #007bff; + color: white; + border: none; + border-radius: 0 5px 5px 0; + cursor: pointer; +} + +.navbar button[type="submit"]:hover { + background-color: #007bff; +} diff --git a/label/tests.py b/label/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/label/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/label/views.py b/label/views.py new file mode 100644 index 0000000..47cdda0 --- /dev/null +++ b/label/views.py @@ -0,0 +1,6 @@ +from django.shortcuts import render + +# Create your views here. + + +#buat view untuk nampilin album yang dipunya label \ No newline at end of file diff --git a/pengguna_biasa/__init__.py b/pengguna_biasa/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pengguna_biasa/admin.py b/pengguna_biasa/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/pengguna_biasa/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/pengguna_biasa/apps.py b/pengguna_biasa/apps.py new file mode 100644 index 0000000..ce297d2 --- /dev/null +++ b/pengguna_biasa/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class PenggunaBiasaConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "pengguna_biasa" diff --git a/pengguna_biasa/migrations/__init__.py b/pengguna_biasa/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pengguna_biasa/models.py b/pengguna_biasa/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/pengguna_biasa/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/pengguna_biasa/tests.py b/pengguna_biasa/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/pengguna_biasa/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/pengguna_biasa/views.py b/pengguna_biasa/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/pengguna_biasa/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/podcaster/__init__.py b/podcaster/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/podcaster/admin.py b/podcaster/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/podcaster/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/podcaster/apps.py b/podcaster/apps.py new file mode 100644 index 0000000..b678adf --- /dev/null +++ b/podcaster/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class PodcasterConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "podcaster" diff --git a/podcaster/migrations/__init__.py b/podcaster/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/podcaster/models.py b/podcaster/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/podcaster/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/podcaster/tests.py b/podcaster/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/podcaster/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/podcaster/views.py b/podcaster/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/podcaster/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..fd33223 --- /dev/null +++ b/templates/base.html @@ -0,0 +1,12 @@ + + {% block meta %} + + + {% endblock meta %} + + + + + + + \ No newline at end of file diff --git a/templates/nav.html b/templates/nav.html new file mode 100644 index 0000000..e12cb4b --- /dev/null +++ b/templates/nav.html @@ -0,0 +1,70 @@ + + + From 235d27dc6a008756e33d623903de0473d9df1a17 Mon Sep 17 00:00:00 2001 From: saras355 Date: Tue, 14 May 2024 21:20:40 +0700 Subject: [PATCH 02/13] dah connect db, ada login register --- akun/templates/dashboard.html | 12 + akun/templates/list_tables.html | 14 + akun/templates/login.html | 34 ++ akun/templates/register_choice.html | 19 ++ akun/templates/register_label.html | 38 +++ akun/templates/register_pengguna.html | 68 ++++ akun/urls.py | 17 + akun/views.py | 320 +++++++++++++++++- album_song_royalti/templates/cek_royalti.html | 5 +- .../templates/kelola_album_song.html | 6 +- auth/templates/dashboard.html | 97 ------ auth/templates/dashboard_untuk_tk3.html | 59 +++- auth/templates/home.html | 2 +- auth/templates/home_untuk_tk3.html | 3 +- auth/urls.py | 10 +- auth/views.py | 6 + connect_postgress.py | 0 templates/nav.html | 4 +- tk_basdat/settings.py | 32 +- tk_basdat/urls.py | 7 +- 20 files changed, 635 insertions(+), 118 deletions(-) create mode 100644 akun/templates/dashboard.html create mode 100644 akun/templates/list_tables.html create mode 100644 akun/templates/login.html create mode 100644 akun/templates/register_choice.html create mode 100644 akun/templates/register_label.html create mode 100644 akun/templates/register_pengguna.html create mode 100644 akun/urls.py create mode 100644 connect_postgress.py diff --git a/akun/templates/dashboard.html b/akun/templates/dashboard.html new file mode 100644 index 0000000..e1a9939 --- /dev/null +++ b/akun/templates/dashboard.html @@ -0,0 +1,12 @@ + + + + + Dashboard + + +

Selamat Datang di Dashboard

+

Halo, {{ request.session.user_data.nama }}!

+ + + diff --git a/akun/templates/list_tables.html b/akun/templates/list_tables.html new file mode 100644 index 0000000..98a90cd --- /dev/null +++ b/akun/templates/list_tables.html @@ -0,0 +1,14 @@ + + + + List of Tables + + +

Tables in Database

+ + + diff --git a/akun/templates/login.html b/akun/templates/login.html new file mode 100644 index 0000000..80f623a --- /dev/null +++ b/akun/templates/login.html @@ -0,0 +1,34 @@ + + + + + + Form Login + + + + + +
+
+
+

FORM LOGIN

+
+ {% csrf_token %} +
+ + +
+
+ + +
+ +
+
+
+
+ + + + diff --git a/akun/templates/register_choice.html b/akun/templates/register_choice.html new file mode 100644 index 0000000..ba43b0b --- /dev/null +++ b/akun/templates/register_choice.html @@ -0,0 +1,19 @@ + {% include 'nav.html' %} + + + + + + + Pilihan Registrasi + + +

Pilihan Registrasi

+

Silakan pilih peran Anda:

+ + + + diff --git a/akun/templates/register_label.html b/akun/templates/register_label.html new file mode 100644 index 0000000..0f45a10 --- /dev/null +++ b/akun/templates/register_label.html @@ -0,0 +1,38 @@ + + + + + + Register Label + + + +
+
+
+

Register Label

+
+ {% csrf_token %} +
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+
+ + diff --git a/akun/templates/register_pengguna.html b/akun/templates/register_pengguna.html new file mode 100644 index 0000000..4eecafc --- /dev/null +++ b/akun/templates/register_pengguna.html @@ -0,0 +1,68 @@ + + + + + + Register Pengguna + + + +
+
+
+

Register Pengguna

+
+ {% csrf_token %} +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
+ + diff --git a/akun/urls.py b/akun/urls.py new file mode 100644 index 0000000..c97ea3d --- /dev/null +++ b/akun/urls.py @@ -0,0 +1,17 @@ +from django.urls import path +from .views import * +app_name = 'akun' + + +urlpatterns = [ + path('list_tables/', list_tables, name='list_tables'), + # path('register/', register_with_postgres, name='register' ), + path('login/', login_with_postgres, name='login' ), + path('register_choice/', register_choice, name='register_choice'), + # path('register_pengguna//', register_pengguna, name='register'), + # path('logout/', logout_with_postgres, name='logout'), + # path('dashboard/', dashboard, name='dashboard'), + path('dashboard/', dashboard, name='dashboard'), + path('register/pengguna/', register_pengguna, name='register_pengguna'), + path('register/label/', register_label, name='register_label'), +] \ No newline at end of file diff --git a/akun/views.py b/akun/views.py index 91ea44a..a852466 100644 --- a/akun/views.py +++ b/akun/views.py @@ -1,3 +1,321 @@ from django.shortcuts import render - +from django.shortcuts import render, redirect +from django.contrib.auth import authenticate, login +from django.contrib import messages +# from .forms import LoginForm -> ga usah pakai form langsung dari login.html aja(?) +import json +from django.db import connection +# from connect_postgres import execute_sql_query +from django.shortcuts import render, redirect +from django.contrib.auth.decorators import login_required +from django.http import JsonResponse,HttpResponseRedirect +import datetime +import uuid +from django.views.decorators.csrf import csrf_exempt +from django.contrib import messages +from django.contrib.auth.hashers import check_password +from django.urls import reverse +import psycopg2 +from django.shortcuts import render, redirect +from django.contrib import messages +from django.db import connection # Create your views here. +def list_tables(request): + with connection.cursor() as cursor: + cursor.execute("SELECT table_name FROM information_schema.tables WHERE table_schema = 'marmut';") + tables = cursor.fetchall() + table_list = [table[0] for table in tables] # Extract table names from tuples + return render(request, 'list_tables.html', {'tables': table_list}) + +# def list_tables(request): +# # with connection.cursor() as cursor: +# # cursor.execute("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';") +# # tables = cursor.fetchall() +# # table_list = [table[0] for table in tables] # Extract table names from tuples +# return render(request, 'akun/list_tables.html') + + +#membuat untuk views dashboard terlebih dahulu + +@login_required +def dashboard(request): + # Anda bisa menambahkan logika di sini untuk mengambil data yang diperlukan untuk dashboard + #next ini bisa ditambahkan logika apa role dari pengguna tersebut , atau mungkin bisa di dahsbroad htmlnya sendiri kita pakai untuk variabel yang ada. + return render(request, 'dashboard.html') + +#loginnn + + + +@csrf_exempt +def login_with_postgres(request): + is_premium = False + is_artist = False + is_songwriter = False + is_podcaster = False + is_label = False + + if request.method == 'POST': + email = request.POST.get('email') + password = request.POST.get('password') + + # Query untuk mencari pengguna berdasarkan email di tabel akun + query_akun = f""" + SELECT * FROM marmut.akun WHERE email = '{email}' + """ + + with connection.cursor() as cursor: + cursor.execute(query_akun) + columns = [col[0] for col in cursor.description] + matching_users_akun = [dict(zip(columns, row)) for row in cursor.fetchall()] + + if matching_users_akun: + user_akun = matching_users_akun[0] + if user_akun['password'] == password: + # Set user data in session + request.session['user_data'] = { + 'email': user_akun['email'], + 'nama': user_akun.get('nama', ''), + 'password': password, + 'is_premium': is_premium, + 'is_artist': is_artist, + 'is_songwriter': is_songwriter, + 'is_podcaster': is_podcaster, + 'is_label': is_label + } + return render(request, 'dashboard.html') + else: + messages.error(request, 'Maaf, password yang Anda masukkan salah.') + else: + messages.error(request, 'Pengguna tidak ditemukan.') + + return render(request, "login.html") + + +#BATASSSSSSSSSSSSSSSSS +#syarat untuk login unik akunnya +# @csrf_exempt +# def login_with_postgres(request): +# is_premium = False +# is_artist = False +# is_songwriter = False +# is_podcaster = False +# is_label = False + +# matching_users_akun = 0 + +# if request.method == 'POST': +# email = request.POST.get('email') +# password = request.POST.get('password') + +# # Query untuk mencari pengguna berdasarkan email di tabel akun +# query_akun = f""" +# SELECT *, +# CASE WHEN EXISTS ( +# SELECT 1 FROM marmut.akun u +# WHERE u.email = '{email}' +# ) THEN 'true' +# ELSE 'false' END AS is_user +# FROM marmut.akun WHERE email = '{email}' +# """ + +# #cursor.execute +# with connection.cursor() as cursor: +# cursor.execute(query_akun) +# matching_users_akun = cursor.fetchall() + +# if matching_users_akun : +# return render(request, "dashboard.html") + +# #matching_users_akun kalau ada +# # print("match: " + matching_users_akun) +# #batas batas +# # if len(matching_users_akun) == 0 and len(matching_users_label) == 0: +# # # Jika email tidak ditemukan di kedua tabel +# # messages.error(request, 'Pengguna tidak ditemukan.') +# # else: +# # # Jika email ditemukan di salah satu atau kedua tabel +# # user_data = {} + +# # if len(matching_users_akun) > 0: +# # # Jika pengguna ada di tabel akun +# # user_akun = matching_users_akun[0] +# # if user_akun['password'] == password: +# # # Jika password sesuai, ambil informasi pengguna dari tabel akun +# # user_data['email'] = user_akun['email'] +# # user_data['nama'] = user_akun['nama'] +# # user_data['kota_asal'] = user_akun['kota_asal'] +# # user_data['gender'] = user_akun['gender'] +# # user_data['tempat_lahir'] = user_akun['tempat_lahir'] +# # user_data['tanggal_lahir'] = user_akun['tanggal_lahir'] + + +# # roles = [] +# # # Cek role pengguna +# # # Cek apakah email pengguna ada di tabel Premium +# # query_premium = f""" +# # SELECT * FROM marmut.premium +# # WHERE email = '{user_akun['email']}' +# # """ +# # matching_premium = execute_sql_query(query=query_premium) +# # if len(matching_premium) > 0: +# # roles.append('Premium') +# # is_premium = True + +# # # Cek apakah email pengguna ada di tabel Artist +# # query_artist = f""" +# # SELECT * FROM marmut.artist +# # WHERE email = '{user_akun['email']}' +# # """ +# # matching_artist = execute_sql_query(query=query_artist) +# # if len(matching_artist) > 0: +# # roles.append('Artist') +# # is_artist = True + +# # # Cek apakah email pengguna ada di tabel Songwriter +# # query_songwriter = f""" +# # SELECT * FROM marmut.songwriter +# # WHERE email = '{user_akun['email']}' +# # """ +# # matching_songwriter = execute_sql_query(query=query_songwriter) +# # if len(matching_songwriter) > 0: +# # roles.append('Songwriter') +# # is_songwriter = True + +# # # Cek apakah email pengguna ada di tabel Podcaster +# # query_podcaster = f""" +# # SELECT * FROM marmut.podcaster +# # WHERE email = '{user_akun['email']}' +# # """ +# # matching_podcaster = execute_sql_query(query=query_podcaster) +# # if len(matching_podcaster) > 0: +# # roles.append('Podcaster') +# # is_podcaster = True + + +# # user_data['role'] = ', '.join(roles) +# # #berarti pengguna biasa ga ada is_pengguna biasa tapi cek aja is dari tiap role +# # request.session['user_data'] = { +# # 'email': email, +# # 'nama': user_akun.get('nama', ''), +# # 'password': password, +# # 'is_premium' : is_premium, +# # 'is_artist' : is_artist, +# # 'is_songwriter' : is_songwriter , +# # 'is_podcaster' : is_podcaster, +# # 'is_label' : is_label +# # } + +# # # Redirect ke halaman dashboard pengguna +# # return HttpResponseRedirect('/dashboard/') +# # else: +# # messages.error(request, 'Maaf, password yang Anda masukkan salah.') + +# # if len(matching_users_label) > 0: +# # # Jika pengguna ada di tabel label +# # user_label = matching_users_label[0] +# # # Ambil informasi pengguna dari tabel label +# # if user_label['password'] == password: +# # user_data['email'] = user_label['email'] +# # user_data['nama'] = user_label['nama'] +# # user_data['kontak'] = user_label['kontak'] + + +# # # request.session['user_data'] = { +# # # 'email': email, +# # # 'nama': user_akun.get('nama', ''), +# # # 'password': password +# # # } + +# # request.session['user_data'] = { +# # 'email': email, +# # 'nama': user_akun.get('nama', ''), +# # 'password': password, +# # 'is_premium' : is_premium, +# # 'is_artist' : is_artist, +# # 'is_songwriter' : is_songwriter , +# # 'is_podcaster' : is_podcaster, +# # 'is_label' : is_label +# # } + +# # #next -> blm tambahin di views(?) +# # return HttpResponseRedirect('label/label_dashboard/') +# # else: +# # messages.error(request, 'Maaf, password yang Anda masukkan salah.') +# # #next : ini bisa ditaruh di views.py untuk di app label aja -> buat nampilin semua album yang dimiliki oleh label teresebut +# # # # Query untuk mencari album milik label +# # # query_album = f""" +# # # SELECT * FROM marmut.album +# # # WHERE id_label = '{user_label['id']}' +# # # """ +# # # # Eksekusi query album +# # # # matching_albums = execute_sql_query(query=query_album) +# # # if len(matching_albums) == 0: +# # # messages.info(request, 'Belum Memproduksi Album') + +# # # Redirect ke halaman dashboard label + + +# return render(request, "login.html") +#BATASSSSSSSSSSSSSS + + +#register yang dasar +def register_choice(request): + return render(request, 'register_choice.html') + +#register label +def register_label(request): + if request.method == 'POST': + email = request.POST.get('email') + password = request.POST.get('password') + nama = request.POST.get('nama') + kontak = request.POST.get('kontak') + + with connection.cursor() as cursor: + cursor.execute(""" + INSERT INTO marmut.label (email, password, nama, kontak) + VALUES (%s, %s, %s, %s) + """, [email, password, nama, kontak]) + + return redirect('login') # Ubah 'login' sesuai dengan nama URL untuk halaman login + + return render(request, 'register_label.html') + +#register pengguna +@csrf_exempt +def register_pengguna(request): + if request.method == 'POST': + # SAMA --------------------------- + email = request.POST.get('email') + password = request.POST.get('password') + nama = request.POST.get('nama') + gender = request.POST.get('gender') + tempat_lahir = request.POST.get('tempat_lahir') + tanggal_lahir = request.POST.get('tanggal_lahir') + kota_asal = request.POST.get('kota_asal') + roles = request.POST.getlist('role') + is_verified = True + + #next : mungkin nanti baru ada triggernya + #kalau ga ada role yang dipilih + if not roles: + #maka akan dibuat akund enagn status unverfied + #dan dikategorikan sebagai pengguna biasa + #langsung add ke database dulu + is_verified = False + with connection.cursor() as cursor: + #next perlu distrip ga ya? + cursor.execute(""" + INSERT INTO marmut.akun (email, password, nama, gender, tempat_lahir, tanggal_lahir, is_verified, kota_asal) + VALUES (%s, %s, %s, %s, %s, %s, %s, %s) + """, [email, password, nama, gender, tempat_lahir, tanggal_lahir, is_verified, kota_asal]) + + + + return HttpResponseRedirect('/login/') + # except psycopg2.Error as error: + # messages.error(request, f'{error}') + # except Exception as error: + # messages.error(request, f'{error}') + return render(request, 'register_pengguna.html') diff --git a/album_song_royalti/templates/cek_royalti.html b/album_song_royalti/templates/cek_royalti.html index cf07b92..be7c36d 100644 --- a/album_song_royalti/templates/cek_royalti.html +++ b/album_song_royalti/templates/cek_royalti.html @@ -13,14 +13,15 @@
  • Dashboard
  • Chart
  • +
  • Search Bar -
  • Kelola Playlist
  • Langganan Paket
  • diff --git a/album_song_royalti/templates/kelola_album_song.html b/album_song_royalti/templates/kelola_album_song.html index a962cae..c7b3275 100644 --- a/album_song_royalti/templates/kelola_album_song.html +++ b/album_song_royalti/templates/kelola_album_song.html @@ -2,13 +2,15 @@
    • Dashboard
    • Chart
    • -
    • Search Bar
    • + +
    • Kelola Playlist
    • diff --git a/auth/templates/dashboard.html b/auth/templates/dashboard.html index f7550f7..e69de29 100644 --- a/auth/templates/dashboard.html +++ b/auth/templates/dashboard.html @@ -1,97 +0,0 @@ - - -{% extends 'base.html' %} - - -

      Dashboard

      -

      Informasi Profil Pengguna:

      -

      Nama: {{ user_data.nama }}

      -

      Email: {{ user_data.email }}

      - {% if user_data.kota_asal %} -

      Kota Asal: {{ user_data.kota_asal }}

      - {% endif %} - {% if user_data.gender %} -

      Gender: {{ user_data.gender }}

      - {% endif %} - {% if user_data.tempat_lahir %} -

      Tempat Lahir: {{ user_data.tempat_lahir }}

      - {% endif %} - {% if user_data.tanggal_lahir %} -

      Tanggal Lahir: {{ user_data.tanggal_lahir }}

      - {% endif %} - {% if user_data.role %} -

      Role: {{ user_data.role }}

      - {% endif %} - - - - - {% if not user_data.is_artist and not user_data.is_podcaster and not user_data.is_songwriter %} - - {% if playlists %} -

      Daftar Playlist

      -
        - {% for playlist in playlists %} -
      • {{ playlist.nama }}
      • - {% endfor %} -
      - {% else %} -

      Belum memiliki playlist.

      - {% endif %} - {% endif %} - - - {% if user_data.is_artist or user_data.is_songwriter %} - - {% if songs %} -

      Daftar Lagu

      -
        - {% for song in songs %} -
      • {{ song.judul }}
      • - {% endfor %} -
      - {% else %} -

      Belum memiliki lagu.

      - {% endif %} - {% endif %} - - - {% if user_data.is_podcaster %} - - {% if podcasts %} -

      Daftar Podcast

      -
        - {% for podcast in podcasts %} -
      • {{ podcast.judul }}
      • - {% endfor %} -
      - {% else %} -

      Belum memiliki podcast.

      - {% endif %} - {% endif %} - - - - - - - \ No newline at end of file diff --git a/auth/templates/dashboard_untuk_tk3.html b/auth/templates/dashboard_untuk_tk3.html index bf3ed7c..09a51e4 100644 --- a/auth/templates/dashboard_untuk_tk3.html +++ b/auth/templates/dashboard_untuk_tk3.html @@ -13,12 +13,13 @@
      • Dashboard
      • Chart
      • -
      • Search Bar
      • +
      • Kelola Playlist
      • Langganan Paket
      • Kelola Podcast
      • @@ -55,3 +56,57 @@

        Daftar Podcast

        Belum memiliki lagu.

        + + + + + + + + + \ No newline at end of file diff --git a/auth/templates/home.html b/auth/templates/home.html index 6593d21..d760eec 100644 --- a/auth/templates/home.html +++ b/auth/templates/home.html @@ -6,7 +6,7 @@
        -

        Marmut - KODE KELOMPOK

        +

        Marmut - 1

        diff --git a/auth/templates/home_untuk_tk3.html b/auth/templates/home_untuk_tk3.html index b2464d6..813f69b 100644 --- a/auth/templates/home_untuk_tk3.html +++ b/auth/templates/home_untuk_tk3.html @@ -14,7 +14,7 @@
        -

        Marmut - 1

        +

        Marmut - A_1

        @@ -24,5 +24,6 @@

        Marmut - 1

        + diff --git a/auth/urls.py b/auth/urls.py index e5d2102..dc78909 100644 --- a/auth/urls.py +++ b/auth/urls.py @@ -4,9 +4,9 @@ urlpatterns = [ - path('', show_home, name='home'), - path('register/', register_with_postgres, name='register' ), - path('login/', login_with_postgres, name='login' ), - path('logout/', logout_with_postgres, name='logout'), - path('dashboard/', dashboard_view, name='dashboard'), + # path('', list_tables, name='list_tables'), + # path('register/', register_with_postgres, name='register' ), + # path('login/', login_with_postgres, name='login' ), + # path('logout/', logout_with_postgres, name='logout'), + # path('dashboard/', dashboard_view, name='dashboard'), ] \ No newline at end of file diff --git a/auth/views.py b/auth/views.py index 51b66aa..e488112 100644 --- a/auth/views.py +++ b/auth/views.py @@ -25,6 +25,12 @@ def show_login(request): return render(request, "login.html") #next blm ganti +def list_tables(request): + with connection.cursor() as cursor: + cursor.execute("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';") + tables = cursor.fetchall() + table_list = [table[0] for table in tables] # Extract table names from tuples + return render(request, ''auth/list_tables.html'', {'tables': table_list}) @csrf_exempt def logout_with_postgres(request): diff --git a/connect_postgress.py b/connect_postgress.py new file mode 100644 index 0000000..e69de29 diff --git a/templates/nav.html b/templates/nav.html index e12cb4b..3df0f5e 100644 --- a/templates/nav.html +++ b/templates/nav.html @@ -11,10 +11,10 @@ {% if not is_logged_in %} {% else %} diff --git a/tk_basdat/settings.py b/tk_basdat/settings.py index fb37926..22d619b 100644 --- a/tk_basdat/settings.py +++ b/tk_basdat/settings.py @@ -10,8 +10,11 @@ https://docs.djangoproject.com/en/5.0/ref/settings/ """ +import os from pathlib import Path +import akun + # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -37,6 +40,14 @@ "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", + "akun", + # "auth", + "album_song_royalti", + "artist_songwriter", + "label", + "main", + "pengguna_biasa", + "podcaster" ] MIDDLEWARE = [ @@ -54,7 +65,10 @@ TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", - "DIRS": [], + 'DIRS': [ + os.path.join(BASE_DIR, "templates"), # Tambahkan direktori template root proyek + os.path.join(BASE_DIR, "akun", "templates"), # Tambahkan direktori template dari aplikasi 'akun' + ], "APP_DIRS": True, "OPTIONS": { "context_processors": [ @@ -73,10 +87,20 @@ # Database # https://docs.djangoproject.com/en/5.0/ref/settings/#databases +# DATABASES = { +# "default": { +# "ENGINE": "django.db.backends.sqlite3", +# "NAME": BASE_DIR / "db.sqlite3", +# } +# } DATABASES = { - "default": { - "ENGINE": "django.db.backends.sqlite3", - "NAME": BASE_DIR / "db.sqlite3", + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': 'postgres', + 'USER': 'postgres.wjvkpituiyaewdobydxl', + 'PASSWORD': 'Marmut123_?', + 'HOST': 'aws-0-ap-southeast-1.pooler.supabase.com', + 'PORT': '5432', } } diff --git a/tk_basdat/urls.py b/tk_basdat/urls.py index f08743e..ca82ddd 100644 --- a/tk_basdat/urls.py +++ b/tk_basdat/urls.py @@ -15,8 +15,13 @@ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path +from django.urls import path, include + +from akun.views import list_tables urlpatterns = [ + # path("admin/", admin.site.urls), + # path('auth/', include('auth.urls')), path("admin/", admin.site.urls), + path('', include('akun.urls')), ] From 74e339f1ab35ecc1b612e35a918dd47e2ca531df Mon Sep 17 00:00:00 2001 From: saras355 Date: Wed, 15 May 2024 21:25:33 +0700 Subject: [PATCH 03/13] tes readme --- README.md | 6 +- akun/templates/home.html | 23 ++++++++ akun/templates/register_label.html | 3 + akun/templates/register_pengguna.html | 2 + akun/views.py | 80 ++++++++++++++++++++++++++- tk_basdat/urls.py | 4 +- 6 files changed, 109 insertions(+), 9 deletions(-) create mode 100644 akun/templates/home.html diff --git a/README.md b/README.md index 64e5927..eab5cee 100644 --- a/README.md +++ b/README.md @@ -1,5 +1 @@ -Nama : Kevin Ivan Eda Radhiyya - -NPM : 2201233210 - -Kelas : PBP B \ No newline at end of file +Ubah \ No newline at end of file diff --git a/akun/templates/home.html b/akun/templates/home.html new file mode 100644 index 0000000..dab8ebd --- /dev/null +++ b/akun/templates/home.html @@ -0,0 +1,23 @@ + + + + + + Marmut + + + + +
        +

        Marmut - 1

        +
        + Login + Register +
        +
        + + + + + + diff --git a/akun/templates/register_label.html b/akun/templates/register_label.html index 0f45a10..9275c17 100644 --- a/akun/templates/register_label.html +++ b/akun/templates/register_label.html @@ -1,4 +1,7 @@ + +{% include 'nav.html' %} + diff --git a/akun/templates/register_pengguna.html b/akun/templates/register_pengguna.html index 4eecafc..f4bd0cd 100644 --- a/akun/templates/register_pengguna.html +++ b/akun/templates/register_pengguna.html @@ -1,4 +1,6 @@ +{% include 'nav.html' %} + diff --git a/akun/views.py b/akun/views.py index a852466..09032ef 100644 --- a/akun/views.py +++ b/akun/views.py @@ -2,6 +2,7 @@ from django.shortcuts import render, redirect from django.contrib.auth import authenticate, login from django.contrib import messages +import uuid # from .forms import LoginForm -> ga usah pakai form langsung dari login.html aja(?) import json from django.db import connection @@ -259,6 +260,9 @@ def login_with_postgres(request): # return render(request, "login.html") #BATASSSSSSSSSSSSSS +#show_home +def home(request): + return render(request, 'home.html') #register yang dasar def register_choice(request): @@ -286,7 +290,6 @@ def register_label(request): @csrf_exempt def register_pengguna(request): if request.method == 'POST': - # SAMA --------------------------- email = request.POST.get('email') password = request.POST.get('password') nama = request.POST.get('nama') @@ -296,7 +299,7 @@ def register_pengguna(request): kota_asal = request.POST.get('kota_asal') roles = request.POST.getlist('role') is_verified = True - + #next : mungkin nanti baru ada triggernya #kalau ga ada role yang dipilih if not roles: @@ -311,8 +314,79 @@ def register_pengguna(request): VALUES (%s, %s, %s, %s, %s, %s, %s, %s) """, [email, password, nama, gender, tempat_lahir, tanggal_lahir, is_verified, kota_asal]) + #tambahkan di table masing masing role + #tambahkan jika podcaster + if 'podcaster' in roles: + #attribut hanya email saja + #karena sudah ada emailnya di table akun, harusnya emailnya bisa langsung tanpa perlu fk lagi + with connection.cursor() as cursor: + cursor.execute(""" + INSERT INTO marmut.podcaster (email) + VALUES (%s) + """, [email]) + + #tambahkan jika artist + #note kalau FK berarti data tersebut harus ada di tabel yang di FKan terlebih dahulu + #jadi asumsinya sudah ada + #attributnya ada id dari UUID PK + #ada email_akun yang FK ke AKUN.email + #ada id_pemilik_hak_cipta dengan tipe data UUID , yang FK ke pemilik_hak_cipta.id + + #next harusnya bisa -> tanyain -> krn pemilik hak cipta kan dibuat independen + if 'artist' in roles: + artist_id = uuid.uuid4() + cursor.execute("""SELECT * FROM marmut.akun WHERE email = %s LIMIT 1;""", [email]) + email_akun = cursor.fetchall() + #ambil email dari table akun + email_akun = email_akun[0][0] #NEXT + #ambil id dari table pemilik hak cipta + cursor.execute(""" SELECT DISTINCT r.id_pemilik_hak_cipta + FROM song s + JOIN royalti r ON s.id_konten = r.id_song + WHERE s.id_artist = %s;""", [artist_id]) + id_pemilik_hak_cipta = cursor.fetchall() + + #masukkan ke table artist + query_insert_artist = """ + INSERT INTO marmut.artist (id, email_akun, id_pemilik_hak_cipta) + VALUES (%s, %s, %s) + """ + cursor.execute(query_insert_artist, (artist_id, email_akun, id_pemilik_hak_cipta)) + + + #cek di dataset apakah ada orang yang id song writernya sama dengan id artist + #tapi ada kemungkinan kalau satu orang kan bisa jadi artist dan bisa jadi songwriter harusnya saling berbagi id? + #cek dataset -> + #pakai + # SELECT * FROM ARTIST WHERE ARTIST.id in (SELECT id FROM SONGWRITER); -> idnya ga ada yg sama antara di kedua table itu + # SELECT * FROM ARTIST WHERE ARTIST.email_akun in (SELECT email_akun FROM SONGWRITER); -> tapiii ada email yang sama + #asumsi: ini berarti untuk satu orangyag rolenya bisa artist dan songwriter maka idnya berbeda, tetapi email_akunnya boleh sama + + #tambahkan jika songwriter + if 'songwriter' in roles: + songwriter_id = uuid.uuid4() + cursor.execute("""SELECT * FROM marmut.akun WHERE email = %s LIMIT 1;""", [email]) + email_akun = cursor.fetchall() + #ambil email dari table akun + email_akun = email_akun[0][0] #NEXT + #ambil id pemilik hak cipta -> ambil dari songwriter_write_song dulu baru dapat id_songnya + query = """ + SELECT DISTINCT r.id_pemilik_hak_cipta + FROM songwriter_write_song sws + JOIN song s ON sws.id_song = s.id_konten + JOIN royalti r ON s.id_konten = r.id_song + WHERE sws.id_songwriter = %s + """ + cursor.execute(query, (artist_id,)) + id_pemilik_hak_cipta = cursor.fetchone() + + #masukkan ke table artist + query_insert_artist = """ + INSERT INTO marmut.songwriter (id, email_akun, id_pemilik_hak_cipta) + VALUES (%s, %s, %s) + """ + cursor.execute(query_insert_artist, (songwriter_id, email_akun, id_pemilik_hak_cipta)) - return HttpResponseRedirect('/login/') # except psycopg2.Error as error: # messages.error(request, f'{error}') diff --git a/tk_basdat/urls.py b/tk_basdat/urls.py index ca82ddd..9afcc77 100644 --- a/tk_basdat/urls.py +++ b/tk_basdat/urls.py @@ -16,6 +16,7 @@ """ from django.contrib import admin from django.urls import path, include +from akun import views as akun_views from akun.views import list_tables @@ -23,5 +24,6 @@ # path("admin/", admin.site.urls), # path('auth/', include('auth.urls')), path("admin/", admin.site.urls), - path('', include('akun.urls')), + path('akun/', include('akun.urls')), + path('', akun_views.home, name='home'), ] From 5fcc0364edf602ead2badb27dec76fd2f384f85d Mon Sep 17 00:00:00 2001 From: saras355 Date: Fri, 17 May 2024 15:05:18 +0700 Subject: [PATCH 04/13] login bener --- akun/templates/dashboard.html | 99 ++- akun/urls.py | 1 + akun/views.py | 663 ++++++++++++-- album_song_royalti/bener.py | 109 +++ album_song_royalti/create_album.py | 119 +++ album_song_royalti/simpen_cek_royalti.py | 39 + album_song_royalti/templates/cek_royalti.html | 89 +- .../templates/create_album.html | 68 ++ album_song_royalti/templates/create_lagu.html | 59 ++ album_song_royalti/templates/daftar_lagu.html | 37 + .../entry_album_song_create_list.html | 28 + .../templates/lihat_detail_lagu.html | 39 + album_song_royalti/templates/list_album.html | 36 + .../templates/list_album_artist.html | 76 ++ album_song_royalti/templates/list_lagu.html | 41 + .../templates/multiselect_form.html | 18 + album_song_royalti/tes.py | 6 + album_song_royalti/tes_multi.html | 19 + album_song_royalti/ubah_format.py | 7 + album_song_royalti/urls.py | 32 + album_song_royalti/views.py | 827 ++++++++++++++++++ auth/views.py | 822 ++++++++--------- requirements.txt | 2 +- templates/nav.html | 89 +- tk_basdat/settings.py | 25 +- tk_basdat/trigger.sql | 267 ++++++ tk_basdat/urls.py | 4 +- 27 files changed, 3043 insertions(+), 578 deletions(-) create mode 100644 album_song_royalti/bener.py create mode 100644 album_song_royalti/create_album.py create mode 100644 album_song_royalti/simpen_cek_royalti.py create mode 100644 album_song_royalti/templates/create_album.html create mode 100644 album_song_royalti/templates/create_lagu.html create mode 100644 album_song_royalti/templates/daftar_lagu.html create mode 100644 album_song_royalti/templates/entry_album_song_create_list.html create mode 100644 album_song_royalti/templates/lihat_detail_lagu.html create mode 100644 album_song_royalti/templates/list_album.html create mode 100644 album_song_royalti/templates/list_album_artist.html create mode 100644 album_song_royalti/templates/list_lagu.html create mode 100644 album_song_royalti/templates/multiselect_form.html create mode 100644 album_song_royalti/tes.py create mode 100644 album_song_royalti/tes_multi.html create mode 100644 album_song_royalti/ubah_format.py create mode 100644 album_song_royalti/urls.py create mode 100644 tk_basdat/trigger.sql diff --git a/akun/templates/dashboard.html b/akun/templates/dashboard.html index e1a9939..a689553 100644 --- a/akun/templates/dashboard.html +++ b/akun/templates/dashboard.html @@ -1,12 +1,105 @@ + {% include 'nav.html' %} + + Dashboard + -

        Selamat Datang di Dashboard

        -

        Halo, {{ request.session.user_data.nama }}!

        - +

        Dashboard

        +

        Informasi Profil Pengguna

        +
          +
        • Nama: {{ request.session.user_data.nama }}
        • +
        • Email: {{ request.session.user_data.email }}
        • + + {% if not request.session.user_data.is_label %} + {% if request.session.user_data.is_premium %} +
        • Status Langganan: Premium
        • + {% else %} +
        • Status Langganan: Non Premium
        • + {% endif %} + {% endif %} + + + {% if request.session.user_data.is_label%} + +
        • Kontak: {{user_data.kontak }}
        • + {% endif %} + + {% if not request.session.user_data.is_label%} +
        • Kota Asal: {{ user_data.kota_asal }}
        • + {% if request.session.user_data.gender == 0 %} +
        • Gender: Perempuan
        • + {% else %} +
        • Gender: Laki-laki
        • + {% endif%} +
        • Tempat Lahir: {{ user_data.tempat_lahir }}
        • +
        • Tanggal Lahir: {{ user_data.tanggal_lahir }}
        • + {% endif %} + {% if request.session.user_data.roles %} +
        • Role: + {% for role in request.session.user_data.roles %} + {% if not forloop.first %}, {% endif %} + {{ role }} + {% endfor %} +
        • + {% endif %} + + + {% if not request.session.user_data.is_label and not request.session.user_data.is_artist and not request.session.user_data.is_songwriter and not request.session.user_data.is_podcaster %} + {% if playlists %} +

          Daftar Playlist

          +
            + {% for playlist in playlists %} +
          • {{ playlist }}
          • + {% endfor %} +
          + {% else %} +

          Belum Memiliki Playlist

          + {% endif %} + {% endif %} + + {% if request.session.user_data.is_artist or request.session.user_data.is_songwriter and not request.session.user_data.is_podcaster%} + {% if songs %} +

          Daftar Lagu

          +
            + {% for song in songs %} +
          • {{ song }}
          • + {% endfor %} +
          + {% else %} +

          Belum Memiliki Lagu

          + {% endif %} + + {% endif %} + + {% if request.session.user_data.is_podcaster %} + {% if podcasts %} +

          Daftar Podcast

          +
            + {% for podcast in podcasts %} +
          • {{ podcast }}
          • + {% endfor %} +
          + {% else %} +

          Belum Memiliki Podcast

          + {% endif %} + {% endif %} + + {% if request.session.user_data.is_label %} + {% if albums %} +

          Daftar Album

          +
            + {% for album in albums %} +
          • {{ album }}
          • + {% endfor %} +
          + {% else %} +

          Belum Memproduksi Album

          + {% endif %} + {% endif %} diff --git a/akun/urls.py b/akun/urls.py index c97ea3d..2f870a4 100644 --- a/akun/urls.py +++ b/akun/urls.py @@ -14,4 +14,5 @@ path('dashboard/', dashboard, name='dashboard'), path('register/pengguna/', register_pengguna, name='register_pengguna'), path('register/label/', register_label, name='register_label'), + path('logout/', logout_view, name='logout'), ] \ No newline at end of file diff --git a/akun/views.py b/akun/views.py index 09032ef..9a887d4 100644 --- a/akun/views.py +++ b/akun/views.py @@ -1,3 +1,4 @@ +import logging from django.shortcuts import render from django.shortcuts import render, redirect from django.contrib.auth import authenticate, login @@ -38,61 +39,597 @@ def list_tables(request): #membuat untuk views dashboard terlebih dahulu -@login_required +# @login_required +# def dashboard(request): +# #dari request session yang sekarnag -> cek di tiap table apakah emailnya ada atau tidak +# #ambil request session terlebih dahulu +# user_data = request.session.get('user_data', {}) +# nama = user_data.get('nama', '') +# email = user_data.get('email', '') +# #next apakah is nya bisa ambil dari request session atau harus diquery juga? +# is_premium = user_data.get('is_premium', False) +# is_artist = user_data.get('is_artist', False) +# is_songwriter = user_data.get('is_songwriter', False) #kalau kuncinya ga ada di dalam request.session maka defaultnya jadi False +# is_podcaster = user_data.get('is_podcaster', False) +# is_label = user_data.get('is_label', False) + +# #is_premium = true -> ini tidak dipakai di dashboard +# data_dict = { +# 'nama': nama, +# 'email': email, +# } +# #is_artist = true + +# #is_songwriter = true +# #is_podcaster = true +# #is_label = true +# return render(request, 'dashboard.html', data_dict) + +# #loginnn + +# def dashboard(request): +# user_data = request.session.get('user_data', {}) +# context = { +# 'is_logged_in': user_data.get('is_logged_in', False), +# 'is_premium': user_data.get('is_premium', False), +# 'is_artist': user_data.get('is_artist', False), +# 'is_songwriter': user_data.get('is_songwriter', False), +# 'is_podcaster': user_data.get('is_podcaster', False), +# 'is_label': user_data.get('is_label', False), +# } +# return render(request, 'dashboard.html', context) def dashboard(request): - # Anda bisa menambahkan logika di sini untuk mengambil data yang diperlukan untuk dashboard - #next ini bisa ditambahkan logika apa role dari pengguna tersebut , atau mungkin bisa di dahsbroad htmlnya sendiri kita pakai untuk variabel yang ada. - return render(request, 'dashboard.html') + # Ambil data pengguna dari session + user_data = request.session.get('user_data', {}) + + # Initialize role flags + user_data.update({ + 'is_artist': False, + 'is_songwriter': False, + 'is_podcaster': False, + 'is_label': False, + 'is_pengguna': False, + 'is_premium' : False, + 'roles': [], + + + }) + #cek apakah dia premium atau tidak di table premium + query_premium = f"SELECT 1 FROM marmut.premium WHERE email = '{user_data.get('email')}'" + with connection.cursor() as cursor: + cursor.execute(query_premium) + user_data['is_premium'] = cursor.fetchone() is not None + + # Check for Artist + query_artist = f"SELECT 1 FROM marmut.artist WHERE email_akun = '{user_data.get('email')}'" + with connection.cursor() as cursor: + cursor.execute(query_artist) + user_data['is_artist'] = cursor.fetchone() is not None + user_data['roles'].append('Artist') if user_data['is_artist'] else '' + + # Check for Pengguna + query_pengguna = f"SELECT 1 FROM marmut.akun WHERE email = '{user_data.get('email')}'" + with connection.cursor() as cursor: + cursor.execute(query_pengguna) + user_data['is_pengguna'] = cursor.fetchone() is not None + user_data['roles'].append('Pengguna') if user_data['is_pengguna'] else '' -#loginnn + # Check for Songwriter + query_songwriter = f"SELECT 1 FROM marmut.songwriter WHERE email_akun = '{user_data.get('email')}'" + with connection.cursor() as cursor: + cursor.execute(query_songwriter) + user_data['is_songwriter'] = cursor.fetchone() is not None + user_data['roles'].append('Songwriter') if user_data['is_songwriter'] else '' + # Check for Podcaster + query_podcaster = f"SELECT 1 FROM marmut.podcaster WHERE email = '{user_data.get('email')}'" + with connection.cursor() as cursor: + cursor.execute(query_podcaster) + user_data['is_podcaster'] = cursor.fetchone() is not None + user_data['roles'].append('Podcaster') if user_data['is_podcaster'] else '' + # Check for Label + query_label = f"SELECT 1 FROM marmut.label WHERE email = '{user_data.get('email')}'" + with connection.cursor() as cursor: + cursor.execute(query_label) + user_data['is_label'] = cursor.fetchone() is not None + user_data['roles'].append('Label') if user_data['is_label'] else '' + + # Update session with user_data + user_data['is_logged_in'] = any([user_data['is_artist'], user_data['is_songwriter'], user_data['is_podcaster'], user_data['is_label'], user_data['is_pengguna']]) + print("cekk") + print(user_data['is_logged_in']) + request.session['user_data'] = user_data + + # Query to get user info + if user_data.get('is_label'): + query_info = f""" + SELECT nama, email, kontak + FROM marmut.label + WHERE email = '{user_data.get('email')}' + """ + else: + query_info = f""" + SELECT email, nama, kota_asal, gender, tempat_lahir, tanggal_lahir + FROM marmut.akun + WHERE email = '{user_data.get('email')}' + """ + with connection.cursor() as cursor: + cursor.execute(query_info) + columns = [col[0] for col in cursor.description] + user_info = dict(zip(columns, cursor.fetchone())) + + playlists = [] + songs_artist = [] + songs_songwriter = [] + podcasts = [] + albums = [] + + # Contoh query untuk pengguna biasa + if not user_data.get('is_label'): + query_playlists = f""" + SELECT judul + FROM marmut.user_playlist + WHERE email_pembuat = '{user_data.get('email')}' + """ + with connection.cursor() as cursor: + cursor.execute(query_playlists) + playlists = [row[0] for row in cursor.fetchall()] + + # Kalau dia artist + if user_data.get('is_artist'): + query_songs_artist = f""" + SELECT k.judul + FROM marmut.konten k + JOIN marmut.song s ON k.id = s.id_konten + JOIN marmut.artist a ON s.id_artist = a.id + WHERE a.email_akun = '{user_data.get('email')}' + """ + with connection.cursor() as cursor: + cursor.execute(query_songs_artist) + songs_artist = [row[0] for row in cursor.fetchall()] + + # Kalau dia songwriter + if user_data.get('is_songwriter'): + query_songs_songwriter = f""" + SELECT k.judul + FROM marmut.konten k + JOIN marmut.songwriter_write_song sws ON k.id = sws.id_song + JOIN marmut.songwriter sw ON sws.id_songwriter = sw.id + WHERE sw.email_akun = '{user_data.get('email')}' + """ + with connection.cursor() as cursor: + cursor.execute(query_songs_songwriter) + songs_songwriter = [row[0] for row in cursor.fetchall()] + + # Kalau dia podcaster + if user_data.get('is_podcaster'): + query_podcasts = f""" + SELECT k.judul + FROM marmut.konten k + JOIN marmut.podcast p ON k.id = p.id_konten + WHERE p.email_podcaster = '{user_data.get('email')}' + """ + with connection.cursor() as cursor: + cursor.execute(query_podcasts) + podcasts = [row[0] for row in cursor.fetchall()] + + # Kalau dia label + if user_data.get('is_label'): + query_albums = f""" + SELECT a.judul + FROM marmut.album a + JOIN marmut.label l ON a.id_label = l.id + WHERE l.email = '{user_data.get('email')}' + """ + with connection.cursor() as cursor: + cursor.execute(query_albums) + albums = [row[0] for row in cursor.fetchall()] + + context = { + 'user_data': user_info, + 'playlists': playlists, + 'songs_artist': songs_artist, + 'songs_songwriter': songs_songwriter, + 'podcasts': podcasts, + 'albums': albums + } + print(user_data) + print("albummmm") + print(albums) + + return render(request, 'dashboard.html', context) + +#TEST +# def dashboard(request): +# # Ambil data pengguna dari session +# user_data = request.session.get('user_data', {}) +# print(user_data) +# #{'email': 'jeffrey36@yahoo.com', 'nama': 'Alexis Long', 'is_premium': False, 'is_artist': False, 'is_songwriter': True, 'is_podcaster': False, 'is_label': False} + +# #cek apakah dia premium atau tidak di table premium +# query_premium = f"SELECT 1 FROM marmut.premium WHERE email = '{user_data.get('email')}'" +# with connection.cursor() as cursor: +# cursor.execute(query_premium) +# user_data['is_premium'] = cursor.fetchone() is not None + +# #cek apakah dia artist atau tidak di table artist +# query_artist = f"SELECT 1 FROM marmut.artist WHERE email_akun = '{user_data.get('email')}'" +# with connection.cursor() as cursor: +# cursor.execute(query_artist) +# user_data['is_artist'] = cursor.fetchone() is not None + +# #cek apakah dia songwriter atau tidak di table songwriter +# query_songwriter = f"SELECT 1 FROM marmut.songwriter WHERE email_akun = '{user_data.get('email')}'" +# with connection.cursor() as cursor: +# cursor.execute(query_songwriter) +# user_data['is_songwriter'] = cursor.fetchone() is not None + +# #cek apakah dia podcaster atau tidak di table podcaster +# query_podcaster = f"SELECT 1 FROM marmut.podcaster WHERE email = '{user_data.get('email')}'" +# with connection.cursor() as cursor: +# cursor.execute(query_podcaster) +# user_data['is_podcaster'] = cursor.fetchone() is not None + +# #cek apakah dia label atau tidak di table label +# query_label = f"SELECT 1 FROM marmut.label WHERE email = '{user_data.get('email')}'" +# with connection.cursor() as cursor: +# cursor.execute(query_label) +# user_data['is_label'] = cursor.fetchone() is not None + +# is_logged_in = True +# user_data['is_logged_in'] = is_logged_in + +# # Query untuk mendapatkan informasi sesuai dengan role pengguna +# query_info = "" + +# #kalau dia pengguna berarti yg penting dia ga label +# print(user_data['is_label']) +# if user_data['is_label'] == False: +# print("masuk sini") +# #status langganan pakai cek di html aja is_premium atau ga +# query_info = f""" + +# SELECT nama, email, kota_asal, gender, tempat_lahir, tanggal_lahir +# FROM marmut.akun +# WHERE email = '{user_data.get('email')}' +# """ +# with connection.cursor() as cursor: +# cursor.execute(query_info) +# columns = [col[0] for col in cursor.description] +# user_info = dict(zip(columns, cursor.fetchone())) +# elif user_data['is_label'] == True: +# print("pipuppipip") +# query_info = f""" +# SELECT nama, email, kontak, kota_asal +# FROM marmut.label +# WHERE email = '{user_data.get('email')}' +# """ +# with connection.cursor() as cursor: +# cursor.execute(query_info) +# columns = [col[0] for col in cursor.description] +# user_info = dict(zip(columns, cursor.fetchone())) +# # Tambahkan kondisi lain untuk role Artist, Songwriter, dan Podcaster jika diperlukan + + + +# # Query untuk mendapatkan playlist, lagu, podcast, atau album sesuai dengan role pengguna +# playlists = [] +# songs_artist = [] +# songs_songwriter = [] +# podcasts = [] +# albums = [] + +# # Contoh query untuk pengguna biasa +# if user_data.get('is_label') == False: +# query_playlists = f""" +# SELECT judul +# FROM marmut.user_playlist +# WHERE email_pembuat = '{user_data.get('email')}' +# """ +# with connection.cursor() as cursor: +# cursor.execute(query_playlists) +# playlists = [row[0] for row in cursor.fetchall()] + +# #kalau dia artist +# if user_data.get('is_artist') == True : +# #ambil dulu dari artist -> dpt id -> gabung sama song.id_artist =artist.id -> gabung sama konten.id = song.id_konten -> ambil judul +# query_songs_artist = f""" +# SELECT judul +# FROM marmut.konten +# JOIN marmut.artist ON song.id_artist = artist.id +# JOIN marmut.song ON song.id_konten = konten.id +# WHERE artist.email_akun = '{user_data.get('email')}' +# """ +# with connection.cursor() as cursor: +# cursor.execute(query_songs_artist) +# songs_artist = [row[0] for row in cursor.fetchall()] + +# #kalau dia songwriter +# if user_data.get('is_songwriter') == True: +# query_songs_songwriter = f""" +# SELECT judul +# FROM marmut.konten +# JOIN marmut.songwriter_write_song ON songwriter_write_song.id_song = konten.id +# JOIN marmut.songwriter ON songwriter_write_song.id_songwriter = songwriter.id +# WHERE songwriter.email_akun = '{user_data.get('email')}' +# """ +# with connection.cursor() as cursor: +# cursor.execute(query_songs_songwriter) +# songs_songwriter = [row[0] for row in cursor.fetchall()] +# #kalau dia podcaster +# if user_data.get('is_podcaster') == True: +# query_podcasts = f""" +# SELECT nama_podcast +# FROM marmut.podcast +# WHERE host = '{user_data.get('email')}' +# """ +# with connection.cursor() as cursor: +# cursor.execute(query_podcasts) +# podcasts = [row[0] for row in cursor.fetchall()] + +# #kalau dia label +# if user_data.get('is_label') == True: +# query_albums = f""" +# SELECT nama_album +# FROM marmut.album +# WHERE label = '{user_data.get('email')}' +# """ +# with connection.cursor() as cursor: +# cursor.execute(query_albums) +# albums = [row[0] for row in cursor.fetchall()] +# #buat pass list roles +# roles = [] +# if user_data.get('is_artist') == True: +# roles.append('Artist') +# if user_data.get('is_songwriter') == True: +# roles.append('Songwriter') +# if user_data.get('is_podcaster') == True: +# roles.append('Podcaster') +# if user_data.get('is_label') == True: +# roles.append('Label') +# if user_data.get('is_label') == False: +# roles.append('Pengguna') +# context = { +# 'user_data': user_info, +# 'role': ', '.join(roles), +# 'playlists': playlists, +# 'songs': songs, +# 'podcasts': podcasts, +# 'albums': albums +# } + +# return render(request, 'dashboard.html', context) + + +# def dashboard(request): +# # Ambil data pengguna dari session +# user_data = request.session.get('user_data', {}) +# print(user_data) +# # Query untuk mendapatkan informasi sesuai dengan role pengguna +# query_info = "" +# if user_data.get('role') == 'Pengguna': +# query_info = f""" +# SELECT nama, email, status_langganan, kota_asal, gender, tempat_lahir, tanggal_lahir, role +# FROM marmut.akun +# WHERE email = '{user_data.get('email')}' +# """ +# elif user_data.get('role') == 'Label': +# query_info = f""" +# SELECT nama, email, kontak, kota_asal +# FROM marmut.label +# WHERE email = '{user_data.get('email')}' +# """ +# # Tambahkan kondisi lain untuk role Artist, Songwriter, dan Podcaster jika diperlukan + +# with connection.cursor() as cursor: +# cursor.execute(query_info) +# columns = [col[0] for col in cursor.description] +# user_info = dict(zip(columns, cursor.fetchone())) + +# # Query untuk mendapatkan playlist, lagu, podcast, atau album sesuai dengan role pengguna +# playlists = [] +# songs = [] +# podcasts = [] +# albums = [] + +# # Contoh query untuk pengguna +# if user_data.get('role') == 'Pengguna': +# query_playlists = f""" +# SELECT nama_playlist +# FROM playlist +# WHERE pemilik = '{user_data.get('email')}' +# """ +# cursor.execute(query_playlists) +# playlists = [row[0] for row in cursor.fetchall()] + +# # Contoh query untuk Artist/Songwriter +# if user_data.get('role') in ['Artist', 'Songwriter']: +# query_songs = f""" +# SELECT judul_lagu +# FROM lagu +# WHERE pemilik = '{user_data.get('email')}' +# """ +# cursor.execute(query_songs) +# songs = [row[0] for row in cursor.fetchall()] + +# # Contoh query untuk Podcaster +# if user_data.get('role') == 'Podcaster': +# query_podcasts = f""" +# SELECT nama_podcast +# FROM podcast +# WHERE host = '{user_data.get('email')}' +# """ +# cursor.execute(query_podcasts) +# podcasts = [row[0] for row in cursor.fetchall()] + +# # Contoh query untuk Label +# if user_data.get('role') == 'Label': +# query_albums = f""" +# SELECT nama_album +# FROM album +# WHERE label = '{user_data.get('email')}' +# """ +# cursor.execute(query_albums) +# albums = [row[0] for row in cursor.fetchall()] + +# context = { +# 'user_data': user_info, +# 'playlists': playlists, +# 'songs': songs, +# 'podcasts': podcasts, +# 'albums': albums +# } + +# return render(request, 'dashboard.html', context) +#coba yang baru login nya @csrf_exempt def login_with_postgres(request): - is_premium = False - is_artist = False - is_songwriter = False - is_podcaster = False - is_label = False - if request.method == 'POST': email = request.POST.get('email') password = request.POST.get('password') - # Query untuk mencari pengguna berdasarkan email di tabel akun - query_akun = f""" - SELECT * FROM marmut.akun WHERE email = '{email}' - """ + + # Query untuk mencari pengguna atau label berdasarkan email dan mengambil passwordnya + query_akun = f"SELECT email, password, nama FROM marmut.akun WHERE email = %s" + query_label = f"SELECT email, password, nama FROM marmut.label WHERE email = %s" + + user_akun = None with connection.cursor() as cursor: - cursor.execute(query_akun) - columns = [col[0] for col in cursor.description] - matching_users_akun = [dict(zip(columns, row)) for row in cursor.fetchall()] - - if matching_users_akun: - user_akun = matching_users_akun[0] - if user_akun['password'] == password: - # Set user data in session - request.session['user_data'] = { - 'email': user_akun['email'], - 'nama': user_akun.get('nama', ''), - 'password': password, - 'is_premium': is_premium, - 'is_artist': is_artist, - 'is_songwriter': is_songwriter, - 'is_podcaster': is_podcaster, - 'is_label': is_label - } - return render(request, 'dashboard.html') + cursor.execute(query_akun, [email]) + user_akun = cursor.fetchone() + + if not user_akun: + cursor.execute(query_label, [email]) + user_akun = cursor.fetchone() + + if user_akun: + email, stored_password, nama = user_akun + + # Check if the provided password matches the stored password + if stored_password == password: + # Check for roles + queries = { + 'is_artist': f"SELECT 1 FROM marmut.artist WHERE email_akun = %s", + 'is_songwriter': f"SELECT 1 FROM marmut.songwriter WHERE email_akun = %s", + 'is_podcaster': f"SELECT 1 FROM marmut.podcaster WHERE email = %s", + } + roles = {} + for role, query in queries.items(): + cursor.execute(query, [email]) + roles[role] = cursor.fetchone() is not None + + # Check if the user is a label + is_label = False + cursor.execute(query_label, [email]) + if cursor.fetchone(): + is_label = True + + # Set user data in session + request.session['user_data'] = { + 'email': email, + 'nama': nama, + 'is_premium': False, # Modify this if you need to set it dynamically + 'is_artist': roles.get('is_artist', False), + 'is_songwriter': roles.get('is_songwriter', False), + 'is_podcaster': roles.get('is_podcaster', False), + 'is_label': is_label, + 'is_logged_in': True, + 'roles': roles + } + #request.session['is_logged_in'] = True + print("hihi") + print(request.session['user_data']) + return redirect('akun:dashboard') + else: + messages.error(request, 'Maaf, password yang Anda masukkan salah.') else: - messages.error(request, 'Maaf, password yang Anda masukkan salah.') - else: - messages.error(request, 'Pengguna tidak ditemukan.') + messages.error(request, 'Pengguna tidak ditemukan.') return render(request, "login.html") + +# @csrf_exempt +# def login_with_postgres(request): +# is_premium = False +# is_artist = False +# is_songwriter = False +# is_podcaster = False +# is_label = False +# is_logged_in = False + +# if request.method == 'POST': +# email = request.POST.get('email') +# password = request.POST.get('password') + +# # Query untuk mencari pengguna berdasarkan email di tabel akun +# query_akun = f""" +# SELECT * FROM marmut.akun WHERE email = '{email}' +# """ + +# with connection.cursor() as cursor: +# cursor.execute(query_akun) +# columns = [col[0] for col in cursor.description] +# matching_users_akun = [dict(zip(columns, row)) for row in cursor.fetchall()] + +# if matching_users_akun: +# user_akun = matching_users_akun[0] + + + +# # Check for artist +# query_artist = f"SELECT 1 FROM marmut.artist WHERE email_akun = '{email}'" +# with connection.cursor() as cursor: +# cursor.execute(query_artist) +# is_artist = cursor.fetchone() is not None + +# # Check for songwriter +# query_songwriter = f"SELECT 1 FROM marmut.songwriter WHERE email_akun = '{email}'" +# with connection.cursor() as cursor: +# cursor.execute(query_songwriter) +# is_songwriter = cursor.fetchone() is not None + +# # Check for podcaster +# query_podcaster = f"SELECT 1 FROM marmut.podcaster WHERE email = '{email}'" +# with connection.cursor() as cursor: +# cursor.execute(query_podcaster) +# is_podcaster = cursor.fetchone() is not None + +# # Check for label +# query_label = f"SELECT 1 FROM marmut.label WHERE email = '{email}'" +# with connection.cursor() as cursor: +# cursor.execute(query_label) +# is_label = cursor.fetchone() is not None +# if user_akun['password'] == password: +# # Set user data in session +# is_logged_in = True +# request.session['user_data'] = { +# 'email': user_akun['email'], +# 'nama': user_akun.get('nama', ''), +# 'password': password, +# 'is_premium': is_premium, +# 'is_artist': is_artist, +# 'is_songwriter': is_songwriter, +# 'is_podcaster': is_podcaster, +# 'is_label': is_label, +# 'is_logged_in': is_logged_in +# } +# print("aaaaaaa") +# print(is_songwriter) +# print(is_logged_in) + +# return render(request, 'dashboard.html') +# else: +# messages.error(request, 'Maaf, password yang Anda masukkan salah.') +# else: +# messages.error(request, 'Pengguna tidak ditemukan.') + +# return render(request, "login.html") + + #BATASSSSSSSSSSSSSSSSS #syarat untuk login unik akunnya # @csrf_exempt @@ -288,6 +825,7 @@ def register_label(request): #register pengguna @csrf_exempt +#TO DO: apakah sebenarnya pas insert itu boleh null, kalau begitu insert seperti biasa saja NEXT def register_pengguna(request): if request.method == 'POST': email = request.POST.get('email') @@ -299,6 +837,8 @@ def register_pengguna(request): kota_asal = request.POST.get('kota_asal') roles = request.POST.getlist('role') is_verified = True + #id pemilik hak cipta berarti gapapa None + id_pemilik_hak_cipta = None #next : mungkin nanti baru ada triggernya #kalau ga ada role yang dipilih @@ -340,11 +880,11 @@ def register_pengguna(request): #ambil email dari table akun email_akun = email_akun[0][0] #NEXT #ambil id dari table pemilik hak cipta - cursor.execute(""" SELECT DISTINCT r.id_pemilik_hak_cipta - FROM song s - JOIN royalti r ON s.id_konten = r.id_song - WHERE s.id_artist = %s;""", [artist_id]) - id_pemilik_hak_cipta = cursor.fetchall() + # cursor.execute(""" SELECT DISTINCT r.id_pemilik_hak_cipta + # FROM song s + # JOIN royalti r ON s.id_konten = r.id_song + # WHERE s.id_artist = %s;""", [artist_id]) + # id_pemilik_hak_cipta = cursor.fetchall() #masukkan ke table artist query_insert_artist = """ @@ -370,15 +910,15 @@ def register_pengguna(request): #ambil email dari table akun email_akun = email_akun[0][0] #NEXT #ambil id pemilik hak cipta -> ambil dari songwriter_write_song dulu baru dapat id_songnya - query = """ - SELECT DISTINCT r.id_pemilik_hak_cipta - FROM songwriter_write_song sws - JOIN song s ON sws.id_song = s.id_konten - JOIN royalti r ON s.id_konten = r.id_song - WHERE sws.id_songwriter = %s - """ - cursor.execute(query, (artist_id,)) - id_pemilik_hak_cipta = cursor.fetchone() + # query = """ + # SELECT DISTINCT r.id_pemilik_hak_cipta + # FROM songwriter_write_song sws + # JOIN song s ON sws.id_song = s.id_konten + # JOIN royalti r ON s.id_konten = r.id_song + # WHERE sws.id_songwriter = %s + # """ + # cursor.execute(query, (artist_id,)) + # id_pemilik_hak_cipta = cursor.fetchone() #masukkan ke table artist query_insert_artist = """ @@ -393,3 +933,24 @@ def register_pengguna(request): # except Exception as error: # messages.error(request, f'{error}') return render(request, 'register_pengguna.html') + +logger = logging.getLogger(__name__) + +def logout_view(request): + # Cetak nama pengguna sebelum menghapus sesi + logger.info(f"Nama pengguna sebelum logout: {request.session.get('username')}") + + # Hapus data sesi + request.session.flush() + + # Cetak nama pengguna setelah menghapus sesi + logger.info(f"Nama pengguna setelah logout: {request.session.get('username')}") + + # Redirect ke halaman login + return redirect('akun:login') +# def logout_view(request): +# # Hapus data sesi +# request.session.flush() + +# # Redirect ke halaman login +# return redirect('akun:login') \ No newline at end of file diff --git a/album_song_royalti/bener.py b/album_song_royalti/bener.py new file mode 100644 index 0000000..995a371 --- /dev/null +++ b/album_song_royalti/bener.py @@ -0,0 +1,109 @@ + +def create_album(request): + user_data = request.session.get('user_data', {}) + email = user_data.get('email', None) + + if request.method == "POST": + #print(request.POST) + for a in request.POST: + print(a, request.POST[a]) + judul_album = request.POST.get('judul_album') + label_str = request.POST.get('label') + label_id = label_str[13:49] + judul_lagu = request.POST.get('judul_lagu') + artists = request.POST.get('artist') + print(artists) + songwriters = request.POST.getlist('songwriter[]') + genres = request.POST.getlist('genre[]') + durasi = request.POST.get('durasi') + #ambil tanggal sekarang + tanggal_rilis = datetime.datetime.now() + tahun = tanggal_rilis.year + + + + #carik di artist_id pakai query dah + with connection.cursor() as cursor: + cursor.execute("SELECT id FROM marmut.artist WHERE email_akun = %s", [artists]) + artist_id = cursor.fetchone()[0] + + print(artist_id) + + genre_masuk = [] + #isinya nomor idnya + for genre in genres: + print(genre) + with connection.cursor() as cursor: + cursor.execute("SELECT DISTINCT genre FROM marmut.genre") + ada_genre = cursor.fetchall() + ada_genre = ada_genre[int(genre)] + ada_genre_2 = ada_genre[0] + genre_masuk.append(ada_genre_2) + + + + #ambil dari nomor genre ke query + print(songwriters) + if user_data['is_songwriter']: + with connection.cursor() as cursor: + cursor.execute("SELECT DISTINCT id FROM marmut.songwriter WHERE email_akun = %s", (email,)) + songwriter_orangnya = cursor.fetchall() + songwriters.append(str(songwriter_orangnya[0][0])) + songwriter_ids = [songwriter for songwriter in songwriters] + + + #sekarnag bagian insert data ke database + album_id = str(uuid.uuid4()) + song_id = str(uuid.uuid4()) + with connection.cursor() as cursor: + cursor.execute("INSERT INTO marmut.konten (id, judul, tanggal_rilis, tahun, durasi) VALUES (%s, %s, %s, %s, %s)", [song_id, judul_lagu, tanggal_rilis, tahun, durasi]) + cursor.execute("INSERT INTO marmut.album (id, judul, jumlah_lagu, id_label, total_durasi) VALUES (%s, %s, %s, %s, %s)", [album_id, judul_album, 1, label_id, int(durasi)]) + cursor.execute("INSERT INTO marmut.song (id_konten, id_artist, id_album) VALUES (%s, %s, %s)", [song_id, artist_id, album_id]) + for genre_id in genre_masuk: + cursor.execute("INSERT INTO marmut.genre (id_konten, genre) VALUES (%s, %s)", [song_id, genre_id]) + for songwriter_id in songwriter_ids: + cursor.execute("INSERT INTO marmut.songwriter_write_song (id_songwriter, id_song) VALUES (%s, %s)", [songwriter_id, song_id]) + + + #NEXT HABIS INI KAYAKNYA AMBIL SEMUA SYANG BISA PUNYA ROYALTI DAH SEPERTI ARTIST, LABEL, SONGWRITER + # TAPI MASALAHNYA RIYALTI NYA GA TAU BERAPAAN + return HttpResponse(f'Album {judul_album} berhasil dibuat dengan artist: {label_str}{(artists)}, songwriters: {", ".join(songwriters)}, genres: {", ".join(genres)}, durasi: {durasi} menit.') + #ambil labels dulu dari database, sekalian dengan key nya + with connection.cursor() as cursor: + cursor.execute("SELECT id, nama FROM marmut.label") + labels = cursor.fetchall() + #petakan ke dictionary + labels = [{'id': label[0], 'nama': label[1]} for label in labels] + + cursor.execute("SELECT id, email_akun FROM marmut.artist") + artists = cursor.fetchall() + #petakan ke dictionary + artists = [{'id': artist[0], 'email_akun': artist[1]} for artist in artists] + + + cursor.execute("SELECT id, email_akun FROM marmut.songwriter WHERE email_akun != %s", (email,)) + songwriters = cursor.fetchall() + #petakan ke dictionary + songwriters = [{'id': songwriter[0], 'email_akun': songwriter[1]} for songwriter in songwriters] + + cursor.execute("SELECT DISTINCT genre FROM marmut.genre") + genres = cursor.fetchall() + #petakan ke dictionary -> enumparate + genres = [{'id': idx, 'genre': genre[0]} for idx, genre in enumerate(genres)] + + print(genres) + print(labels) + print(songwriters) + print(artists) + + + + + + return render(request, 'create_album.html', { + 'labels': labels, + 'artists': artists, + 'songwriters': songwriters, + 'genres': genres, + }) + \ No newline at end of file diff --git a/album_song_royalti/create_album.py b/album_song_royalti/create_album.py new file mode 100644 index 0000000..7dfbc57 --- /dev/null +++ b/album_song_royalti/create_album.py @@ -0,0 +1,119 @@ +def create_album(request): + user_data = request.session.get('user_data', {}) + is_artist = user_data.get('is_artist', False) + is_songwriter = user_data.get('is_songwriter', False) + user_id = user_data.get('user_id', None) + email = user_data.get('email', None) + + print("test userdata") + print(user_data) + if not (is_artist or is_songwriter): + return HttpResponse("You are not authorized to access this page", status=403) + + if request.method == "POST": + print("Semua data dalam request.POST:") + for a in request.POST: + print(a) + judul_album = request.POST.get('judul_album') + print(judul_album) + label_id = request.POST.get('label') + print("label iddddddddddd") + print(label_id) + album_id = str(uuid.uuid4()) + artists = request.POST.getlist('artist[]') + print("kasik artist") + + + #untuk section lagu pertama + judul_lagu = request.POST['judul_lagu'] + artist_id = request.POST.get('artist') + + songwriter_ids = request.POST.getlist('songwriter.id') + print(songwriter_ids) + genre_ids = request.POST.getlist('genre.id') + durasi = request.POST['durasi'] + song_id = str(uuid.uuid4()) + print(song_id) + tanggal_rilis = datetime.datetime.now() + tahun = tanggal_rilis.year + print(album_id) + + #insert ke table konteen dulu + with connection.cursor() as cursor: + cursor.execute("INSERT INTO marmut.konten (id, judul, tanggal_rilis, tahun, durasi) VALUES (%s, %s, %s, %s, %s)", [song_id, judul_lagu, tanggal_rilis, tahun, durasi]) + #cursor.execute("INSERT INTO marmut.artist (artist_id, song_id) VALUES (%s, %s)", [artist_id, song_id]) + #masukkan ke album + cursor.execute("INSERT INTO marmut.album (id, judul, jumlah_lagu, id_label, total_durasi) VALUES (%s, %s, %s, %s, %s)", [album_id, judul_album, 1, label_id, int(durasi)]) + + with connection.cursor() as cursor: + #ke table song -> artistnya pasti satu + cursor.execute("INSERT INTO marmut.song (id_konten, id_artist, id_album) VALUES (%s, %s, %s)", [song_id, artist_id, album_id]) + + for genre_id in genre_ids: + cursor.execute("INSERT INTO marmut.genre (id_konten, genre) VALUES (%s, %s)", [song_id, genre_id]) + #ini ga perlu karena dia sudah ada di table songwriter + # for songwriter_id in songwriter_ids: + # cursor.execute("INSERT INTO marmut.songwriter_writes_song (songwriter_id, song_id) VALUES (%s, %s)", [songwriter_id, song_id]) + + #songwriter_write_song + for songwriter_id in songwriter_ids: + cursor.execute("INSERT INTO marmut.songwriter_write_song (id_songwriter, id_song) VALUES (%s, %s)", [songwriter_id, song_id]) + + + + # #insert into table song dulu -> biarin album id null dulu, ntar diupdate + # with connection.cursor() as cursor: + # cursor.execute("INSERT INTO marmut.song (id_konten, id_artist) VALUES (%s, %s, %s)", [song_id, judul_lagu, durasi]) + # for songwriter_id in songwriter_ids: + # cursor.execute("INSERT INTO marmut.songwriter_writes_song (songwriter_id, song_id) VALUES (%s, %s)", [songwriter_id, song_id]) + + + + + + # return redirect(reverse('create_lagu', args=[album_id])) + return HttpResponseRedirect(reverse('list_album_artist')) + with connection.cursor() as cursor: + cursor.execute("SELECT id, nama FROM marmut.label") + labels = cursor.fetchall() + + #jika is_artist true + if not user_data['is_artist'] : + print("dia bukan artist") + cursor.execute("SELECT id, nama FROM marmut.artist JOIN marmut.akun ON artist.email_akun = akun.email") + artists = cursor.fetchall() + else: + cursor.execute("SELECT id, nama FROM marmut.artist JOIN marmut.akun ON artist.email_akun = akun.email WHERE akun.email = %s", [email]) + artists = cursor.fetchall() + + #jika is_songwriter true + #jika is_songwriter true + if user_data['is_songwriter']: + print(" songwriter adalah true") + cursor.execute("""SELECT id, nama FROM marmut.songwriter + JOIN marmut.akun ON songwriter.email_akun = akun.email + WHERE akun.email != %s + """, [email]) + songwriters = cursor.fetchall() + cursor.execute("SELECT id, nama FROM marmut.songwriter JOIN marmut.akun ON songwriter.email_akun = akun.email WHERE akun.email = %s", [email]) + + # Tambahkan data songwriter pengguna ke dalam list songwriters + # user_songwriter = cursor.fetchone() + # if user_songwriter: + # songwriters.append(user_songwriter) + else: + print("songwriter bukan trueee") + cursor.execute("SELECT id, nama FROM marmut.songwriter JOIN marmut.akun ON songwriter.email_akun = akun.email") + songwriters = cursor.fetchall() + + + cursor.execute("SELECT DISTINCT genre FROM marmut.genre") + genres = cursor.fetchall() + + context = { + 'labels': labels, + 'artists': artists, + 'songwriters': songwriters, + 'genres': genres, + } + return render(request, 'create_album.html', context) diff --git a/album_song_royalti/simpen_cek_royalti.py b/album_song_royalti/simpen_cek_royalti.py new file mode 100644 index 0000000..79b8dcb --- /dev/null +++ b/album_song_royalti/simpen_cek_royalti.py @@ -0,0 +1,39 @@ +def cek_royalti(request): + user_data = request.session.get('user_data', {}) + user_email = user_data.get('email', '') + + if user_data.get('is_label'): + with connection.cursor() as cursor: + cursor.execute(""" + SET SEARCH_PATH TO MARMUT; + SELECT + S.id_konten AS id_song, + PHC.id AS id_pemilik_hak_cipta, + (CAST(S.total_play AS NUMERIC) * CAST(PHC.rate_royalti AS NUMERIC)) AS TotalRoyalti + FROM + LABEL L + JOIN ALBUM A ON L.id = A.id_label + JOIN SONG S ON S.id_album = A.id + JOIN KONTEN K ON K.id = S.id_konten + JOIN PEMILIK_HAK_CIPTA PHC ON L.id_pemilik_hak_cipta = PHC.id + WHERE + L.email = %s + """, [user_email]) + royalty_data = cursor.fetchall() + + # Update the ROYALTI table for each song + for row in royalty_data: + id_song = row[0] + id_pemilik_hak_cipta = row[1] + total_royalti = row[2] + + cursor.execute(""" + UPDATE ROYALTI + SET jumlah = %s + WHERE id_pemilik_hak_cipta = %s AND id_song = %s + """, [total_royalti, id_pemilik_hak_cipta, id_song]) + + context = { + 'royalty_list': royalty_data + } + return render(request, 'cek_royalti.html', context) diff --git a/album_song_royalti/templates/cek_royalti.html b/album_song_royalti/templates/cek_royalti.html index be7c36d..3fe0947 100644 --- a/album_song_royalti/templates/cek_royalti.html +++ b/album_song_royalti/templates/cek_royalti.html @@ -1,73 +1,32 @@ - + + {% include 'nav.html' %} - - Cek Royalti - - - - - - - - - -

          LIST ROYALTI

          - - - - - - - - - - - - - - - - - - - - - - - - +

          Daftar Royalti

          +
          Judul LaguJudul AlbumTotal PlayTotal DownloadTotal Royalti Didapat
          Lagu1Album130Rp 450000
          Lagu2Album222Rp 520000
          + + + + + + + + + + + {% for royalti in royalti_list %} + + + + + + + + {% endfor %} +
          Judul LaguJudul AlbumTotal PlayTotal DownloadTotal Royalti Didapat
          {{ royalti.0 }}{{ royalti.1 }}{{ royalti.2 }}{{ royalti.3 }}Rp {{ royalti.4 }}
          diff --git a/album_song_royalti/templates/create_album.html b/album_song_royalti/templates/create_album.html new file mode 100644 index 0000000..91a9230 --- /dev/null +++ b/album_song_royalti/templates/create_album.html @@ -0,0 +1,68 @@ + + + + + Create Album + + +

          Create Album

          +
          + {% csrf_token %} + +
          + + +
          + +

          Lagu Pertama

          + +
          + + +
          + + + {% if request.session.user_data.is_songwriter %} +
          +
          Anda adalah songwriter jadi anda otomatis masuk ke dalam songwriter. Silahkan pilih songwriter lainnya:
          + {% endif %} +
          +
          + {% for songwriter in songwriters %} + +
          + {% endfor %} +
          + + +
          +
          + {% for genre in genres %} + +
          + {% endfor %} +
          + + + +
          + + +
          + + diff --git a/album_song_royalti/templates/create_lagu.html b/album_song_royalti/templates/create_lagu.html new file mode 100644 index 0000000..8f36d49 --- /dev/null +++ b/album_song_royalti/templates/create_lagu.html @@ -0,0 +1,59 @@ + + + + + Create Lagu + + + +

          Create lagu untuk di Album {{judul_album}} - {{album_id}}

          +
          + {% csrf_token %} + +

          Lagu Pertama

          + +
          + + +
          + + + {% if request.session.user_data.is_songwriter %} +
          +
          Anda adalah songwriter jadi anda otomatis masuk ke dalam songwriter. Silahkan pilih songwriter lainnya:
          + {% endif %} +
          +
          + {% for songwriter in songwriters %} + +
          + {% endfor %} +
          + + +
          +
          + {% for genre in genres %} + +
          + {% endfor %} +
          + + + +
          + + +
          + + diff --git a/album_song_royalti/templates/daftar_lagu.html b/album_song_royalti/templates/daftar_lagu.html new file mode 100644 index 0000000..aea026f --- /dev/null +++ b/album_song_royalti/templates/daftar_lagu.html @@ -0,0 +1,37 @@ + + + + Daftar Lagu pada Album {{ album.judul }} + + +

          Daftar Lagu pada Album {{ album.judul }}

          + + + + + + + + + + + + {% for song in song_list %} + + + + + + + + {% endfor %} + +
          JudulDurasiTotal PlayTotal DownloadAction
          {{ song.judul }}{{ song.durasi }} menit{{ song.total_play }}{{ song.total_download }} + Lihat Detail +
          + {% csrf_token %} + +
          +
          + + diff --git a/album_song_royalti/templates/entry_album_song_create_list.html b/album_song_royalti/templates/entry_album_song_create_list.html new file mode 100644 index 0000000..b356f2d --- /dev/null +++ b/album_song_royalti/templates/entry_album_song_create_list.html @@ -0,0 +1,28 @@ + + + + + {% include 'nav.html' %} + + + + Pilihan Registrasi + + +

          CRUD KELOLA ALBUM & SONG

          + + + + diff --git a/album_song_royalti/templates/lihat_detail_lagu.html b/album_song_royalti/templates/lihat_detail_lagu.html new file mode 100644 index 0000000..ff40e26 --- /dev/null +++ b/album_song_royalti/templates/lihat_detail_lagu.html @@ -0,0 +1,39 @@ + + + {% include 'nav.html' %} + + Detail Lagu + + +

          Detail Lagu

          + + {% if song %} + + + + + + + + + + + + + + + + + + + + + +
          ID{{ song.id }}
          Judul{{ song.judul }}
          Durasi{{ song.durasi }} menit
          Total Play{{ song.total_play }}
          Total Download{{ song.total_download }}
          + {% else %} +

          Lagu tidak ditemukan.

          + {% endif %} + + Kembali ke Daftar Album + + diff --git a/album_song_royalti/templates/list_album.html b/album_song_royalti/templates/list_album.html new file mode 100644 index 0000000..a4b7015 --- /dev/null +++ b/album_song_royalti/templates/list_album.html @@ -0,0 +1,36 @@ + + + + + Daftar Album - Label + + +

          Daftar Album

          + + + + + + + + + + + {% for album in album_list %} + + + + + + + {% endfor %} + +
          JudulJumlah LaguTotal DurasiAction
          {{ album.judul }}{{ album.jumlah_lagu }}{{ album.total_durasi }} menit + Lihat Daftar Lagu +
          + {% csrf_token %} + +
          +
          + + diff --git a/album_song_royalti/templates/list_album_artist.html b/album_song_royalti/templates/list_album_artist.html new file mode 100644 index 0000000..c37b6fd --- /dev/null +++ b/album_song_royalti/templates/list_album_artist.html @@ -0,0 +1,76 @@ + + + + Daftar Album - Artist/Songwriter + + +

          Daftar Album

          + Buat Album Baru + + {% if album_list_songwriter %} +

          Daftar Album As Songwriter

          + + + + + + + + + + + + {% for album in album_list_songwriter %} + + + + + + + + {% endfor %} + +
          JudulLabelJumlah LaguTotal DurasiAction
          {{ album.judul }}{{ album.label }}{{ album.jumlah_lagu }}{{ album.total_durasi }} menit + Lihat Daftar Lagu + Tambah Lagu +
          + {% csrf_token %} + +
          +
          + {% endif %} + + {% if album_list_artist %} +

          Daftar Album As Artist

          + + + + + + + + + + + + {% for album in album_list_artist %} + + + + + + + + {% endfor %} + +
          JudulLabelJumlah LaguTotal DurasiAction
          {{ album.judul }}{{ album.label }}{{ album.jumlah_lagu }}{{ album.total_durasi }} menit + Lihat Daftar Lagu + Tambah Lagu +
          + {% csrf_token %} + +
          +
          + {% endif %} + + diff --git a/album_song_royalti/templates/list_lagu.html b/album_song_royalti/templates/list_lagu.html new file mode 100644 index 0000000..d73a04e --- /dev/null +++ b/album_song_royalti/templates/list_lagu.html @@ -0,0 +1,41 @@ + + + +{% include 'nav.html' %} + + + + Daftar Lagu + + +

          Daftar Lagu pada Album {{ album.judul }}

          + + + + + + + + + + + + {% for lagu in lagu_list %} + + + + + + + + {% endfor %} + +
          JudulDurasiTotal PlayTotal DownloadAction
          {{ lagu.judul }}{{ lagu.durasi }} menit{{ lagu.total_play }}{{ lagu.total_download }} + Lihat Detail +
          + {% csrf_token %} + +
          +
          + + diff --git a/album_song_royalti/templates/multiselect_form.html b/album_song_royalti/templates/multiselect_form.html new file mode 100644 index 0000000..fdc142e --- /dev/null +++ b/album_song_royalti/templates/multiselect_form.html @@ -0,0 +1,18 @@ + + + + Multiselect Example + + +
          +
          +

          + +
          + + \ No newline at end of file diff --git a/album_song_royalti/tes.py b/album_song_royalti/tes.py new file mode 100644 index 0000000..7e87357 --- /dev/null +++ b/album_song_royalti/tes.py @@ -0,0 +1,6 @@ +#Impory uuid +import uuid + +#buat uuid +album_id = str(uuid.uuid4()) +print(album_id) \ No newline at end of file diff --git a/album_song_royalti/tes_multi.html b/album_song_royalti/tes_multi.html new file mode 100644 index 0000000..bf81f08 --- /dev/null +++ b/album_song_royalti/tes_multi.html @@ -0,0 +1,19 @@ + + +Multi-selection + + + +
          +
          +

          + +
          + + + \ No newline at end of file diff --git a/album_song_royalti/ubah_format.py b/album_song_royalti/ubah_format.py new file mode 100644 index 0000000..674b2cd --- /dev/null +++ b/album_song_royalti/ubah_format.py @@ -0,0 +1,7 @@ +import json +from uuid import UUID + +# String dictionary yang diberikan +string_dict = '{"id": UUID("8e604435-ac15-496f-90ca-4ac3255e51b0"), "nama": "Harper-Bell"}' + +print(string_dict[13:49]) \ No newline at end of file diff --git a/album_song_royalti/urls.py b/album_song_royalti/urls.py new file mode 100644 index 0000000..3cf71f7 --- /dev/null +++ b/album_song_royalti/urls.py @@ -0,0 +1,32 @@ +from django.urls import path +from album_song_royalti.views import * + +urlpatterns = [ + # path('create-album/', create_album, name='create_album'), + # path('success_create_album/', success_create_album, name='success_create_album'), + + # #untuk list album + # path('list-album/', list_album, name='list_album'), + # path('hapus-album//',hapus_album, name='hapus_album'), + # path('lihat-daftar-lagu//', list_lagu, name='lihat_daftar_lagu'), + # path('create-lagu//', create_lagu, name='create_lagu'), + # # path('create-lagu//', create_lagu, name='create_lagu'), + # path('lihat-detail//',lihat_detail, name='lihat_detail'), + # path('hapus-lagu//',hapus_lagu, name='hapus_lagu'), + #cek royalti + path('cek-royalti/', cek_royalti, name='cek_royalti'), + #baru + path('list-album/', list_album, name='list_album'), + path('list-album-artist/', list_album_artist, name='list_album_artist'), + path('daftar-lagu//', daftar_lagu, name='lihat_daftar_lagu_label'), + path('daftar-lagu-artist//', daftar_lagu, name='lihat_daftar_lagu_artist'), + path('create-album/', create_album, name='create_album'), + path('create-lagu//', create_lagu, name='create_lagu'), + path('hapus-album//', hapus_album, name='hapus_album'), + path('hapus-lagu//', hapus_lagu, name='hapus_lagu'), + path('index/', index, name='index'), + path('submit', submit, name='submit'), + + path('entry_album_song_create_list/', entry_album_song_create_list, name='entry_album_song_create_list'), + path('lihat_detail_lagu//', lihat_detail_lagu, name='lihat_detail_lagu'), +] diff --git a/album_song_royalti/views.py b/album_song_royalti/views.py index 91ea44a..5f41c27 100644 --- a/album_song_royalti/views.py +++ b/album_song_royalti/views.py @@ -1,3 +1,830 @@ from django.shortcuts import render # Create your views here. +from django.shortcuts import render +from django.shortcuts import render, redirect +from django.contrib.auth import authenticate, login +from django.contrib import messages +import uuid +# from .forms import LoginForm -> ga usah pakai form langsung dari login.html aja(?) +import json +from django.db import connection +# from connect_postgres import execute_sql_query +from django.shortcuts import render, redirect +from django.contrib.auth.decorators import login_required +from django.http import HttpResponse, JsonResponse,HttpResponseRedirect +import datetime +import uuid +from django.views.decorators.csrf import csrf_exempt +from django.contrib import messages +from django.contrib.auth.hashers import check_password +from django.urls import reverse +import psycopg2 +from django.shortcuts import render, redirect +from django.contrib import messages +from django.db import connection + + +# #CREATE ALBUM -> butuh masukkin judul isian, dan dropdown label (fetch semua label yang terdaftar di marmut) +# def get_labels(): +# with connection.cursor() as cursor: +# cursor.execute("SELECT id, name FROM marmut_label") +# labels = cursor.fetchall() +# return [{'id': label[0], 'name': label[1]} for label in labels] + +# def create_album(request): +# if request.method == 'POST': +# judul = request.POST.get('judul') +# label_id = request.POST.get('label') +# album_id = str(uuid.uuid4()) +# with connection.cursor() as cursor: +# cursor.execute(""" +# INSERT INTO marmut_album (id, judul, label_id) +# VALUES (%s, %s, %s) +# """, [album_id, judul, label_id]) +# #cek lagi yang relate dengan table album -> song ga relate karena kan bisa aja albumnya kosong dulu -> jumlah lagunya 0 misalnya +# # +# return redirect(reverse('success_create_album')) + +# labels = get_labels() +# return render(request, 'create_album.html', {'labels': labels}) + + +# def success_create_album(request): +# return HttpResponse("Album anda berhasil dibuat! Terus berkarya") + + +# #LIST_ALBUM VIEWS +# def get_albums(): +# with connection.cursor() as cursor: +# cursor.execute(""" +# SELECT a.id, a.judul, l.name as label_name, +# COUNT(s.id) as jumlah_lagu, +# COALESCE(SUM(s.durasi), 0) as total_durasi +# FROM marmut_album a +# LEFT JOIN marmut_label l ON a.label_id = l.id +# LEFT JOIN marmut_song s ON a.id = s.album_id +# GROUP BY a.id, a.judul, l.name +# """) +# albums = cursor.fetchall() +# return [{ +# 'id': album[0], +# 'judul': album[1], +# 'label_name': album[2], +# 'jumlah_lagu': album[3], +# 'total_durasi': album[4] +# } for album in albums] + +# def list_album(request): +# albums = get_albums() #ambil semua album +# return render(request, 'list_album.html', {'albums': albums}) + +# def hapus_album(request, album_id): +# if request.method == 'POST': +# with connection.cursor() as cursor: +# cursor.execute("DELETE FROM marmut_album WHERE id = %s", [album_id]) +# return redirect(reverse('list_album')) +# #function get album by id bisa untuk list album dan untuk list lagu di suatu album +# def get_album_by_id(album_id): +# with connection.cursor() as cursor: +# cursor.execute("SELECT id, judul FROM marmut_album WHERE id = %s", [album_id]) +# album = cursor.fetchone() +# return {'id': album[0], 'judul': album[1]} if album else None + +# #lanjutan dari list_album views + + +# #create_lagu views +# #ambil bedasarkanalbum yang diklik -> di album : nama album + + + +# def get_artists(): +# with connection.cursor() as cursor: +# cursor.execute("SELECT id, name FROM marmut_artist") +# artists = cursor.fetchall() +# return [{'id': artist[0], 'name': artist[1]} for artist in artists] + +# def get_songwriters(): +# with connection.cursor() as cursor: +# cursor.execute("SELECT id, name FROM marmut_songwriter") +# songwriters = cursor.fetchall() +# return [{'id': songwriter[0], 'name': songwriter[1]} for songwriter in songwriters] + +# def get_genres(): +# with connection.cursor() as cursor: +# cursor.execute("SELECT id, name FROM marmut_genre") +# genres = cursor.fetchall() +# return [{'id': genre[0], 'name': genre[1]} for genre in genres] + +# def create_lagu(request): +# user_data = request.session.get('user_data', {}) +# is_artist = user_data.get('is_artist', False) +# is_songwriter = user_data.get('is_songwriter', False) +# user_artist_id = user_data.get('artist_id', None) +# user_songwriter_id = user_data.get('songwriter_id', None) + +# if request.method == 'POST': +# album_id = request.POST.get('album') +# judul = request.POST.get('judul') +# artist_id = user_artist_id if is_artist else request.POST.get('artist') +# songwriters = request.POST.getlist('songwriters') +# genres = request.POST.getlist('genres') +# durasi = request.POST.get('durasi') +# song_id = str(uuid.uuid4()) + +# with connection.cursor() as cursor: +# cursor.execute(""" +# INSERT INTO marmut_song (id, judul, artist_id, album_id, durasi) +# VALUES (%s, %s, %s, %s, %s) +# """, [song_id, judul, artist_id, album_id, durasi]) + +# for songwriter_id in songwriters: +# cursor.execute(""" +# INSERT INTO marmut_songwriter_write_song (songwriter_id, song_id) +# VALUES (%s, %s) +# """, [songwriter_id, song_id]) + +# for genre_id in genres: +# cursor.execute(""" +# INSERT INTO marmut_song_genre (song_id, genre_id) +# VALUES (%s, %s) +# """, [song_id, genre_id]) + +# return redirect(reverse('success')) + +# albums = get_albums() +# artists = get_artists() if is_songwriter else [] +# songwriters = get_songwriters() +# genres = get_genres() + +# context = { +# 'albums': albums, +# 'artists': artists, +# 'songwriters': songwriters, +# 'genres': genres, +# 'is_artist': is_artist, +# 'is_songwriter': is_songwriter, +# 'user_artist_id': user_artist_id, +# 'user_songwriter_id': user_songwriter_id, +# } + +# return render(request, 'create_lagu.html', context) + +# #list lagu views + +# from django.shortcuts import render, redirect, get_object_or_404 +# from django.urls import reverse +# from django.db import connection +# from django.http import HttpResponse + +# def get_album_by_id(album_id): +# with connection.cursor() as cursor: +# cursor.execute("SELECT id, judul FROM marmut_album WHERE id = %s", [album_id]) +# album = cursor.fetchone() +# return {'id': album[0], 'judul': album[1]} if album else None + +# def get_lagu_by_album_id(album_id): +# with connection.cursor() as cursor: +# cursor.execute(""" +# SELECT id, judul, durasi, total_play, total_download +# FROM marmut_song +# WHERE album_id = %s +# """, [album_id]) +# lagu_list = cursor.fetchall() +# return [{ +# 'id': lagu[0], +# 'judul': lagu[1], +# 'durasi': lagu[2], +# 'total_play': lagu[3], +# 'total_download': lagu[4] +# } for lagu in lagu_list] + +# def list_lagu(request, album_id): +# album = get_album_by_id(album_id) +# if not album: +# return HttpResponse("Album not found", status=404) + +# lagu_list = get_lagu_by_album_id(album_id) + +# context = { +# 'album': album, +# 'lagu_list': lagu_list +# } +# return render(request, 'list_lagu.html', context) + +# def hapus_lagu(request, lagu_id): +# if request.method == 'POST': +# with connection.cursor() as cursor: +# cursor.execute("DELETE FROM marmut_song WHERE id = %s", [lagu_id]) +# return redirect(request.META.get('HTTP_REFERER', 'redirect_if_referer_not_found')) +# return HttpResponse(status=405) + +# def lihat_detail(request, lagu_id): +# with connection.cursor() as cursor: +# cursor.execute(""" +# SELECT id, judul, durasi, total_play, total_download, artist_id +# FROM marmut_song +# WHERE id = %s +# """, [lagu_id]) +# lagu = cursor.fetchone() + +# if not lagu: +# return HttpResponse("Lagu not found", status=404) + +# context = { +# 'lagu': { +# 'id': lagu[0], +# 'judul': lagu[1], +# 'durasi': lagu[2], +# 'total_play': lagu[3], +# 'total_download': lagu[4], +# 'artist_id': lagu[5] +# } +# } +# return render(request, 'lihat_detail.html', context) + + +#CEK_ROYALTI views.py +def cek_royalti(request): + # Raw query to retrieve royalty information + user_data = request.session.get('user_data', {}) + user_email = user_data.get('email', '') + + #semuanya -> label, songwriter, dan artist -> ada pemilih hak cipta kan + #cari terlebih dahulu id pemilik_hak_ciptanya + #if is_label -> cari dari table label + if user_data['is_label']: + with connection.cursor() as cursor: + cursor.execute(""" + SELECT id FROM marmut.label WHERE email = %s + """, [user_email]) + label_hak_cipta_id = cursor.fetchall()['id_pemilik_hak_cipta'] + #if is_artist -> cari dari table artist + if user_data['is_artist']: + with connection.cursor() as cursor: + cursor.execute(""" + SELECT id FROM marmut.artist WHERE email_akun = %s + """, [user_email]) + artist_hak_cipta_id = cursor.fetchall()['id_pemilik_hak_cipta'] + #if is_songwriter -> cari dari table songwriter + if user_data['is_songwriter']: + with connection.cursor() as cursor: + cursor.execute(""" + SELECT id FROM marmut.songwriter WHERE email_akun = %s + """, [user_email]) + songwriter_hak_cipta_id = cursor.fetchall()['id_pemilik_hak_cipta'] + + #krn bisa multiple role -> berarti di html pakai as artist , or as sonrgwritre, dan seterunsya + #ambil dulu sebagai label + if user_data['is_artist']: + with connection.cursor() as cursor: + cursor.execute(""" + SELECT + S.judul AS JudulLagu, + A.judul AS JudulAlbum, + S.total_play AS TotalPlay, + S.total_download AS TotalDownload, + (S.total_play * PH.rate_royalti) AS TotalRoyalti + FROM + SONG AS S + JOIN + ALBUM AS A ON S.id_album = A.id + JOIN + ARTIST AS AR ON S.id_artist = AR.id + JOIN + PEMILIK_HAK_CIPTA AS PH ON AR.id_pemilik_hak_cipta = PH.id + WHERE + AR.email_akun = %s + + """, [user_email]) + royalti_artist = cursor.fetchall() + for row in royalti_artist: + id_song = row[0] + id_pemilik_hak_cipta = row[1] + total_royalti = row[2] + + cursor.execute(""" + UPDATE ROYALTI + SET jumlah = %s + WHERE id_pemilik_hak_cipta = %s AND id_song = %s + """, [total_royalti, id_pemilik_hak_cipta, id_song]) + + #if is_songwriter + if user_data['is_songwriter']: + with connection.cursor() as cursor: + cursor.execute(""" + SELECT + S.judul AS JudulLagu, + A.judul AS JudulAlbum, + S.total_play AS TotalPlay, + S.total_download AS TotalDownload, + (S.total_play * PH.rate_royalti) AS TotalRoyalti + FROM + SONG AS S + JOIN + ALBUM AS A ON S.id_album = A.id + JOIN + SONGWRITER AS AR ON S.id_artist = AR.id + JOIN + PEMILIK_HAK_CIPTA AS PH ON AR.id_pemilik_hak_cipta = PH.id + WHERE + AR.email_akun = %s + + """, [user_email]) + royalti_songwriter = cursor.fetchall() + for row in royalti_songwriter: + id_song = row[0] + id_pemilik_hak_cipta = row[1] + total_royalti = row[2] + + cursor.execute(""" + UPDATE ROYALTI + SET jumlah = %s + WHERE id_pemilik_hak_cipta = %s AND id_song = %s + """, [total_royalti, id_pemilik_hak_cipta, id_song]) + context = { + 'royalti_list': royalti_artist + } + + #if is_songwriter + if user_data['is_label']: + with connection.cursor() as cursor: + cursor.execute(""" + SELECT + S.judul AS JudulLagu, + A.judul AS JudulAlbum, + S.total_play AS TotalPlay, + S.total_download AS TotalDownload, + (S.total_play * PH.rate_royalti) AS TotalRoyalti + FROM + SONG AS S + JOIN + ALBUM AS A ON S.id_album = A.id + JOIN + SONGWRITER AS AR ON S.id_artist = AR.id + JOIN + PEMILIK_HAK_CIPTA AS PH ON AR.id_pemilik_hak_cipta = PH.id + WHERE + AR.email_akun = %s + + """, [user_email]) + royalti_label = cursor.fetchall() + for row in royalti_label: + id_song = row[0] + id_pemilik_hak_cipta = row[1] + total_royalti = row[2] + + cursor.execute(""" + UPDATE ROYALTI + SET jumlah = %s + WHERE id_pemilik_hak_cipta = %s AND id_song = %s + """, [total_royalti, id_pemilik_hak_cipta, id_song]) + context = { + 'royalti_list': royalti_artist + } + return render(request, 'cek_royalti.html', context) + +# SET SEARCH_PATH TO MARMUT; +# SELECT a.judul AS JudulLagu, A.judul AS JudulAlbum, S.total_play AS TotalPlay, +# S.total_download AS TotalDownload, +# (CAST(S.total_play AS NUMERIC) * CAST(PH.rate_royalti AS NUMERIC)) AS TotalRoyalti +# FROM SONG AS S +# JOIN ALBUM AS A ON S.id_album = A.id +# JOIN ARTIST AS AR ON S.id_artist = AR.id +# JOIN PEMILIK_HAK_CIPTA AS PH ON AR.id_pemilik_hak_cipta = PH.id +# WHERE AR.email_akun = %s + + + +from django.shortcuts import render, redirect, get_object_or_404 +from django.http import HttpResponse +from django.db import connection +from django.urls import reverse +import uuid + +def list_album(request): + user_data = request.session.get('user_data', {}) + is_label = user_data.get('is_label', False) + user_email = user_data.get('email', None) + + if not is_label: + return HttpResponse("You are not authorized to access this page", status=403) + + #ambil id label dari email + with connection.cursor() as cursor: + cursor.execute("SELECT id FROM marmut.label WHERE email = %s", [user_email]) + label_id = cursor.fetchone()[0] + + with connection.cursor() as cursor: + cursor.execute(""" + SELECT + ALBUM.id, + ALBUM.judul, + ALBUM.jumlah_lagu, + ALBUM.total_durasi + FROM + marmut.ALBUM + JOIN + marmut.LABEL ON ALBUM.id_label = LABEL.id + WHERE + LABEL.id = %s; + """, [label_id]) + album_list = cursor.fetchall() + + context = { + 'album_list': [{ + 'id': album[0], + 'judul': album[1], + 'jumlah_lagu': album[2], + 'total_durasi': album[3] + } for album in album_list] + } + return render(request, 'list_album.html', context) + +def list_album_artist(request): + user_data = request.session.get('user_data', {}) + email = user_data.get('email', None) + is_artist = user_data.get('is_artist', False) + is_songwriter = user_data.get('is_songwriter', False) + is_label = user_data.get('is_label', False) + + if not (is_artist or is_songwriter or is_label): + return HttpResponse("You are not authorized to access this page", status=403) + + album_list_songwriter = [] + album_list_artist = [] + + if is_songwriter: + with connection.cursor() as cursor: + cursor.execute(""" + SET SEARCH_PATH TO MARMUT; + SELECT a.id, a.judul, a.jumlah_lagu, a.total_durasi, l.nama + FROM songwriter sw + JOIN songwriter_write_song sws ON sw.id = sws.id_songwriter + JOIN song s ON sws.id_song = s.id_konten + JOIN album a ON s.id_album = a.id + JOIN label l ON a.id_label = l.id + WHERE sw.email_akun = %s + """, [email]) + album_list_songwriter = cursor.fetchall() + + if is_artist: + with connection.cursor() as cursor: + cursor.execute(""" + SET SEARCH_PATH TO MARMUT; + SELECT DISTINCT a.id, a.judul, a.jumlah_lagu, a.total_durasi, l.nama + FROM artist ar + JOIN song s ON ar.id = s.id_artist + JOIN album a ON s.id_album = a.id + JOIN label l ON a.id_label = l.id + WHERE ar.email_akun = %s + """, [email]) + album_list_artist = cursor.fetchall() + + context = { + 'album_list_songwriter': [{ + 'id': album[0], + 'judul': album[1], + 'jumlah_lagu': album[2], + 'total_durasi': album[3], + 'label': album[4] + } for album in album_list_songwriter], + 'album_list_artist': [{ + 'id': album[0], + 'judul': album[1], + 'jumlah_lagu': album[2], + 'total_durasi': album[3], + 'label': album[4] + } for album in album_list_artist] + } + return render(request, 'list_album_artist.html', context) + + + +def daftar_lagu(request, album_id): + with connection.cursor() as cursor: + #cursor.execute("SELECT id_konten, judul, durasi, total_play, total_download FROM marmut.song WHERE id_album = %s", [album_id]) + cursor.execute("""SELECT id_konten, k.judul, k.durasi, total_play, total_download + FROM marmut.song + JOIN marmut.konten k ON song.id_konten = k.id + WHERE id_album = %s """, [album_id]) + + song_list = cursor.fetchall() + + cursor.execute("SELECT judul FROM marmut.album WHERE id = %s", [album_id]) + album = cursor.fetchone() + + context = { + 'album': {'judul': album[0]}, + 'song_list': [{ + 'id': song[0], + 'judul': song[1], + 'durasi': song[2], + 'total_play': song[3], + 'total_download': song[4] + } for song in song_list] + } + return render(request, 'daftar_lagu.html', context) +def lihat_detail_lagu(request, song_id): + with connection.cursor() as cursor: + cursor.execute(""" + SELECT id_konten, judul, durasi, total_play, total_download + FROM marmut.song + JOIN marmut.konten ON song.id_konten = konten.id + WHERE id_konten = %s + """, [song_id]) + song = cursor.fetchone() + + if not song: + return HttpResponse("Lagu not found", status=404) + + context = { + 'song': { + 'id': song[0], + 'judul': song[1], + 'durasi': song[2], + 'total_play': song[3], + 'total_download': song[4] + } + } + return render(request, 'lihat_detail_lagu.html', context) + +#BATASSSSSSS +#BATASSSSSS + + +def create_album(request): + user_data = request.session.get('user_data', {}) + email = user_data.get('email', None) + + if request.method == "POST": + #print(request.POST) + for a in request.POST: + print(a, request.POST[a]) + judul_album = request.POST.get('judul_album') + label_str = request.POST.get('label') + label_id = label_str[13:49] + judul_lagu = request.POST.get('judul_lagu') + artists = request.POST.get('artist') + print(artists) + songwriters = request.POST.getlist('songwriter[]') + genres = request.POST.getlist('genre[]') + durasi = request.POST.get('durasi') + #ambil tanggal sekarang + tanggal_rilis = datetime.datetime.now() + tahun = tanggal_rilis.year + + + + #carik di artist_id pakai query dah + with connection.cursor() as cursor: + cursor.execute("SELECT id FROM marmut.artist WHERE email_akun = %s", [artists]) + artist_id = cursor.fetchone()[0] + + print(artist_id) + + genre_masuk = [] + #isinya nomor idnya + for genre in genres: + print(genre) + with connection.cursor() as cursor: + cursor.execute("SELECT DISTINCT genre FROM marmut.genre") + ada_genre = cursor.fetchall() + ada_genre = ada_genre[int(genre)] + ada_genre_2 = ada_genre[0] + genre_masuk.append(ada_genre_2) + + + + #ambil dari nomor genre ke query + print(songwriters) + if user_data['is_songwriter']: + with connection.cursor() as cursor: + cursor.execute("SELECT DISTINCT id FROM marmut.songwriter WHERE email_akun = %s", (email,)) + songwriter_orangnya = cursor.fetchall() + songwriters.append(str(songwriter_orangnya[0][0])) + songwriter_ids = [songwriter for songwriter in songwriters] + + + #sekarnag bagian insert data ke database + album_id = str(uuid.uuid4()) + song_id = str(uuid.uuid4()) + with connection.cursor() as cursor: + cursor.execute("INSERT INTO marmut.konten (id, judul, tanggal_rilis, tahun, durasi) VALUES (%s, %s, %s, %s, %s)", [song_id, judul_lagu, tanggal_rilis, tahun, durasi]) + cursor.execute("INSERT INTO marmut.album (id, judul, jumlah_lagu, id_label, total_durasi) VALUES (%s, %s, %s, %s, %s)", [album_id, judul_album, 1, label_id, int(durasi)]) + cursor.execute("INSERT INTO marmut.song (id_konten, id_artist, id_album) VALUES (%s, %s, %s)", [song_id, artist_id, album_id]) + for genre_id in genre_masuk: + cursor.execute("INSERT INTO marmut.genre (id_konten, genre) VALUES (%s, %s)", [song_id, genre_id]) + for songwriter_id in songwriter_ids: + cursor.execute("INSERT INTO marmut.songwriter_write_song (id_songwriter, id_song) VALUES (%s, %s)", [songwriter_id, song_id]) + + + #NEXT HABIS INI KAYAKNYA AMBIL SEMUA SYANG BISA PUNYA ROYALTI DAH SEPERTI ARTIST, LABEL, SONGWRITER + # TAPI MASALAHNYA RIYALTI NYA GA TAU BERAPAAN + #return HttpResponse(f'Album {judul_album} berhasil dibuat dengan artist: {label_str}{(artists)}, songwriters: {", ".join(songwriters)}, genres: {", ".join(genres)}, durasi: {durasi} menit.') + #return ke list album + return HttpResponseRedirect(reverse('list_album_artist')) + #ambil labels dulu dari database, sekalian dengan key nya + with connection.cursor() as cursor: + cursor.execute("SELECT id, nama FROM marmut.label") + labels = cursor.fetchall() + #petakan ke dictionary + labels = [{'id': label[0], 'nama': label[1]} for label in labels] + + cursor.execute("SELECT id, email_akun FROM marmut.artist") + artists = cursor.fetchall() + #petakan ke dictionary + artists = [{'id': artist[0], 'email_akun': artist[1]} for artist in artists] + + + cursor.execute("SELECT id, email_akun FROM marmut.songwriter WHERE email_akun != %s", (email,)) + songwriters = cursor.fetchall() + #petakan ke dictionary + songwriters = [{'id': songwriter[0], 'email_akun': songwriter[1]} for songwriter in songwriters] + + cursor.execute("SELECT DISTINCT genre FROM marmut.genre") + genres = cursor.fetchall() + #petakan ke dictionary -> enumparate + genres = [{'id': idx, 'genre': genre[0]} for idx, genre in enumerate(genres)] + + print(genres) + print(labels) + print(songwriters) + print(artists) + + + + + + return render(request, 'create_album.html', { + 'labels': labels, + 'artists': artists, + 'songwriters': songwriters, + 'genres': genres, + }) + +def create_lagu(request, album_id): + user_data = request.session.get('user_data', {}) + is_artist = user_data.get('is_artist', False) + is_songwriter = user_data.get('is_songwriter', False) + email = user_data.get('email', None) + album_id = album_id + print("album idnya ") + print(album_id) + with connection.cursor() as cursor: + cursor.execute("SELECT judul FROM marmut.album WHERE id = %s", [album_id]) + judul_album = cursor.fetchone()[0] + + #label ambil dari database + with connection.cursor() as cursor: + cursor.execute("SELECT label.id, nama FROM marmut.label JOIN marmut.album ON label.id = album.id_label WHERE album.id = %s", [album_id]) + labels = cursor.fetchall() + #petakan ke dictionary + labels = [{'id': label[0], 'nama': label[1]} for label in labels] + + label_id = labels[0]['id'] + if request.method == "POST": + #print(request.POST) + for a in request.POST: + print(a, request.POST[a]) + #ambil judul album dari database dari album_id + + + judul_lagu = request.POST.get('judul_lagu') + artists = request.POST.get('artist') + print(artists) + songwriters = request.POST.getlist('songwriter[]') + genres = request.POST.getlist('genre[]') + durasi = request.POST.get('durasi') + #ambil tanggal sekarang + tanggal_rilis = datetime.datetime.now() + tahun = tanggal_rilis.year + + + + #carik di artist_id pakai query dah + with connection.cursor() as cursor: + cursor.execute("SELECT id FROM marmut.artist WHERE email_akun = %s", [artists]) + artist_id = cursor.fetchone()[0] + + print(artist_id) + + genre_masuk = [] + #isinya nomor idnya + for genre in genres: + print(genre) + with connection.cursor() as cursor: + cursor.execute("SELECT DISTINCT genre FROM marmut.genre") + ada_genre = cursor.fetchall() + ada_genre = ada_genre[int(genre)] + ada_genre_2 = ada_genre[0] + genre_masuk.append(ada_genre_2) + + + + #ambil dari nomor genre ke query + print(songwriters) + if user_data['is_songwriter']: + with connection.cursor() as cursor: + cursor.execute("SELECT DISTINCT id FROM marmut.songwriter WHERE email_akun = %s", (email,)) + songwriter_orangnya = cursor.fetchall() + songwriters.append(str(songwriter_orangnya[0][0])) + songwriter_ids = [songwriter for songwriter in songwriters] + + + #sekarnag bagian insert data ke database + + song_id = str(uuid.uuid4()) + with connection.cursor() as cursor: + cursor.execute("INSERT INTO marmut.konten (id, judul, tanggal_rilis, tahun, durasi) VALUES (%s, %s, %s, %s, %s)", [song_id, judul_lagu, tanggal_rilis, tahun, durasi]) + # cursor.execute("INSERT INTO marmut.album (id, judul, jumlah_lagu, id_label, total_durasi) VALUES (%s, %s, %s, %s, %s)", [album_id, judul_album, 1, label_id, int(durasi)]) + cursor.execute("INSERT INTO marmut.song (id_konten, id_artist, id_album) VALUES (%s, %s, %s)", [song_id, artist_id, album_id]) + for genre_id in genre_masuk: + cursor.execute("INSERT INTO marmut.genre (id_konten, genre) VALUES (%s, %s)", [song_id, genre_id]) + for songwriter_id in songwriter_ids: + cursor.execute("INSERT INTO marmut.songwriter_write_song (id_songwriter, id_song) VALUES (%s, %s)", [songwriter_id, song_id]) + + + #NEXT HABIS INI KAYAKNYA AMBIL SEMUA SYANG BISA PUNYA ROYALTI DAH SEPERTI ARTIST, LABEL, SONGWRITER + # TAPI MASALAHNYA RIYALTI NYA GA TAU BERAPAAN + #return HttpResponse(f'Album {judul_album} berhasil dibuat dengan artist: {label_str}{(artists)}, songwriters: {", ".join(songwriters)}, genres: {", ".join(genres)}, durasi: {durasi} menit.') + return redirect('list_album_artist') + + # return redirect(reverse('list_album_artist')) + + #ambil labels dulu dari database, sekalian dengan key nya + with connection.cursor() as cursor: + cursor.execute("SELECT id, nama FROM marmut.label") + labels = cursor.fetchall() + #petakan ke dictionary + labels = [{'id': label[0], 'nama': label[1]} for label in labels] + + cursor.execute("SELECT id, email_akun FROM marmut.artist") + artists = cursor.fetchall() + #petakan ke dictionary + artists = [{'id': artist[0], 'email_akun': artist[1]} for artist in artists] + + + cursor.execute("SELECT id, email_akun FROM marmut.songwriter WHERE email_akun != %s", (email,)) + songwriters = cursor.fetchall() + #petakan ke dictionary + songwriters = [{'id': songwriter[0], 'email_akun': songwriter[1]} for songwriter in songwriters] + + cursor.execute("SELECT DISTINCT genre FROM marmut.genre") + genres = cursor.fetchall() + #petakan ke dictionary -> enumparate + genres = [{'id': idx, 'genre': genre[0]} for idx, genre in enumerate(genres)] + + print(genres) + print(labels) + print(songwriters) + print(artists) + return render(request, 'create_lagu.html', { + 'album_id' : album_id, + 'judul_album': judul_album, + 'labels': labels, + 'artists': artists, + 'songwriters': songwriters, + 'genres': genres, + }) + + + + + + + + + + +def hapus_album(request, album_id): + + with connection.cursor() as cursor: + cursor.execute("DELETE FROM marmut.album WHERE id = %s", [album_id]) + return redirect(reverse('list_album_artist') if 'is_artist' in request.session['user_data'] or 'is_songwriter' in request.session['user_data'] else 'list_album') + +def hapus_lagu(request, song_id): + with connection.cursor() as cursor: + cursor.execute("DELETE FROM marmut.song WHERE id_konten = %s", [song_id]) + return redirect(request.META.get('HTTP_REFERER', 'redirect_if_referer_not_found')) + + +def entry_album_song_create_list(request): + return render(request, 'entry_album_song_create_list.html') + + +#tes +from django.shortcuts import render +from django.http import HttpResponse + +def index(request): + return render(request, 'multiselect_form.html') + +def submit(request): + if request.method == 'POST': + selected_names = request.POST.getlist('names') + print("nama yang dipilih") + print(selected_names) + return HttpResponse(f'Selected names: {", ".join(selected_names)}') + return HttpResponse("No data submitted.") diff --git a/auth/views.py b/auth/views.py index e488112..7087146 100644 --- a/auth/views.py +++ b/auth/views.py @@ -1,439 +1,439 @@ -from django.shortcuts import render, redirect -from django.contrib.auth import authenticate, login -from django.contrib import messages -# from .forms import LoginForm -> ga usah pakai form langsung dari login.html aja(?) -import json -from django.db import connection -from connect_postgres import execute_sql_query -from django.shortcuts import render, redirect -from django.http import JsonResponse,HttpResponseRedirect -import datetime -import uuid -from django.views.decorators.csrf import csrf_exempt -from django.contrib import messages -from django.contrib.auth.hashers import check_password -from django.urls import reverse -import psycopg2 - -def show_home(request): - return render(request, "home.html") - -def show_register(request): - return render(request, "register.html") - -def show_login(request): - return render(request, "login.html") -#next blm ganti - -def list_tables(request): - with connection.cursor() as cursor: - cursor.execute("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';") - tables = cursor.fetchall() - table_list = [table[0] for table in tables] # Extract table names from tuples - return render(request, ''auth/list_tables.html'', {'tables': table_list}) - -@csrf_exempt -def logout_with_postgres(request): - # Hapus data sesi pengguna - if 'user_data' in request.session: - del request.session['user_data'] +# from django.shortcuts import render, redirect +# from django.contrib.auth import authenticate, login +# from django.contrib import messages +# # from .forms import LoginForm -> ga usah pakai form langsung dari login.html aja(?) +# import json +# from django.db import connection +# from connect_postgres import execute_sql_query +# from django.shortcuts import render, redirect +# from django.http import JsonResponse,HttpResponseRedirect +# import datetime +# import uuid +# from django.views.decorators.csrf import csrf_exempt +# from django.contrib import messages +# from django.contrib.auth.hashers import check_password +# from django.urls import reverse +# import psycopg2 + +# def show_home(request): +# return render(request, "home.html") + +# def show_register(request): +# return render(request, "register.html") + +# def show_login(request): +# return render(request, "login.html") +# #next blm ganti + +# # def list_tables(request): +# # with connection.cursor() as cursor: +# # cursor.execute("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';") +# # tables = cursor.fetchall() +# # table_list = [table[0] for table in tables] # Extract table names from tuples +# # return render(request, ''auth/list_tables.html'', {'tables': table_list}) + +# @csrf_exempt +# def logout_with_postgres(request): +# # Hapus data sesi pengguna +# if 'user_data' in request.session: +# del request.session['user_data'] - # Lakukan logout pengguna menggunakan fungsi bawaan Django +# # Lakukan logout pengguna menggunakan fungsi bawaan Django - # Redirect ke halaman login atau halaman lain yang sesuai - return redirect('home') #based dari nama yang dibentuk di urls.py - -@csrf_exempt -def register_with_postgres(request): - if request.method == 'POST': - # SAMA --------------------------- - email = request.POST.get('email') - password = request.POST.get('password') - confirm_password = request.POST.get('confirm_password') - fname = request.POST.get('fname') - lname = request.POST.get('lname') - phone_num = request.POST.get('phone_num') - # SAMA ------------------------------------- - # HANYA CUSTOMER --------------------------- - nik = request.POST.get('nik') - # HANYA HOTEL ------------------------------ - hotel_name = request.POST.get('hotel_name') - hotel_branch = request.POST.get('hotel_branch') - nib = request.POST.get('nib') - star = request.POST.get('star') - street = request.POST.get('street') - district = request.POST.get('district') - city = request.POST.get('city') - province = request.POST.get('province') - description = request.POST.get('description') - min_checkout = request.POST.get('min_checkout') - max_checkout = request.POST.get('max_checkout') - print(hotel_name) - - # CEK REGISTER CUSTOMER ATAU HOTEL - is_customer = True if nik is not None else False - - # CEK CUSTOMER - if is_customer and not all([email.strip(), password.strip(), confirm_password.strip(), fname.strip(), lname.strip(), nik.strip(), phone_num.strip()]): - messages.error(request, 'Mohon lengkapi field yang kosong dalam mendaftarkan customer.') - # CEK HOTEL - elif not is_customer and not all([email.strip(), password.strip(), - confirm_password.strip(), fname.strip(), lname.strip(), - hotel_name.strip(), hotel_branch.strip(), nib.strip(), star, - street.strip(),district.strip(),city.strip(), - province.strip(), description.strip(), - min_checkout.strip(), max_checkout.strip(), phone_num.strip()]): - messages.error(request, 'Mohon lengkapi field yang kosong dalam mendaftarkan hotel.') - # CEK BINTANG - elif not is_customer and not star.isdigit(): - messages.error(request, 'Maaf, bintang hotel harus bilangan bulat.') - # CEK RANGE BINTANG - elif not is_customer and (float(star) < 1 or float(star) > 5): - messages.error(request, 'Maaf, bintang hotel harus ada di range 1 sampai 5.') - # CEK PASSWORD - elif password != confirm_password: - messages.error(request, 'Password dan konfirmasi password tidak cocok.') - else: - if is_customer: - query= f""" - - INSERT INTO sistel.user (email, password, fname, lname) VALUES ('{email}','{password}', '{fname}', '{lname}'); - INSERT INTO reservation_actor (email, phonenum) VALUES ('{email}','{phone_num}'); - INSERT INTO customer (email, nik) VALUES ('{email}','{nik}') - RETURNING email; +# # Redirect ke halaman login atau halaman lain yang sesuai +# return redirect('home') #based dari nama yang dibentuk di urls.py + +# @csrf_exempt +# def register_with_postgres(request): +# if request.method == 'POST': +# # SAMA --------------------------- +# email = request.POST.get('email') +# password = request.POST.get('password') +# confirm_password = request.POST.get('confirm_password') +# fname = request.POST.get('fname') +# lname = request.POST.get('lname') +# phone_num = request.POST.get('phone_num') +# # SAMA ------------------------------------- +# # HANYA CUSTOMER --------------------------- +# nik = request.POST.get('nik') +# # HANYA HOTEL ------------------------------ +# hotel_name = request.POST.get('hotel_name') +# hotel_branch = request.POST.get('hotel_branch') +# nib = request.POST.get('nib') +# star = request.POST.get('star') +# street = request.POST.get('street') +# district = request.POST.get('district') +# city = request.POST.get('city') +# province = request.POST.get('province') +# description = request.POST.get('description') +# min_checkout = request.POST.get('min_checkout') +# max_checkout = request.POST.get('max_checkout') +# print(hotel_name) + +# # CEK REGISTER CUSTOMER ATAU HOTEL +# is_customer = True if nik is not None else False + +# # CEK CUSTOMER +# if is_customer and not all([email.strip(), password.strip(), confirm_password.strip(), fname.strip(), lname.strip(), nik.strip(), phone_num.strip()]): +# messages.error(request, 'Mohon lengkapi field yang kosong dalam mendaftarkan customer.') +# # CEK HOTEL +# elif not is_customer and not all([email.strip(), password.strip(), +# confirm_password.strip(), fname.strip(), lname.strip(), +# hotel_name.strip(), hotel_branch.strip(), nib.strip(), star, +# street.strip(),district.strip(),city.strip(), +# province.strip(), description.strip(), +# min_checkout.strip(), max_checkout.strip(), phone_num.strip()]): +# messages.error(request, 'Mohon lengkapi field yang kosong dalam mendaftarkan hotel.') +# # CEK BINTANG +# elif not is_customer and not star.isdigit(): +# messages.error(request, 'Maaf, bintang hotel harus bilangan bulat.') +# # CEK RANGE BINTANG +# elif not is_customer and (float(star) < 1 or float(star) > 5): +# messages.error(request, 'Maaf, bintang hotel harus ada di range 1 sampai 5.') +# # CEK PASSWORD +# elif password != confirm_password: +# messages.error(request, 'Password dan konfirmasi password tidak cocok.') +# else: +# if is_customer: +# query= f""" + +# INSERT INTO sistel.user (email, password, fname, lname) VALUES ('{email}','{password}', '{fname}', '{lname}'); +# INSERT INTO reservation_actor (email, phonenum) VALUES ('{email}','{phone_num}'); +# INSERT INTO customer (email, nik) VALUES ('{email}','{nik}') +# RETURNING email; - """ - else: - query = f""" - INSERT INTO sistel.user (email, password, fname, lname) VALUES ('{email}','{password}', '{fname}', '{lname}'); - INSERT INTO reservation_actor (email, phonenum) VALUES ('{email}','{phone_num}'); - INSERT INTO hotel - (email, hotel_name, hotel_branch, nib, star, street, district, city, - province, description, max_checkout, min_checkout) VALUES ( - '{email}', '{hotel_name}', '{hotel_branch}', '{nib}', - {star}, '{street}', '{district}', '{city}', '{province}', - '{description}', '{max_checkout}', '{min_checkout}' - ) - RETURNING email; - - """ - try: - execute_sql_query(query=query) - return HttpResponseRedirect('/login/') - except psycopg2.Error as error: - messages.error(request, f'{error}') - except Exception as error: - messages.error(request, f'{error}') - return render(request,"register.html") +# """ +# else: +# query = f""" +# INSERT INTO sistel.user (email, password, fname, lname) VALUES ('{email}','{password}', '{fname}', '{lname}'); +# INSERT INTO reservation_actor (email, phonenum) VALUES ('{email}','{phone_num}'); +# INSERT INTO hotel +# (email, hotel_name, hotel_branch, nib, star, street, district, city, +# province, description, max_checkout, min_checkout) VALUES ( +# '{email}', '{hotel_name}', '{hotel_branch}', '{nib}', +# {star}, '{street}', '{district}', '{city}', '{province}', +# '{description}', '{max_checkout}', '{min_checkout}' +# ) +# RETURNING email; + +# """ +# try: +# execute_sql_query(query=query) +# return HttpResponseRedirect('/login/') +# except psycopg2.Error as error: +# messages.error(request, f'{error}') +# except Exception as error: +# messages.error(request, f'{error}') +# return render(request,"register.html") -#LOGINNNNNNNNNNN - # ketika masuk pertama kali berarti -> ada dua kemungkinan bisa label atau bisa saja pengguna . - # ketika masuk sebagai pengguna maka ada kombinasi dair 3 kemungkiann -> bisa podcaster artsit atau songwriter - # nah ini caranya denagn loop ke semua table terkait saja lalu pakekkan is untuk setiap - - - # is_user -> kalau dia ada di akun - # is_premium - # is_artist - # is_songwriter - # is_podcaster - # is_label - - #cek dulu apakah emailnya ada di akun (is_user jadi true kalau ada ) atau ada di table label (is_label jadi true kalau ada ) - # kalau misalnya ada ga ada di keduanya maka berikan mesage error pengguna tidak ditemukan. - - #kalau email ditemukan entah salah satu di table akun atau di table label - #maka cek apakah passwordnya benar -> kalau passwordnya benar - #kalau passwordnya salah berikan pesan error bahwa password salah - #kalau passwordnya benar lalu selanjutnya akan ke dashboard.html tetapi sebelumnya skenarionya speerti ini +# #LOGINNNNNNNNNNN +# # ketika masuk pertama kali berarti -> ada dua kemungkinan bisa label atau bisa saja pengguna . +# # ketika masuk sebagai pengguna maka ada kombinasi dair 3 kemungkiann -> bisa podcaster artsit atau songwriter +# # nah ini caranya denagn loop ke semua table terkait saja lalu pakekkan is untuk setiap + + +# # is_user -> kalau dia ada di akun +# # is_premium +# # is_artist +# # is_songwriter +# # is_podcaster +# # is_label + +# #cek dulu apakah emailnya ada di akun (is_user jadi true kalau ada ) atau ada di table label (is_label jadi true kalau ada ) +# # kalau misalnya ada ga ada di keduanya maka berikan mesage error pengguna tidak ditemukan. + +# #kalau email ditemukan entah salah satu di table akun atau di table label +# #maka cek apakah passwordnya benar -> kalau passwordnya benar +# #kalau passwordnya salah berikan pesan error bahwa password salah +# #kalau passwordnya benar lalu selanjutnya akan ke dashboard.html tetapi sebelumnya skenarionya speerti ini - #sekanrionya pasti salah satu entah is_user true atau is_label yang true - #kalau is_user true, ambil nama, email, kota asal, gender, tempat lahir, tanggal lahir yang dipunya user - #ini kayaknya ga ada hubungan dulu ke user premium atau ga -> tapi yg penting megang email bisa disearch dia premium atau ga - #nah ada role -> ini ntar diisi dengan is aja , kalau cmn is_user saja yg true maka jadi pengguna biasa, kalau yang lainnya ada - #is_podcaster gtgt masuk berarti nanti tinggal ditambhin aja di rolenya saja-> di kode htmlnya saja. (pakai if) +# #sekanrionya pasti salah satu entah is_user true atau is_label yang true +# #kalau is_user true, ambil nama, email, kota asal, gender, tempat lahir, tanggal lahir yang dipunya user +# #ini kayaknya ga ada hubungan dulu ke user premium atau ga -> tapi yg penting megang email bisa disearch dia premium atau ga +# #nah ada role -> ini ntar diisi dengan is aja , kalau cmn is_user saja yg true maka jadi pengguna biasa, kalau yang lainnya ada +# #is_podcaster gtgt masuk berarti nanti tinggal ditambhin aja di rolenya saja-> di kode htmlnya saja. (pakai if) - #kalau dia is_user nya true dan is_labelnya false, maka unutk isi tiap kemungkinan is - #kita cek apakah email user tersebut ada atau tidak di table artist, table songwriter, dan tabel podcaster - - - #kalau dia is_user false dan is_label true -> maka kita ambil nama, email, kontak, dan - #dan dari ambil id_label nya buat nanti mencari semua album yang id_label sama dengan label.id dari user yang log in ini. - #dan nanti di htmlnya ada menampilkan kode untuk nampilin album id ini -> next atau hmm buat views baru aja - #kalau ternyata id labelnya tidak ada di table album maka tampilan pesan nanti di htmlnya belum memproduksi album - -@csrf_exempt -def login_with_postgres(request): - is_premium = False - is_artist = False - is_songwriter = False - is_podcaster = False - is_label = False - - if request.method == 'POST': - email = request.POST.get('email') - password = request.POST.get('password') +# #kalau dia is_user nya true dan is_labelnya false, maka unutk isi tiap kemungkinan is +# #kita cek apakah email user tersebut ada atau tidak di table artist, table songwriter, dan tabel podcaster + + +# #kalau dia is_user false dan is_label true -> maka kita ambil nama, email, kontak, dan +# #dan dari ambil id_label nya buat nanti mencari semua album yang id_label sama dengan label.id dari user yang log in ini. +# #dan nanti di htmlnya ada menampilkan kode untuk nampilin album id ini -> next atau hmm buat views baru aja +# #kalau ternyata id labelnya tidak ada di table album maka tampilan pesan nanti di htmlnya belum memproduksi album + +# @csrf_exempt +# def login_with_postgres(request): +# is_premium = False +# is_artist = False +# is_songwriter = False +# is_podcaster = False +# is_label = False + +# if request.method == 'POST': +# email = request.POST.get('email') +# password = request.POST.get('password') - # Query untuk mencari pengguna berdasarkan email di tabel akun - query_akun = f""" - SELECT *, - CASE WHEN EXISTS ( - SELECT 1 FROM marmut.akun u - WHERE u.email = '{email}' - ) THEN 'true' - ELSE 'false' END AS is_user - FROM marmut.akun WHERE email = '{email}' - """ - # Eksekusi query tabel akun - matching_users_akun = execute_sql_query(query=query_akun) +# # Query untuk mencari pengguna berdasarkan email di tabel akun +# query_akun = f""" +# SELECT *, +# CASE WHEN EXISTS ( +# SELECT 1 FROM marmut.akun u +# WHERE u.email = '{email}' +# ) THEN 'true' +# ELSE 'false' END AS is_user +# FROM marmut.akun WHERE email = '{email}' +# """ +# # Eksekusi query tabel akun +# matching_users_akun = execute_sql_query(query=query_akun) - # Query untuk mencari pengguna berdasarkan email di tabel label - query_label = f""" - SELECT *, - CASE WHEN EXISTS ( - SELECT 1 FROM marmut.label l - WHERE l.email = '{email}' - ) THEN 'true' - ELSE 'false' END AS is_label - FROM marmut.label WHERE email = '{email}' - """ - # Eksekusi query tabel label - matching_users_label = execute_sql_query(query=query_label) +# # Query untuk mencari pengguna berdasarkan email di tabel label +# query_label = f""" +# SELECT *, +# CASE WHEN EXISTS ( +# SELECT 1 FROM marmut.label l +# WHERE l.email = '{email}' +# ) THEN 'true' +# ELSE 'false' END AS is_label +# FROM marmut.label WHERE email = '{email}' +# """ +# # Eksekusi query tabel label +# matching_users_label = execute_sql_query(query=query_label) - if len(matching_users_akun) == 0 and len(matching_users_label) == 0: - # Jika email tidak ditemukan di kedua tabel - messages.error(request, 'Pengguna tidak ditemukan.') - else: - # Jika email ditemukan di salah satu atau kedua tabel - user_data = {} +# if len(matching_users_akun) == 0 and len(matching_users_label) == 0: +# # Jika email tidak ditemukan di kedua tabel +# messages.error(request, 'Pengguna tidak ditemukan.') +# else: +# # Jika email ditemukan di salah satu atau kedua tabel +# user_data = {} - if len(matching_users_akun) > 0: - # Jika pengguna ada di tabel akun - user_akun = matching_users_akun[0] - if user_akun['password'] == password: - # Jika password sesuai, ambil informasi pengguna dari tabel akun - user_data['email'] = user_akun['email'] - user_data['nama'] = user_akun['nama'] - user_data['kota_asal'] = user_akun['kota_asal'] - user_data['gender'] = user_akun['gender'] - user_data['tempat_lahir'] = user_akun['tempat_lahir'] - user_data['tanggal_lahir'] = user_akun['tanggal_lahir'] +# if len(matching_users_akun) > 0: +# # Jika pengguna ada di tabel akun +# user_akun = matching_users_akun[0] +# if user_akun['password'] == password: +# # Jika password sesuai, ambil informasi pengguna dari tabel akun +# user_data['email'] = user_akun['email'] +# user_data['nama'] = user_akun['nama'] +# user_data['kota_asal'] = user_akun['kota_asal'] +# user_data['gender'] = user_akun['gender'] +# user_data['tempat_lahir'] = user_akun['tempat_lahir'] +# user_data['tanggal_lahir'] = user_akun['tanggal_lahir'] - roles = [] - # Cek role pengguna - # Cek apakah email pengguna ada di tabel Premium - query_premium = f""" - SELECT * FROM marmut.premium - WHERE email = '{user_akun['email']}' - """ - matching_premium = execute_sql_query(query=query_premium) - if len(matching_premium) > 0: - roles.append('Premium') - is_premium = True +# roles = [] +# # Cek role pengguna +# # Cek apakah email pengguna ada di tabel Premium +# query_premium = f""" +# SELECT * FROM marmut.premium +# WHERE email = '{user_akun['email']}' +# """ +# matching_premium = execute_sql_query(query=query_premium) +# if len(matching_premium) > 0: +# roles.append('Premium') +# is_premium = True - # Cek apakah email pengguna ada di tabel Artist - query_artist = f""" - SELECT * FROM marmut.artist - WHERE email = '{user_akun['email']}' - """ - matching_artist = execute_sql_query(query=query_artist) - if len(matching_artist) > 0: - roles.append('Artist') - is_artist = True +# # Cek apakah email pengguna ada di tabel Artist +# query_artist = f""" +# SELECT * FROM marmut.artist +# WHERE email = '{user_akun['email']}' +# """ +# matching_artist = execute_sql_query(query=query_artist) +# if len(matching_artist) > 0: +# roles.append('Artist') +# is_artist = True - # Cek apakah email pengguna ada di tabel Songwriter - query_songwriter = f""" - SELECT * FROM marmut.songwriter - WHERE email = '{user_akun['email']}' - """ - matching_songwriter = execute_sql_query(query=query_songwriter) - if len(matching_songwriter) > 0: - roles.append('Songwriter') - is_songwriter = True +# # Cek apakah email pengguna ada di tabel Songwriter +# query_songwriter = f""" +# SELECT * FROM marmut.songwriter +# WHERE email = '{user_akun['email']}' +# """ +# matching_songwriter = execute_sql_query(query=query_songwriter) +# if len(matching_songwriter) > 0: +# roles.append('Songwriter') +# is_songwriter = True - # Cek apakah email pengguna ada di tabel Podcaster - query_podcaster = f""" - SELECT * FROM marmut.podcaster - WHERE email = '{user_akun['email']}' - """ - matching_podcaster = execute_sql_query(query=query_podcaster) - if len(matching_podcaster) > 0: - roles.append('Podcaster') - is_podcaster = True +# # Cek apakah email pengguna ada di tabel Podcaster +# query_podcaster = f""" +# SELECT * FROM marmut.podcaster +# WHERE email = '{user_akun['email']}' +# """ +# matching_podcaster = execute_sql_query(query=query_podcaster) +# if len(matching_podcaster) > 0: +# roles.append('Podcaster') +# is_podcaster = True - user_data['role'] = ', '.join(roles) - #berarti pengguna biasa ga ada is_pengguna biasa tapi cek aja is dari tiap role - request.session['user_data'] = { - 'email': email, - 'nama': user_akun.get('nama', ''), - 'password': password, - 'is_premium' : is_premium, - 'is_artist' : is_artist, - 'is_songwriter' : is_songwriter , - 'is_podcaster' : is_podcaster, - 'is_label' : is_label - } +# user_data['role'] = ', '.join(roles) +# #berarti pengguna biasa ga ada is_pengguna biasa tapi cek aja is dari tiap role +# request.session['user_data'] = { +# 'email': email, +# 'nama': user_akun.get('nama', ''), +# 'password': password, +# 'is_premium' : is_premium, +# 'is_artist' : is_artist, +# 'is_songwriter' : is_songwriter , +# 'is_podcaster' : is_podcaster, +# 'is_label' : is_label +# } - # Redirect ke halaman dashboard pengguna - return HttpResponseRedirect('/dashboard/') - else: - messages.error(request, 'Maaf, password yang Anda masukkan salah.') +# # Redirect ke halaman dashboard pengguna +# return HttpResponseRedirect('/dashboard/') +# else: +# messages.error(request, 'Maaf, password yang Anda masukkan salah.') - if len(matching_users_label) > 0: - # Jika pengguna ada di tabel label - user_label = matching_users_label[0] - # Ambil informasi pengguna dari tabel label - if user_label['password'] == password: - user_data['email'] = user_label['email'] - user_data['nama'] = user_label['nama'] - user_data['kontak'] = user_label['kontak'] - - - # request.session['user_data'] = { - # 'email': email, - # 'nama': user_akun.get('nama', ''), - # 'password': password - # } - - request.session['user_data'] = { - 'email': email, - 'nama': user_akun.get('nama', ''), - 'password': password, - 'is_premium' : is_premium, - 'is_artist' : is_artist, - 'is_songwriter' : is_songwriter , - 'is_podcaster' : is_podcaster, - 'is_label' : is_label - } - - #next -> blm tambahin di views(?) - return HttpResponseRedirect('label/label_dashboard/') - else: - messages.error(request, 'Maaf, password yang Anda masukkan salah.') - #next : ini bisa ditaruh di views.py untuk di app label aja -> buat nampilin semua album yang dimiliki oleh label teresebut - # # Query untuk mencari album milik label - # query_album = f""" - # SELECT * FROM marmut.album - # WHERE id_label = '{user_label['id']}' - # """ - # # Eksekusi query album - # # matching_albums = execute_sql_query(query=query_album) - # if len(matching_albums) == 0: - # messages.info(request, 'Belum Memproduksi Album') +# if len(matching_users_label) > 0: +# # Jika pengguna ada di tabel label +# user_label = matching_users_label[0] +# # Ambil informasi pengguna dari tabel label +# if user_label['password'] == password: +# user_data['email'] = user_label['email'] +# user_data['nama'] = user_label['nama'] +# user_data['kontak'] = user_label['kontak'] + + +# # request.session['user_data'] = { +# # 'email': email, +# # 'nama': user_akun.get('nama', ''), +# # 'password': password +# # } + +# request.session['user_data'] = { +# 'email': email, +# 'nama': user_akun.get('nama', ''), +# 'password': password, +# 'is_premium' : is_premium, +# 'is_artist' : is_artist, +# 'is_songwriter' : is_songwriter , +# 'is_podcaster' : is_podcaster, +# 'is_label' : is_label +# } + +# #next -> blm tambahin di views(?) +# return HttpResponseRedirect('label/label_dashboard/') +# else: +# messages.error(request, 'Maaf, password yang Anda masukkan salah.') +# #next : ini bisa ditaruh di views.py untuk di app label aja -> buat nampilin semua album yang dimiliki oleh label teresebut +# # # Query untuk mencari album milik label +# # query_album = f""" +# # SELECT * FROM marmut.album +# # WHERE id_label = '{user_label['id']}' +# # """ +# # # Eksekusi query album +# # # matching_albums = execute_sql_query(query=query_album) +# # if len(matching_albums) == 0: +# # messages.info(request, 'Belum Memproduksi Album') - # Redirect ke halaman dashboard label +# # Redirect ke halaman dashboard label - return render(request, "login.html") - -#khusus pengguna -#next cek dulu ini bener atau ga -@csrf_exempt -def dashboard_view(request): - user_data = request.session.get('user_data') - if not user_data: - messages.error(request, 'Anda harus login terlebih dahulu.') - return render(request, 'login.html') - - playlists = [] - songs = [] - podcasts = [] - - if not user_data.get('is_artist') and not user_data.get('is_podcaster') and not user_data.get('is_songwriter'): - # Jika pengguna bukan artist, podcaster, atau songwriter, maka cari playlistnya - with connection.cursor() as cursor: - cursor.execute("SELECT * FROM marmut.user_playlist WHERE email_pembuat = %s", [user_data['email']]) - playlists = cursor.fetchall() +# return render(request, "login.html") + +# #khusus pengguna +# #next cek dulu ini bener atau ga +# @csrf_exempt +# def dashboard_view(request): +# user_data = request.session.get('user_data') +# if not user_data: +# messages.error(request, 'Anda harus login terlebih dahulu.') +# return render(request, 'login.html') + +# playlists = [] +# songs = [] +# podcasts = [] + +# if not user_data.get('is_artist') and not user_data.get('is_podcaster') and not user_data.get('is_songwriter'): +# # Jika pengguna bukan artist, podcaster, atau songwriter, maka cari playlistnya +# with connection.cursor() as cursor: +# cursor.execute("SELECT * FROM marmut.user_playlist WHERE email_pembuat = %s", [user_data['email']]) +# playlists = cursor.fetchall() - if user_data.get('is_artist') or user_data.get('is_songwriter'): - # Jika pengguna adalah artist atau songwriter, maka cari lagu yang dimilikinya - with connection.cursor() as cursor: - cursor.execute("SELECT * FROM marmut.song WHERE id_artist = %s", [user_data['email']]) - songs = cursor.fetchall() +# if user_data.get('is_artist') or user_data.get('is_songwriter'): +# # Jika pengguna adalah artist atau songwriter, maka cari lagu yang dimilikinya +# with connection.cursor() as cursor: +# cursor.execute("SELECT * FROM marmut.song WHERE id_artist = %s", [user_data['email']]) +# songs = cursor.fetchall() - if user_data.get('is_podcaster'): - # Jika pengguna adalah podcaster, maka cari podcast yang dimilikinya - with connection.cursor() as cursor: - cursor.execute("SELECT * FROM marmut.podcast WHERE email_podcaster = %s", [user_data['email']]) - podcasts = cursor.fetchall() - - context = { - 'user_data': user_data, - 'playlists': playlists, - 'songs': songs, - 'podcasts': podcasts, - } - - return render(request, 'dashboard.html', context) -# @csrf_exempt -# def login_with_postgres(request): -# if request.method == 'POST': -# email = request.POST.get('email') -# password = request.POST.get('password') - -# query = f""" -# SELECT *, -# CASE WHEN EXISTS ( -# SELECT 1 FROM sistel.user u -# INNER JOIN hotel ON u.email = hotel.email -# WHERE u.email = '{email}' -# ) THEN 'false' -# ELSE 'true' END AS is_pengguna -# FROM sistel.user WHERE email = '{email}' -# """ -# matching_users = execute_sql_query(query=query) +# if user_data.get('is_podcaster'): +# # Jika pengguna adalah podcaster, maka cari podcast yang dimilikinya +# with connection.cursor() as cursor: +# cursor.execute("SELECT * FROM marmut.podcast WHERE email_podcaster = %s", [user_data['email']]) +# podcasts = cursor.fetchall() + +# context = { +# 'user_data': user_data, +# 'playlists': playlists, +# 'songs': songs, +# 'podcasts': podcasts, +# } + +# return render(request, 'dashboard.html', context) +# # @csrf_exempt +# # def login_with_postgres(request): +# # if request.method == 'POST': +# # email = request.POST.get('email') +# # password = request.POST.get('password') + +# # query = f""" +# # SELECT *, +# # CASE WHEN EXISTS ( +# # SELECT 1 FROM sistel.user u +# # INNER JOIN hotel ON u.email = hotel.email +# # WHERE u.email = '{email}' +# # ) THEN 'false' +# # ELSE 'true' END AS is_pengguna +# # FROM sistel.user WHERE email = '{email}' +# # """ +# # matching_users = execute_sql_query(query=query) -# # print(matching_users) -# if len(matching_users) == 0: -# messages.error(request, 'Pengguna tidak ditemukan.') -# else: -# # print(matching_users) -# selected_user = matching_users[0] -# user_store_password = selected_user[1] -# user_fname = selected_user[2] -# user_lname = selected_user[3] -# is_user = selected_user[4] -# if user_store_password == password: -# request.session['user_data'] = { -# 'email': email, -# 'fname': user_fname, -# 'lname': user_lname, -# 'is_hotel': is_user == 'false' -# } -# print(request.session['user_data']) -# # TODO: ganti redirect ke dashboard -# if is_user == 'false': -# return HttpResponseRedirect('/hotel/dashboard/') -# return HttpResponseRedirect('/reservasi/dashboard/') -# messages.error(request, 'Maaf, password yang kamu masukkan salah.') -# return render(request,"login.html") - - -# def login_view(request): -# if request.method == 'POST': -# form = LoginForm(request.POST) -# if form.is_valid(): -# email = form.cleaned_data['email'] -# password = form.cleaned_data['password'] -# user = authenticate(request, username=email, password=password) -# if user is not None: -# login(request, user) -# # Redirect ke halaman Dashboard sesuai peran pengguna -# if user.is_artist: -# return redirect('artist_dashboard') -# elif user.is_songwriter: -# return redirect('songwriter_dashboard') -# elif user.is_podcaster: -# return redirect('podcaster_dashboard') -# else: -# return redirect('user_dashboard') -# else: -# messages.error(request, 'Email atau password salah.') -# else: -# form = LoginForm() -# return render(request, 'login.html', {'form': form}) +# # # print(matching_users) +# # if len(matching_users) == 0: +# # messages.error(request, 'Pengguna tidak ditemukan.') +# # else: +# # # print(matching_users) +# # selected_user = matching_users[0] +# # user_store_password = selected_user[1] +# # user_fname = selected_user[2] +# # user_lname = selected_user[3] +# # is_user = selected_user[4] +# # if user_store_password == password: +# # request.session['user_data'] = { +# # 'email': email, +# # 'fname': user_fname, +# # 'lname': user_lname, +# # 'is_hotel': is_user == 'false' +# # } +# # print(request.session['user_data']) +# # # TODO: ganti redirect ke dashboard +# # if is_user == 'false': +# # return HttpResponseRedirect('/hotel/dashboard/') +# # return HttpResponseRedirect('/reservasi/dashboard/') +# # messages.error(request, 'Maaf, password yang kamu masukkan salah.') +# # return render(request,"login.html") + + +# # def login_view(request): +# # if request.method == 'POST': +# # form = LoginForm(request.POST) +# # if form.is_valid(): +# # email = form.cleaned_data['email'] +# # password = form.cleaned_data['password'] +# # user = authenticate(request, username=email, password=password) +# # if user is not None: +# # login(request, user) +# # # Redirect ke halaman Dashboard sesuai peran pengguna +# # if user.is_artist: +# # return redirect('artist_dashboard') +# # elif user.is_songwriter: +# # return redirect('songwriter_dashboard') +# # elif user.is_podcaster: +# # return redirect('podcaster_dashboard') +# # else: +# # return redirect('user_dashboard') +# # else: +# # messages.error(request, 'Email atau password salah.') +# # else: +# # form = LoginForm() +# # return render(request, 'login.html', {'form': form}) diff --git a/requirements.txt b/requirements.txt index c458349..1704875 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,4 @@ gunicorn whitenoise psycopg2-binary requests -urllib3 \ No newline at end of file +urllib3 diff --git a/templates/nav.html b/templates/nav.html index 3df0f5e..a90e141 100644 --- a/templates/nav.html +++ b/templates/nav.html @@ -1,5 +1,3 @@ - -