Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
harshakhmk committed Jan 8, 2021
0 parents commit 3b2b477
Show file tree
Hide file tree
Showing 232 changed files with 32,210 additions and 0 deletions.
Empty file added CanteenProject/__init__.py
Empty file.
Binary file added CanteenProject/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file added CanteenProject/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file added CanteenProject/__pycache__/wsgi.cpython-38.pyc
Binary file not shown.
16 changes: 16 additions & 0 deletions CanteenProject/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for CanteenProject 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/3.1/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'CanteenProject.settings')

application = get_asgi_application()
129 changes: 129 additions & 0 deletions CanteenProject/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
"""
Django settings for CanteenProject project.
Generated by 'django-admin startproject' using Django 3.1.3.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
import os
from pathlib import Path
import RegisterUserApp

# 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/3.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'b+%wn4a8kiu)we5&o3xdo-s&%!yr@24(&r#gv2*lo%xh%6=4'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['127.0.0.1']


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'RegisterUserApp',
'Productsapp',
]

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 = 'CanteenProject.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR,'templates')],
'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 = 'CanteenProject.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
AUTH_USER_MODEL="RegisterUserApp.User"

# Password validation
# https://docs.djangoproject.com/en/3.1/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/3.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_URL = '/static/'
#STATIC_ROOT=os.path.join(BASE_DIR,'assets')
STATICFILES_DIRS=[ os.path.join(BASE_DIR,'static')]

MEDIA_ROOT=os.path.join(BASE_DIR,'static/images')

MEDIA_URL='/images/'
25 changes: 25 additions & 0 deletions CanteenProject/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""CanteenProject URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.1/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
from django.conf.urls.static import static
from django.conf import settings
urlpatterns = [
path('admin/', admin.site.urls),
path('accounts/',include('RegisterUserApp.urls')),
path('',include('Productsapp.urls')),
]#+static(settings.STATIC_URL,document_root=settings.STATIC_URL)
#urlpatterns+=static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)
16 changes: 16 additions & 0 deletions CanteenProject/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for CanteenProject 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/3.1/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'CanteenProject.settings')

application = get_wsgi_application()
Binary file not shown.
12 changes: 12 additions & 0 deletions Productsapp/Handleviews/customers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.contrib import messages
from django.contrib.auth import login
from django.contrib.auth.decorators import login_required
from django.db import transaction
from django.db.models import Count
from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse_lazy
from django.utils.decorators import method_decorator




133 changes: 133 additions & 0 deletions Productsapp/Handleviews/vendors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
from django.contrib import messages
from django.contrib.auth import login
from django.contrib.auth.decorators import login_required
from django.db import transaction
from django.db.models import Count
from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse_lazy
from django.utils.decorators import method_decorator
from django.views.generic import CreateView, ListView, UpdateView
from RegisterUserApp.decorators import *
from ..models import *
from ..forms import *
from RegisterUserApp.models import *
from django.forms.utils import ValidationError

def is_owner(request,id):
restaurent=Restaurent.objects.get(id=id)

return request.user==restaurent.owner_of

@login_required(login_url="/accounts/login")
@vendor_required
def create_product(request,restaurent_id):
if request.method=="GET" :
form=ProductAddForm()
return render(request,"create_product.html",{'form':form})
else: # For now nly post request
if is_owner(request,restaurent_id):
form_data=ProductAddForm(request.POST or None,request=request)
if form_data.is_valid():
form_data.save()
messages.info(request,"Succesfully created")
# Going to rest products list
return redirect("restaurent_products",kwargs={'id':restaurent_id})
else : # Not valid form
messages.info(request," Something error occured while creating pls try again")
return redirect("create_product",kwargs={'restaurent_id':restaurent_id})
else :
messages.info(request,"You are not allowed to create product in this restaurent")
return redirect('/')




@login_required(login_url="/accounts/login")
@vendor_required
def delete_product(request,restaurent_id,product_id):
prod=Product.objects.get(id=product_id)
if prod.restaurent_id.owner_of==request.user :
prod.is_present=False
messages.success("The product is successfully deleted")
prod.delete()
return redirect("restaurent_products",kwargs={'id':restaurent_id})
else :
messages.info(request,"You are not allowed to modify here")
return redirect('/')

@login_required(login_url="/accounts/login")
@vendor_required
def update_product(request,restaurent_id,product_id):

if request.method=="POST":
prod=Product.objects.get(id=product_id)
if prod.restaurent_id.owner_of==request.user :

form_data=ProductUpdateForm(request.POST or None ,instance=prod)
if form_data.is_valid() :
form_data.save()
messages.info(request,"The product is successfully Updated")
return redirect("restaurent_products",kwargs={'id':restaurent_id})
else : #Not valid form, so redirecting to same page
return redirect("update_product",
kwargs={
'restaurent_id':restaurent_id,
'product_id':product_id
}
)
else :
messages.warning("You aren't allowed to modify here")
return redirect("/")
else:
form=ProductUpdateForm()
return render(request,"Product.html",{'form':form})


@login_required(login_url="/accounts/login")
@vendor_required
def Create_Restaurent(request,**kwargs):
if request.method=="POST":
form=RestaurentAddForm(request.POST , request=request )
if form.is_valid():
form.save()
messages.info(request,"The Restaurent is successfully Created")
else : # Not valid form
messages.info(request,"Fill the deatils properly")
return redirect('/')

elif request.method=="GET" :
form= RestaurentAddForm()
return render(request,"Restaurent.html",{'form':form})


@login_required(login_url="/accounts/login")
@vendor_required
def Update_Restaurent(request,id):
restaurent=get_object_or_404(Restaurent,id=id)
if request.method=="POST":
if request.user==restaurent.owner_of :
form=RestaurentUpdateForm(request.POST ,instance=restaurent)
if form.is_valid():
form.save()
messages.info(request,"Successfully updated")

else :
messages.info(request,"Not updatable right now try again later")
else :
messages.info(request,"Not updatable right You don't have access rights")
return redirect('/')
elif request.method=="GET" :
form= RestaurentUpdateForm()
return render(request,"Restaurent.html",{'form':form})

@login_required(login_url="/accounts/login")
@vendor_required
def Delete_Restaurent(request,id):
if is_owner(request,id) :
restaurent=Restaurent.objects.get(id=id)
messages.info(request," allowed ")

restaurent.delete()
else :
messages.info(request,"You don't have access rights, not allowed ")
return redirect('/')
Empty file added Productsapp/__init__.py
Empty file.
Binary file added Productsapp/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file added Productsapp/__pycache__/admin.cpython-38.pyc
Binary file not shown.
Binary file added Productsapp/__pycache__/forms.cpython-38.pyc
Binary file not shown.
Binary file added Productsapp/__pycache__/models.cpython-38.pyc
Binary file not shown.
Binary file added Productsapp/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file added Productsapp/__pycache__/views.cpython-38.pyc
Binary file not shown.
8 changes: 8 additions & 0 deletions Productsapp/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.contrib import admin
from .models import *
# Register your models here.
admin.site.register(Restaurent)
admin.site.register(Product)
admin.site.register(OrderProduct)
admin.site.register(Order)
admin.site.register(ShippingAddress)
5 changes: 5 additions & 0 deletions Productsapp/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class ProductsappConfig(AppConfig):
name = 'Productsapp'
Loading

0 comments on commit 3b2b477

Please sign in to comment.