Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

No proper deployment #32

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
venv/*
venv
backend/mydjangoproject/eCom/__pycache__/*
backend/mydjangoproject/mydjangoproject/__pycache__/*
4 changes: 2 additions & 2 deletions author.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "",
"entry_number": ""
"name": "Lakshya Mahajan",
"entry_number": "2022CH11429"
}
Binary file added backend/mydjangoproject/db.sqlite3
Binary file not shown.
Empty file.
4 changes: 4 additions & 0 deletions backend/mydjangoproject/eCom/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from django.contrib import admin
from .models import Product
# Register your models here.
admin.site.register(Product)
6 changes: 6 additions & 0 deletions backend/mydjangoproject/eCom/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class EcomConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'eCom'
24 changes: 24 additions & 0 deletions backend/mydjangoproject/eCom/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -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()),
],
),
]
Original file line number Diff line number Diff line change
@@ -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),
),
]
Original file line number Diff line number Diff line change
@@ -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',
),
]
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions backend/mydjangoproject/eCom/models.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions backend/mydjangoproject/eCom/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
8 changes: 8 additions & 0 deletions backend/mydjangoproject/eCom/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.urls import path

from . import views

urlpatterns = [
path("", views.index, name="index"),
path("greet/<str:name>", views.greet, name="greetingsss")
]
10 changes: 10 additions & 0 deletions backend/mydjangoproject/eCom/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# from django.shortcuts import render

# Create your views here.

from django.http import HttpResponse

def index(request):
return HttpResponse("<h1>Hii</h1>")
def greet(request, name):
return HttpResponse(f"Greetings! {name}")
22 changes: 22 additions & 0 deletions backend/mydjangoproject/manage.py
Original file line number Diff line number Diff line change
@@ -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()
Empty file.
16 changes: 16 additions & 0 deletions backend/mydjangoproject/mydjangoproject/asgi.py
Original file line number Diff line number Diff line change
@@ -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()
123 changes: 123 additions & 0 deletions backend/mydjangoproject/mydjangoproject/settings.py
Original file line number Diff line number Diff line change
@@ -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'
23 changes: 23 additions & 0 deletions backend/mydjangoproject/mydjangoproject/urls.py
Original file line number Diff line number Diff line change
@@ -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")),
]
16 changes: 16 additions & 0 deletions backend/mydjangoproject/mydjangoproject/wsgi.py
Original file line number Diff line number Diff line change
@@ -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()
54 changes: 54 additions & 0 deletions backend/week1/server.py
Original file line number Diff line number Diff line change
@@ -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()
Loading