diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..9924bc693 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +venv/* +venv +backend/mydjangoproject/eCom/__pycache__/* +backend/mydjangoproject/mydjangoproject/__pycache__/* \ No newline at end of file diff --git a/author.json b/author.json index 3d4a531ce..f6299a591 100644 --- a/author.json +++ b/author.json @@ -1,4 +1,4 @@ { - "name": "", - "entry_number": "" + "name": "Lakshya Mahajan", + "entry_number": "2022CH11429" } diff --git a/backend/mydjangoproject/db.sqlite3 b/backend/mydjangoproject/db.sqlite3 new file mode 100644 index 000000000..f998d34af Binary files /dev/null and b/backend/mydjangoproject/db.sqlite3 differ diff --git a/backend/mydjangoproject/eCom/__init__.py b/backend/mydjangoproject/eCom/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/backend/mydjangoproject/eCom/admin.py b/backend/mydjangoproject/eCom/admin.py new file mode 100644 index 000000000..c8127a270 --- /dev/null +++ b/backend/mydjangoproject/eCom/admin.py @@ -0,0 +1,4 @@ +from django.contrib import admin +from .models import Product +# Register your models here. +admin.site.register(Product) \ No newline at end of file diff --git a/backend/mydjangoproject/eCom/apps.py b/backend/mydjangoproject/eCom/apps.py new file mode 100644 index 000000000..2388c3ca8 --- /dev/null +++ b/backend/mydjangoproject/eCom/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class EcomConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'eCom' diff --git a/backend/mydjangoproject/eCom/migrations/0001_initial.py b/backend/mydjangoproject/eCom/migrations/0001_initial.py new file mode 100644 index 000000000..80a2d6a67 --- /dev/null +++ b/backend/mydjangoproject/eCom/migrations/0001_initial.py @@ -0,0 +1,24 @@ +# Generated by Django 4.2.2 on 2023-06-27 12:00 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Product', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('_id', models.UUIDField()), + ('name', models.TextField(max_length=50)), + ('descr', models.TextField(max_length=400)), + ('price', models.IntegerField()), + ], + ), + ] diff --git a/backend/mydjangoproject/eCom/migrations/0002_remove_product_id_alter_product__id.py b/backend/mydjangoproject/eCom/migrations/0002_remove_product_id_alter_product__id.py new file mode 100644 index 000000000..650a97fe7 --- /dev/null +++ b/backend/mydjangoproject/eCom/migrations/0002_remove_product_id_alter_product__id.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.2 on 2023-06-27 12:06 + +from django.db import migrations, models +import uuid + + +class Migration(migrations.Migration): + + dependencies = [ + ('eCom', '0001_initial'), + ] + + operations = [ + migrations.RemoveField( + model_name='product', + name='id', + ), + migrations.AlterField( + model_name='product', + name='_id', + field=models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False), + ), + ] diff --git a/backend/mydjangoproject/eCom/migrations/0003_rename__id_product_id.py b/backend/mydjangoproject/eCom/migrations/0003_rename__id_product_id.py new file mode 100644 index 000000000..c250ed52e --- /dev/null +++ b/backend/mydjangoproject/eCom/migrations/0003_rename__id_product_id.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.2 on 2023-06-27 12:28 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('eCom', '0002_remove_product_id_alter_product__id'), + ] + + operations = [ + migrations.RenameField( + model_name='product', + old_name='_id', + new_name='id', + ), + ] diff --git a/backend/mydjangoproject/eCom/migrations/__init__.py b/backend/mydjangoproject/eCom/migrations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/backend/mydjangoproject/eCom/migrations/__pycache__/0001_initial.cpython-310.pyc b/backend/mydjangoproject/eCom/migrations/__pycache__/0001_initial.cpython-310.pyc new file mode 100644 index 000000000..438a40969 Binary files /dev/null and b/backend/mydjangoproject/eCom/migrations/__pycache__/0001_initial.cpython-310.pyc differ diff --git a/backend/mydjangoproject/eCom/migrations/__pycache__/0002_remove_product_id_alter_product__id.cpython-310.pyc b/backend/mydjangoproject/eCom/migrations/__pycache__/0002_remove_product_id_alter_product__id.cpython-310.pyc new file mode 100644 index 000000000..df7482348 Binary files /dev/null and b/backend/mydjangoproject/eCom/migrations/__pycache__/0002_remove_product_id_alter_product__id.cpython-310.pyc differ diff --git a/backend/mydjangoproject/eCom/migrations/__pycache__/0003_rename__id_product_id.cpython-310.pyc b/backend/mydjangoproject/eCom/migrations/__pycache__/0003_rename__id_product_id.cpython-310.pyc new file mode 100644 index 000000000..e5c573848 Binary files /dev/null and b/backend/mydjangoproject/eCom/migrations/__pycache__/0003_rename__id_product_id.cpython-310.pyc differ diff --git a/backend/mydjangoproject/eCom/migrations/__pycache__/__init__.cpython-310.pyc b/backend/mydjangoproject/eCom/migrations/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 000000000..b12990fe1 Binary files /dev/null and b/backend/mydjangoproject/eCom/migrations/__pycache__/__init__.cpython-310.pyc differ diff --git a/backend/mydjangoproject/eCom/models.py b/backend/mydjangoproject/eCom/models.py new file mode 100644 index 000000000..5be3fa76c --- /dev/null +++ b/backend/mydjangoproject/eCom/models.py @@ -0,0 +1,10 @@ +from django.db import models +import uuid +# Create your models here. +class Product(models.Model): + id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) + name = models.TextField(max_length=50) + descr = models.TextField(max_length=400) + price = models.IntegerField() + def __str__(self): + return self.name diff --git a/backend/mydjangoproject/eCom/tests.py b/backend/mydjangoproject/eCom/tests.py new file mode 100644 index 000000000..7ce503c2d --- /dev/null +++ b/backend/mydjangoproject/eCom/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/backend/mydjangoproject/eCom/urls.py b/backend/mydjangoproject/eCom/urls.py new file mode 100644 index 000000000..779e01cf0 --- /dev/null +++ b/backend/mydjangoproject/eCom/urls.py @@ -0,0 +1,8 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path("", views.index, name="index"), + path("greet/", views.greet, name="greetingsss") +] \ No newline at end of file diff --git a/backend/mydjangoproject/eCom/views.py b/backend/mydjangoproject/eCom/views.py new file mode 100644 index 000000000..1b01caa63 --- /dev/null +++ b/backend/mydjangoproject/eCom/views.py @@ -0,0 +1,10 @@ +# from django.shortcuts import render + +# Create your views here. + +from django.http import HttpResponse + +def index(request): + return HttpResponse("

Hii

") +def greet(request, name): + return HttpResponse(f"Greetings! {name}") \ No newline at end of file diff --git a/backend/mydjangoproject/manage.py b/backend/mydjangoproject/manage.py new file mode 100644 index 000000000..62f3e6225 --- /dev/null +++ b/backend/mydjangoproject/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', 'mydjangoproject.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/backend/mydjangoproject/mydjangoproject/__init__.py b/backend/mydjangoproject/mydjangoproject/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/backend/mydjangoproject/mydjangoproject/asgi.py b/backend/mydjangoproject/mydjangoproject/asgi.py new file mode 100644 index 000000000..7e23598f6 --- /dev/null +++ b/backend/mydjangoproject/mydjangoproject/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for mydjangoproject 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', 'mydjangoproject.settings') + +application = get_asgi_application() diff --git a/backend/mydjangoproject/mydjangoproject/settings.py b/backend/mydjangoproject/mydjangoproject/settings.py new file mode 100644 index 000000000..86c98072b --- /dev/null +++ b/backend/mydjangoproject/mydjangoproject/settings.py @@ -0,0 +1,123 @@ +""" +Django settings for mydjangoproject project. + +Generated by 'django-admin startproject' using Django 4.2.2. + +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 + +# 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-*kroh#v#zj3z3z2g(1yy%j^$vetg)rpcr6gnh2v7g$#qt2ruy$' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'eCom.apps.EcomConfig', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'mydjangoproject.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 = 'mydjangoproject.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/4.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# 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/backend/mydjangoproject/mydjangoproject/urls.py b/backend/mydjangoproject/mydjangoproject/urls.py new file mode 100644 index 000000000..6d1b754ac --- /dev/null +++ b/backend/mydjangoproject/mydjangoproject/urls.py @@ -0,0 +1,23 @@ +""" +URL configuration for mydjangoproject 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 include,path +admin.site.site_header = "Admin Panel" +urlpatterns = [ + path('admin/', admin.site.urls), + path('',include("eCom.urls")), +] diff --git a/backend/mydjangoproject/mydjangoproject/wsgi.py b/backend/mydjangoproject/mydjangoproject/wsgi.py new file mode 100644 index 000000000..f2f677db2 --- /dev/null +++ b/backend/mydjangoproject/mydjangoproject/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for mydjangoproject 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', 'mydjangoproject.settings') + +application = get_wsgi_application() diff --git a/backend/week1/server.py b/backend/week1/server.py new file mode 100644 index 000000000..3eb5c1130 --- /dev/null +++ b/backend/week1/server.py @@ -0,0 +1,54 @@ +import http.server +import urllib.parse + +url_mappings = {} +class URLHandler(http.server.BaseHTTPRequestHandler): +# bacc + def do_POST(self): + url = urllib.parse.urlparse(self.path).path + try: + url_ = url.replace("/create/","") + short, dest = url_.split("/") + url_mappings[short] = (dest, 0) + self.send_response_only(201) + self.send_header("content-type","text") + self.end_headers() + self.wfile.write(bytes(f"mapped {short} to {dest}\n", "utf-8")) + return + except Exception as e: + self.send_response_only(406) + return + + def do_GET(self): + url = urllib.parse.urlparse(self.path).path + url = url.replace("/redirect/", "") + try: + dest = url_mappings[url] + except KeyError: + self.send_response_only(404) + self.send_header("error","Not Found") + self.end_headers() + self.wfile.write(bytes("Error\n", "utf-8")) + return + url_mappings[url] = (dest[0],dest[1]+1) + self.send_response_only(302) + self.send_header("content-type","text/html") + self.end_headers() + self.wfile.write(bytes(f"{dest[0]}\n", "utf-8")) + return + + +def run_server(): + server_address = ('', 8000) + httpd = http.server.HTTPServer(server_address, URLHandler) + print('Starting server on port 8000...') + try: + httpd.serve_forever() + except KeyboardInterrupt: + httpd.server_close() + print("\nexiting....") + exit() + except Exception as e: + print(e) +if __name__ == '__main__': + run_server() \ No newline at end of file diff --git a/frontend/week2/web/index.html b/frontend/week2/web/index.html new file mode 100644 index 000000000..0b9772be1 --- /dev/null +++ b/frontend/week2/web/index.html @@ -0,0 +1,38 @@ + + + + + + + + + Document + + +
+

GitHub Forks Dashboard

+
+ +
+
+
+ + + + + \ No newline at end of file diff --git a/frontend/week2/web/main.js b/frontend/week2/web/main.js new file mode 100644 index 000000000..6750e4904 --- /dev/null +++ b/frontend/week2/web/main.js @@ -0,0 +1,63 @@ +const API_BASE_URL = 'https://api.github.com'; +const OWNER = 'devclub-iitd'; +const REPO = 'summer-of-code-2023'; +const TOKEN = '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'; + +const div = document.getElementById("container") +// const url = `${API_BASE_URL}/repos/${OWNER}/${REPO}/forks` +async function getForks(url=`${API_BASE_URL}/repos/${OWNER}/${REPO}/forks`){ + loading(); + const headers = { + + } + let response = await fetch(url, + { + method: "GET", + } + ) + let result = await response.json() + console.log(result) + let links = (response.headers.get('link')) + let urls = links.split(",").map(e => { + return { + url: e.match(/<(.*)>/)[1], + title: e.split(";")[1].trim().match(/"(.*)"/)[1] + } + }) + + clear(); + div.innerHTML += '" + urls.forEach(e => { + let elem = `` + div.innerHTML += elem + }) +} + +async function getUserData(repo_name){ + let url = `${API_BASE_URL}/repos/${repo_name}/commits` + const request = await fetch(url); + let result = await request.json() + console.log(result); +} + +function clear(){ + div.innerHTML = "" +} +function loading(){ + div.classList.replace("d-none", "d-block") + div.innerHTML = "

loading...

" +} \ No newline at end of file