diff --git a/2205126/Django_demo_app/Documentation.txt b/2205126/Django_demo_app/Documentation.txt new file mode 100644 index 0000000..dd64c03 --- /dev/null +++ b/2205126/Django_demo_app/Documentation.txt @@ -0,0 +1,84 @@ +django-admin startproject : + command used to initialise a project in django + +python manage.py runserver or django-admin runserver: + command used to start the Django development server. It allows you to run your Django application locally for testing and development purposes. + +python manage.py startapp : + command used to create apps. + +.vscode/launch.json : + includes debugging configurations for views.py + +Using django-debug-toolbar for debugging (Alternative for vscode direct debugging): + requires installation using 'pip install django-debug-toolbar' + requires a proper html response to work + reference docs: https://django-debug-toolbar.readthedocs.io/en/latest/installation.html + settings.py should be modified to include the following: + INSTALLED_APPS = [ + ... + 'debug_toolbar', + ... + ] + MIDDLEWARE = [ + ... + 'debug_toolbar.middleware.DebugToolbarMiddleware', + ... + ] + DEBUG = True + INTERNAL_IPS = [ + #... + '127.0.0.1', + #... + ] + +/* + What is migrations? + Each migration describes a set of changes, similar to commits in version control systems +*/ + +python manage.py makemigrations : + creates migrations for all the installed apps in the project, these files are used when migrating from development to production server, + .py code in these files will be converted MYSQL statements for creating tables and database + +python manage.py migrate : + command to run migrations + +/* + vscode extension named "SQLite" for using and opening SQLite databases in vscde" +*/ + +python manage.py sqlmigrate "name of migration (eg: store 0003)" : + displays actual code/sql-statements that are sent to our database during migration + the type of statements that are sent depends on the backend database that is used (eg: SQLite, MYSQL, PostgresSQL etc) + +python manage.py migrate "name of the migration to which you want to revert to" : + reverts the migration to the specified migration file + +pip install mysqlclient : + for using mysql database + also mysql server is required to be downloaded, if mysql workbench is installed than no need to install mysql server separately. + + errors encountered while installing: + error: subprocess-exited-with-error : + occurs if libmysqlclient-dev build-essential is not installed, which are dependencies for installing mysqlclient + resolve by installing: sudo apt install libmysqlclient-dev build-essential + + settings.py should be modified to include the following in DATABASE: + To use environment variables import os.environ + DATABASES = { + "default": { + "ENGINE": "django.db.backends.mysql", + "NAME": "storefront", + "HOST": "localhost", + "USER": "root", + "PASSWORD": environ.get("DATABASE_PASSWORD"), + } + } + + +python manage.py makemigrations store --empty : + # This command is used to create an empty migration file for the 'store' app in Django. + # The 'makemigrations' command is used to generate database migration files based on changes in the models. + # The '--empty' flag indicates that the migration file should be empty, without any changes to the database schema. + # This command is useful when you want to manually write the migration file instead of relying on Django's automatic migration generation. \ No newline at end of file diff --git a/2205126/Django_demo_app/Note_maker/__init__.py b/2205126/Django_demo_app/Note_maker/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/2205126/Django_demo_app/Note_maker/asgi.py b/2205126/Django_demo_app/Note_maker/asgi.py new file mode 100644 index 0000000..4776fbb --- /dev/null +++ b/2205126/Django_demo_app/Note_maker/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for Note_maker project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Note_maker.settings") + +application = get_asgi_application() diff --git a/2205126/Django_demo_app/Note_maker/settings.py b/2205126/Django_demo_app/Note_maker/settings.py new file mode 100644 index 0000000..ed02f8d --- /dev/null +++ b/2205126/Django_demo_app/Note_maker/settings.py @@ -0,0 +1,137 @@ +""" +Django settings for Note_maker project. + +Generated by 'django-admin startproject' using Django 4.2.10. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.2/ref/settings/ +""" + +from pathlib import Path +from os import environ +from django.utils import timezone + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = "django-insecure-4h)&t8&z#tjqpuugsh1-yoddditqs)od62u052jat(&i(c8o0a" + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", + 'debug_toolbar', + 'notes_app', +] + +MIDDLEWARE = [ + "django.middleware.security.SecurityMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.common.CommonMiddleware", + "django.middleware.csrf.CsrfViewMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", + "django.middleware.clickjacking.XFrameOptionsMiddleware", + 'debug_toolbar.middleware.DebugToolbarMiddleware', +] + +INTERNAL_IPS = [ + #... + '127.0.0.1', + #... +] + +ROOT_URLCONF = "Note_maker.urls" + +TEMPLATES = [ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [], + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.debug", + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", + ], + }, + }, +] + +WSGI_APPLICATION = "Note_maker.wsgi.application" + + +# Database +# https://docs.djangoproject.com/en/4.2/ref/settings/#databases + +DATABASES = { + "default": { + "ENGINE": "django.db.backends.mysql", + "NAME": "note_maker", + "HOST": "localhost", + "USER": "root", + "PASSWORD": environ.get("DATABASE_PASSWORD"), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/4.2/topics/i18n/ + +LANGUAGE_CODE = "en-us" + +TIME_ZONE = "Asia/Kolkata" + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.2/howto/static-files/ + +STATIC_URL = "static/" + +# Default primary key field type +# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" diff --git a/2205126/Django_demo_app/Note_maker/urls.py b/2205126/Django_demo_app/Note_maker/urls.py new file mode 100644 index 0000000..62f03c9 --- /dev/null +++ b/2205126/Django_demo_app/Note_maker/urls.py @@ -0,0 +1,25 @@ +""" +URL configuration for Note_maker project. + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path, include +import debug_toolbar + +urlpatterns = [ + path("admin/", admin.site.urls), + path("__debug__/", include(debug_toolbar.urls)), + path("", include("notes_app.urls")), +] diff --git a/2205126/Django_demo_app/Note_maker/wsgi.py b/2205126/Django_demo_app/Note_maker/wsgi.py new file mode 100644 index 0000000..2fbd58a --- /dev/null +++ b/2205126/Django_demo_app/Note_maker/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for Note_maker project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Note_maker.settings") + +application = get_wsgi_application() diff --git a/2205126/Django_demo_app/db.sqlite3 b/2205126/Django_demo_app/db.sqlite3 new file mode 100644 index 0000000..e69de29 diff --git a/2205126/Django_demo_app/manage.py b/2205126/Django_demo_app/manage.py new file mode 100755 index 0000000..3df1dbe --- /dev/null +++ b/2205126/Django_demo_app/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Note_maker.settings") + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == "__main__": + main() diff --git a/2205126/Django_demo_app/notes_app/__init__.py b/2205126/Django_demo_app/notes_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/2205126/Django_demo_app/notes_app/admin.py b/2205126/Django_demo_app/notes_app/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/2205126/Django_demo_app/notes_app/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/2205126/Django_demo_app/notes_app/apps.py b/2205126/Django_demo_app/notes_app/apps.py new file mode 100644 index 0000000..672c996 --- /dev/null +++ b/2205126/Django_demo_app/notes_app/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class NotesAppConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "notes_app" diff --git a/2205126/Django_demo_app/notes_app/migrations/0001_initial.py b/2205126/Django_demo_app/notes_app/migrations/0001_initial.py new file mode 100644 index 0000000..0140fcc --- /dev/null +++ b/2205126/Django_demo_app/notes_app/migrations/0001_initial.py @@ -0,0 +1,31 @@ +# Generated by Django 4.2.10 on 2024-02-29 10:45 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [] + + operations = [ + migrations.CreateModel( + name="note", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("title", models.CharField(max_length=200)), + ("content", models.TextField()), + ("created_at", models.DateTimeField(auto_now_add=True)), + ("last_modified", models.DateTimeField(auto_now=True)), + ], + ), + ] diff --git a/2205126/Django_demo_app/notes_app/migrations/__init__.py b/2205126/Django_demo_app/notes_app/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/2205126/Django_demo_app/notes_app/models.py b/2205126/Django_demo_app/notes_app/models.py new file mode 100644 index 0000000..ae431a7 --- /dev/null +++ b/2205126/Django_demo_app/notes_app/models.py @@ -0,0 +1,9 @@ +from django.db import models +from datetime import datetime +# Create your models here. + +class note(models.Model): + title = models.CharField(max_length=200, null=False) + content = models.TextField(null=False) + created_at = models.DateTimeField(auto_now_add=True) + last_modified = models.DateTimeField(auto_now=True) \ No newline at end of file diff --git a/2205126/Django_demo_app/notes_app/templates/index.html b/2205126/Django_demo_app/notes_app/templates/index.html new file mode 100644 index 0000000..f62305b --- /dev/null +++ b/2205126/Django_demo_app/notes_app/templates/index.html @@ -0,0 +1,90 @@ + + + + + + + Note Maker + + + + + + +
+ +
+
+ +
+ {% csrf_token %} +
+ New note + +
+ + +
+ +
+ + +
+
+ +
+
+ +
+

Notes

+ {% for note in notes %} + +
+ + +
+

{{ note.title }}

+

{{ note.content }}

+
+
+ {% endfor %} + + {% if notes|length == 0 %} +
Your notes will appear here
+ {% endif %} +
+
+ +
+ + + + \ No newline at end of file diff --git a/2205126/Django_demo_app/notes_app/templates/note_edit.html b/2205126/Django_demo_app/notes_app/templates/note_edit.html new file mode 100644 index 0000000..5605626 --- /dev/null +++ b/2205126/Django_demo_app/notes_app/templates/note_edit.html @@ -0,0 +1,54 @@ + + + + + + + Note Maker + + + + + + +
+ +
+
+ +
+ {% csrf_token %} +
+ Edit note + +
+ + +
+ +
+ +
+
+ +
+
+ +
+ +
+ + + + \ No newline at end of file diff --git a/2205126/Django_demo_app/notes_app/tests.py b/2205126/Django_demo_app/notes_app/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/2205126/Django_demo_app/notes_app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/2205126/Django_demo_app/notes_app/urls.py b/2205126/Django_demo_app/notes_app/urls.py new file mode 100644 index 0000000..2f5b886 --- /dev/null +++ b/2205126/Django_demo_app/notes_app/urls.py @@ -0,0 +1,11 @@ +from django.urls import path +from . import views + +#URL configuration for the notes_app app. +urlpatterns = [ + path("", views.index, name="index"), # This is the URL pattern for the index page. It will call the index view. + path("note_save/", views.note_save, name="note_save"), + path('note_delete//', views.note_delete, name='note_delete'), + path('note_edit//', views.note_edit, name='note_edit'), + path('note_edit_save/', views.note_edit_save, name='note_edit_save'), +] \ No newline at end of file diff --git a/2205126/Django_demo_app/notes_app/views.py b/2205126/Django_demo_app/notes_app/views.py new file mode 100644 index 0000000..fcc1f31 --- /dev/null +++ b/2205126/Django_demo_app/notes_app/views.py @@ -0,0 +1,42 @@ +from django.shortcuts import redirect, render +from django.db import transaction +from notes_app.models import note as Note + +# Create your views here. + +def index(request): + notes = Note.objects.all() + return render(request,"index.html",{'notes': list(notes)}) + +@transaction.atomic +def note_save(request): + if request.method == "POST": + note = Note() + note.title = request.POST.get("title") + note.content = request.POST.get("content") + note.save() + return redirect("/") + return render(request, "index.html") + +@transaction.atomic +def note_delete(request, note_id): + if request.method == "POST": + note = Note.objects.get(id=note_id) + note.delete() + return redirect("/") + +@transaction.atomic +def note_edit(request, note_id): + if request.method == "POST": + note = Note.objects.get(id=note_id) + return render(request, "note_edit.html", {'note': note}) + return redirect("/") + +@transaction.atomic +def note_edit_save(request, note_id): + if request.method == "POST": + note = Note.objects.get(id=note_id) + note.title = request.POST.get("title") + note.content = request.POST.get("content") + note.save() + return redirect("/") \ No newline at end of file diff --git a/2205126/Django_demo_app/requirements.txt b/2205126/Django_demo_app/requirements.txt new file mode 100644 index 0000000..6f711fc --- /dev/null +++ b/2205126/Django_demo_app/requirements.txt @@ -0,0 +1,6 @@ +asgiref==3.7.2 +Django==4.2.10 +django-debug-toolbar==4.3.0 +mysqlclient==2.2.4 +sqlparse==0.4.4 +typing_extensions==4.10.0 diff --git a/lab3/src/main/java/mes/casetools/lab3/BCA2205126/IsPrime.java b/lab3/src/main/java/mes/casetools/lab3/BCA2205126/IsPrime.java new file mode 100644 index 0000000..4b04486 --- /dev/null +++ b/lab3/src/main/java/mes/casetools/lab3/BCA2205126/IsPrime.java @@ -0,0 +1,16 @@ +package mes.casetools.lab3.BCA2205126; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class IsPrime { + public boolean isPrime(int number){ + for(int i = 2; i <= number/2; i++){ + if(number % i == 0){ + return false; + } + } + return true; + } +} diff --git a/lab3/src/test/java/mes/casetools/lab3/BCA2205126/IsPrime_Test.java b/lab3/src/test/java/mes/casetools/lab3/BCA2205126/IsPrime_Test.java new file mode 100644 index 0000000..13ed1f6 --- /dev/null +++ b/lab3/src/test/java/mes/casetools/lab3/BCA2205126/IsPrime_Test.java @@ -0,0 +1,27 @@ +package mes.casetools.lab3.BCA2205126; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + + +@SpringBootTest +public class IsPrime_Test { + + @Test + void is_prime(){ + IsPrime prime_num = new IsPrime(); + boolean output = prime_num.isPrime(7); + assertTrue(output); + } + + @Test + void is_not_seven(){ + IsPrime prime_num = new IsPrime(); + boolean output = prime_num.isPrime(8); + assertFalse(output); + } +} +