diff --git a/db.sqlite3 b/db.sqlite3 index 5ec8fe9416ad8e864f38617452a3b97395eed046..d29d421672eb9c01fd0f454ec5e2e33dbb540e70 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/lab_3/.tests.py.un~ b/lab_3/.tests.py.un~ new file mode 100644 index 0000000000000000000000000000000000000000..dea0d87e837ef1a44da84e1dff033f3883451e0f Binary files /dev/null and b/lab_3/.tests.py.un~ differ diff --git a/lab_3/.views.py.un~ b/lab_3/.views.py.un~ new file mode 100644 index 0000000000000000000000000000000000000000..394e192410ade69ee7e5a043c684fc4a016e8426 Binary files /dev/null and b/lab_3/.views.py.un~ differ diff --git a/lab_3/tests.py~ b/lab_3/tests.py~ new file mode 100644 index 0000000000000000000000000000000000000000..b8cbd47ced380e2e8c006cf1aca854642f5ab8ae --- /dev/null +++ b/lab_3/tests.py~ @@ -0,0 +1,63 @@ +from django.test import TestCase, Client +from django.urls import resolve +from .views import index, add_activity +from .models import Diary +from django.utils import timezone + +class Lab3Test(TestCase): + def test_lab_3_url_is_exist(self): + response = Client().get('/lab-3/') + self.assertEqual(response.status_code,200) + + def test_lab_3_using_to_do_list_template(self): + response = Client().get('/lab-3/') + self.assertTemplateUsed(response, 'to_do_list.html') + + def test_lab_3_using_index_func(self): + found = resolve('/lab-3/') + self.assertEqual(found.func, index) + + def test_model_can_create_new_activity(self): + # Membuat aktiviti baru + new_activity = Diary.objects.create(date=timezone.now(),activity='Aku mau latihan ngoding deh') + + + # Menerima (retrieve) segala aktiviti yang pernah ada + counting_all_available_activity = Diary.objects.all().count() + self.assertEqual(counting_all_available_activity,1) + + def test_input_tanggal_wrong (self): + response = self.client.post('/lab-3/add_activity/', data={'date': '111111-11-11T11:11', 'activity' : 'Maen Dota Kayaknya Enak'}) + counting_all_available_activity = Diary.objects.all().count() + self.assertEqual(counting_all_available_activity, 0) + + response = Client().get('/lab-3/') + counting_all_available_activity = Diary.objects.all().count() + self.assertEqual(counting_all_available_activity, 0) + + def test_input_aktifiti_wrong (self): + response = self.client.post('/lab-3/add_activity/', data={'date': '1111-11-11T11:11', 'activity' : 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Lorem ipsum!'}) + counting_all_available_activity = Diary.objects.all().count() + self.assertEqual(counting_all_available_activity, 0) + + response = self.client.post('/lab-3/add_activity/', data={'date': '1111-11-11T11:11', 'activity' : ''}) + print("JUMLAH", Diary.objects.all().count()) + counting_all_available_activity = Diary.objects.all().count() + self.assertEqual(counting_all_available_activity, 0) + + response = self.client.post('/lab-3/add_activity/', data={'date': '2017-10-12T14:14', 'activity' : 'benar!'}) + print("JUMLAH BARU", Diary.objects.all().count()) + + def test_can_save_a_POST_request(self): + response = self.client.post('/lab-3/add_activity/', data={'date': '2017-10-12T14:14', 'activity' : 'Maen Dota Kayaknya Enak'}) + counting_all_available_activity = Diary.objects.all().count() + self.assertEqual(counting_all_available_activity, 1) + + self.assertEqual(response.status_code, 302) + self.assertEqual(response['location'], '/lab-3/') + + new_response = self.client.get('/lab-3/') + html_response = new_response.content.decode('utf8') + self.assertIn('Maen Dota Kayaknya Enak', html_response) + + diff --git a/lab_3/views.py b/lab_3/views.py index 6ef39e762e98aee2d2d600ff102adeedd5dda119..ef7738ae6df5442adc390c10d207e5ec0fb02973 100644 --- a/lab_3/views.py +++ b/lab_3/views.py @@ -31,7 +31,6 @@ def add_activity(request): try: date = datetime.strptime(request.POST['date'],'%Y-%m-%dT%H:%M') - anotherDict['getWasFromPost'] |= False if not anotherDict['getWasFromPost']: anotherDict['errorDateBox'] = '' diff --git a/lab_3/views.py~ b/lab_3/views.py~ new file mode 100644 index 0000000000000000000000000000000000000000..6ef39e762e98aee2d2d600ff102adeedd5dda119 --- /dev/null +++ b/lab_3/views.py~ @@ -0,0 +1,51 @@ +from django.shortcuts import render, redirect +from .models import Diary +from datetime import datetime +import pytz +import json +# Create your views here. +diary_dict = {} +anotherDict = {'errorDateBox':'', 'errorActivity':'', 'getWasFromPost': False} + +def index(request): + if (anotherDict['getWasFromPost']): + anotherDict['getWasFromPost'] = False + else: + anotherDict['errorDateBox'] = '' + anotherDict['errorActivity'] = '' + diary_dict = Diary.objects.all().values() + return render(request, 'to_do_list.html', {'diary_dict' : convert_queryset_into_json(diary_dict), + 'errorDateBox': anotherDict['errorDateBox'], + 'errorActivity': anotherDict['errorActivity']}) + +def add_activity(request): + if request.method == 'POST': + + if (len(request.POST['activity']) == 0): + anotherDict['getWasFromPost'] = True + anotherDict['errorActivity'] = 'Format kegiatan tidak boleh kosong' + + elif (len(request.POST['activity']) > 60): + anotherDict['getWasFromPost'] = True + anotherDict['errorActivity'] = 'Format kegiatan tidak boleh melebihi 60 karakter' + + try: + date = datetime.strptime(request.POST['date'],'%Y-%m-%dT%H:%M') + anotherDict['getWasFromPost'] |= False + + if not anotherDict['getWasFromPost']: + anotherDict['errorDateBox'] = '' + Diary.objects.create(date=date.replace(tzinfo=pytz.UTC),activity=request.POST['activity']) + + except ValueError: + anotherDict['getWasFromPost'] = True + anotherDict['errorDateBox'] = 'Format tanggal tidak tepat' + + return redirect('/lab-3/') + +def convert_queryset_into_json(queryset): + ret_val = [] + for data in queryset: + ret_val.append(data) + return ret_val + diff --git a/.gitlab-ci.yml.swp b/lab_4/.admin.py.swp similarity index 90% rename from .gitlab-ci.yml.swp rename to lab_4/.admin.py.swp index 0d968991ac42de41be9c07f986ca441f88c1c692..348029d9da7b3b48e2d910c0ab30547d958b6125 100644 Binary files a/.gitlab-ci.yml.swp and b/lab_4/.admin.py.swp differ diff --git a/lab_4/.admin.py.un~ b/lab_4/.admin.py.un~ new file mode 100644 index 0000000000000000000000000000000000000000..e151d6312ce1b831ac7e2c49e89d71809f206c38 Binary files /dev/null and b/lab_4/.admin.py.un~ differ diff --git a/praktikum/.urls.py.swp b/lab_4/.views.py.swp similarity index 80% rename from praktikum/.urls.py.swp rename to lab_4/.views.py.swp index 73b82226a46b26fed7be399500c6c71f0daed9b9..406ed9c6b36df57051c03c8aecb006e33e84ecd7 100644 Binary files a/praktikum/.urls.py.swp and b/lab_4/.views.py.swp differ diff --git a/lab_4/.views.py.un~ b/lab_4/.views.py.un~ index f8cc34d2cef95a69bc12f9734afe80699a459d9e..3dd0a587b9d28162b9372de117b837dcb5eb011b 100644 Binary files a/lab_4/.views.py.un~ and b/lab_4/.views.py.un~ differ diff --git a/lab_4/admin.py b/lab_4/admin.py index 8c38f3f3dad51e4585f3984282c2a4bec5349c1e..26f44be048a6e4b0595e0259ba97bde06a8f2c10 100644 --- a/lab_4/admin.py +++ b/lab_4/admin.py @@ -1,3 +1,5 @@ from django.contrib import admin +from .models import Message # Register your models here. +admin.site.register(Message) diff --git a/lab_4/admin.py~ b/lab_4/admin.py~ new file mode 100644 index 0000000000000000000000000000000000000000..26f44be048a6e4b0595e0259ba97bde06a8f2c10 --- /dev/null +++ b/lab_4/admin.py~ @@ -0,0 +1,5 @@ +from django.contrib import admin +from .models import Message + +# Register your models here. +admin.site.register(Message) diff --git a/lab_4/views.py b/lab_4/views.py index 21ea2b51e6e45d7a511996efa0f6e90291ed1564..20ee4039371e2123196cc9bea19b9b2ecdf11886 100644 --- a/lab_4/views.py +++ b/lab_4/views.py @@ -6,7 +6,13 @@ from .models import Message # Create your views here. response = {'author': "Rachmat Ridwan"} #TODO Implement yourname -about_me = ["Saya Rachmat Ridwan, panggil saja Farid", "Rid", "wan", "gan", "teng", "nya"] +about_me = ["Saya Rachmat Ridwan, biasa dipanggil Farid", + "Kini sedang pendidikan di Universitas Indonesia", + "Beberapa anime membentuk jati diri saya, seperti Nichijou dan SAO", + "Saya juga amat suka komposisi musik orkestra", + "Sampai saat ini saya senang mengamati latar belakang musik film", + "Saya juga senang membuat gambar 3D dan animasi", + "Because animation matters! (Yes, I am falling in love with EC right now)"] def index(request): response['content'] = landing_page_content diff --git a/lab_4/views.py~ b/lab_4/views.py~ index 39799d6ad4c0c2499456126b394ffbfeea4d1fed..d8d1c35c059297732a0ed0460eb8c849d4754e41 100644 --- a/lab_4/views.py~ +++ b/lab_4/views.py~ @@ -3,11 +3,16 @@ from lab_2.views import landing_page_content from django.http import HttpResponseRedirect from .forms import Message_Form from .models import Message -import datetime # Create your views here. response = {'author': "Rachmat Ridwan"} #TODO Implement yourname -about_me = ["Saya Rachmat Ridwan, panggil saja Farid", "Rid", "wan", "gan", "teng", "nya"] +about_me = ["Saya Rachmat Ridwan, biasa dipanggil Farid", + "Kini sedang pendidikan di Universitas Indonesia", + "Beberapa anime membentuk jati diri saya, seperti Nichijou dan SAO", + "Saya juga amat suka komposisi musik orkestra", + "Sampai saat ini saya senang mengamati latar belakang musik film", + "Saya juga senang membuat gambar 3D dan animasi", + "Because animation matters! (Yes, I'm falling in love with EC right now)"] def index(request): response['content'] = landing_page_content diff --git a/praktikum/.settings.py.swp b/praktikum/.settings.py.swp deleted file mode 100644 index ff6a6b094dc15116dc33a0ce771c56f5ee55b13d..0000000000000000000000000000000000000000 Binary files a/praktikum/.settings.py.swp and /dev/null differ diff --git a/templates/.description_lab2addon.html.swp b/templates/.description_lab2addon.html.swp deleted file mode 100644 index 6b5447703bc460b2dcd6521a77e3ab431a68dcbd..0000000000000000000000000000000000000000 Binary files a/templates/.description_lab2addon.html.swp and /dev/null differ