Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# macOS
.DS_Store

# JavaScript dependencies and builds
node_modules/
build/

# Python caches and virtual environments
__pycache__/
*.py[cod]
venv/
.venv/

# Local configuration
.env
.env.*
!.env.example

# Django local data and uploaded media
*.sqlite3
media/
Empty file.
16 changes: 16 additions & 0 deletions Django_backend/BookMyVenue_project/BookMyVenue_project/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for BookMyVenue_project 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/6.0/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

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

application = get_asgi_application()
140 changes: 140 additions & 0 deletions Django_backend/BookMyVenue_project/BookMyVenue_project/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
"""
Django settings for BookMyVenue_project project.

Generated by 'django-admin startproject' using Django 6.0.6.

For more information on this file, see
https://docs.djangoproject.com/en/6.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/6.0/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/6.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-$%r^q!lcrf&9g^r(b9$lv((05^v(1z8fg+uh8j=@&0#b#wl&uf'

# 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',
'users',
'venues',

"rest_framework",
"corsheaders",
]
AUTH_USER_MODEL = "users.User"

CORS_ALLOWED_ORIGINS = [
"http://localhost:3000",
"http://127.0.0.1:3000",
"http://localhost:5173",
"http://127.0.0.1:5173",
]

REST_FRAMEWORK = {
"DEFAULT_AUTHENTICATION_CLASSES": (
"rest_framework_simplejwt.authentication.JWTAuthentication",
),
}

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'corsheaders.middleware.CorsMiddleware',
'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 = 'BookMyVenue_project.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'BookMyVenue_project.wsgi.application'


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

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


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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


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

STATIC_URL = 'static/'

MEDIA_URL = 'media/'
MEDIA_ROOT = BASE_DIR / 'media'
30 changes: 30 additions & 0 deletions Django_backend/BookMyVenue_project/BookMyVenue_project/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
URL configuration for BookMyVenue_project project.

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/6.0/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.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import include, path

urlpatterns = [
path('admin/', admin.site.urls),

path('api/', include('users.api.urls')),
path('api/', include('venues.api.urls')),
]

if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
16 changes: 16 additions & 0 deletions Django_backend/BookMyVenue_project/BookMyVenue_project/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for BookMyVenue_project 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/6.0/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

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

application = get_wsgi_application()
22 changes: 22 additions & 0 deletions Django_backend/BookMyVenue_project/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', 'BookMyVenue_project.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.
15 changes: 15 additions & 0 deletions Django_backend/BookMyVenue_project/users/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.contrib import admin

# Register your models here.
from .models import User,OwnerProfile,UserProfile

admin.site.register(User)

@admin.register(UserProfile)
class UserProfileAdmin(admin.ModelAdmin):
list_display = ("user", "address", "phone_number")


@admin.register(OwnerProfile)
class OwnerProfileAdmin(admin.ModelAdmin):
list_display = ("user", "address", "phone_number")
54 changes: 54 additions & 0 deletions Django_backend/BookMyVenue_project/users/api/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from rest_framework import serializers
from ..models import User, UserProfile,OwnerProfile
from django.db import transaction

class UserSerializers(serializers.ModelSerializer):
password = serializers.CharField(write_only=True)
address = serializers.CharField(write_only=True, required=False, allow_blank=True)
phone_number = serializers.CharField(write_only=True, required=False, allow_blank=True)

class Meta:
model = User
fields = [
"id",
"username",
"fullname",
"email",
"password",
"account_type",
"terms_privacy",
"address",
"phone_number",
]

def validate_terms_privacy(self,value):
if value is not True:
raise serializers.ValidationError("You must accept terms and privacy policy.")
return value

@transaction.atomic
def create(self, validated_data):
address = validated_data.pop("address", "")

phone_number = validated_data.pop("phone_number", "")

password = validated_data.pop("password")

user = User(**validated_data)
user.set_password(password)
user.save()

if user.account_type == "venue_owner":
OwnerProfile.objects.create(
user=user,
address=address,
phone_number=phone_number,
)
elif user.account_type == "venue_user":
UserProfile.objects.create(
user=user,
address=address,
phone_number=phone_number,
)

return user
11 changes: 11 additions & 0 deletions Django_backend/BookMyVenue_project/users/api/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.urls import path
from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView

from .views import RegisterView, MeView

urlpatterns = [
path("signup/", RegisterView.as_view(), name="signup"),
path("login/", TokenObtainPairView.as_view(), name="login"),
path("token/refresh/", TokenRefreshView.as_view(), name="token_refresh"),
path("me/", MeView.as_view(), name="me"),
]
26 changes: 26 additions & 0 deletions Django_backend/BookMyVenue_project/users/api/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from rest_framework import generics
from rest_framework.permissions import AllowAny, IsAuthenticated
from rest_framework.response import Response # type: ignore[import]
from rest_framework.views import APIView

from .serializers import UserSerializers


class RegisterView(generics.CreateAPIView):
serializer_class = UserSerializers
permission_classes = [AllowAny]


class MeView(APIView):
permission_classes = [IsAuthenticated]

def get(self, request):
user = request.user

return Response({
"id": user.id,
"username": user.username,
"fullname": user.fullname,
"email": user.email,
"account_type": user.account_type,
})
5 changes: 5 additions & 0 deletions Django_backend/BookMyVenue_project/users/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class UsersConfig(AppConfig):
name = 'users'
Loading