Skip to content

Commit

Permalink
setup project
Browse files Browse the repository at this point in the history
  • Loading branch information
keshavmohta009 committed Apr 23, 2023
0 parents commit df9719e
Show file tree
Hide file tree
Showing 140 changed files with 11,440 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
SECRET_KEY=abc
DEBUG=True

# Databse credentials
DATABASE_ENGINE=django.db.backends.postgresql
DATABASE_NAME=astro
DATABASE_USER=postgres
DATABASE_PASSWORD=qwer
DATABASE_HOST=localhost
DATABASE_PORT=5432

CELERY_BROKER_URL=redis://127.0.0.1:6379
CACHE_BROKER_URL=redis://127.0.0.1:6379/1

# creds for sending email service
EMAIL_HOST=sandbox.smtp.mailtrap.io
EMAIL_HOST_USER=aaea48213879d3
EMAIL_HOST_PASSWORD=31aed4f86b21fb
EMAIL_PORT=2525
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
env/
Empty file added astro/__init__.py
Empty file.
Binary file added astro/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file added astro/__pycache__/celery.cpython-39.pyc
Binary file not shown.
Binary file added astro/__pycache__/settings.cpython-39.pyc
Binary file not shown.
Binary file added astro/__pycache__/urls.cpython-39.pyc
Binary file not shown.
Binary file added astro/__pycache__/wsgi.cpython-39.pyc
Binary file not shown.
16 changes: 16 additions & 0 deletions astro/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for astro 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.1/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

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

application = get_asgi_application()
24 changes: 24 additions & 0 deletions astro/celery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from __future__ import absolute_import, unicode_literals

import os

from celery import Celery

# set the default Django settings module for the 'celery' program.
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "astro.settings")

app = Celery("astro")

# Using a string here means the worker don't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
app.config_from_object("django.conf:settings", namespace="CELERY")

# Load task modules from all registered Django app configs.
app.autodiscover_tasks()


@app.task(bind=True)
def debug_task(self):
print("Request: {0!r}".format(self.request))
190 changes: 190 additions & 0 deletions astro/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
"""
Django settings for astro project.
Generated by 'django-admin startproject' using Django 4.1.7.
For more information on this file, see
https://docs.djangoproject.com/en/4.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/
"""
from dotenv import load_dotenv

load_dotenv()

import os
from os import environ
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.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = environ["SECRET_KEY"]

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = environ["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",
"rest_framework",
"rest_framework.authtoken",
"django_celery_results",
"django_celery_beat",
"users",
"properties",
"bids",
]

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 = "astro.urls"

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": ["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 = "astro.wsgi.application"


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

DATABASES = {
"default": {
"ENGINE": environ["DATABASE_ENGINE"],
"NAME": environ["DATABASE_NAME"],
"USER": environ["DATABASE_USER"],
"PASSWORD": environ["DATABASE_PASSWORD"],
"HOST": environ["DATABASE_HOST"],
"PORT": environ["DATABASE_PORT"],
}
}


# Password validation
# https://docs.djangoproject.com/en/4.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/4.1/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/4.1/howto/static-files/

STATIC_URL = "static/"

# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"


REST_FRAMEWORK = {
"DEFAULT_AUTHENTICATION_CLASSES": [
"rest_framework.authentication.TokenAuthentication",
],
"DEFAULT_FILTER_BACKENDS": ["django_filters.rest_framework.DjangoFilterBackend"],
"DEFAULT_RENDERER_CLASSES": [
"rest_framework.renderers.JSONRenderer",
]
+ (["rest_framework.renderers.BrowsableAPIRenderer"] if DEBUG else []),
}

AUTH_USER_MODEL = "users.User"
STATIC_URL = "/static/"
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media")


CELERY_BROKER_URL = environ["CELERY_BROKER_URL"]
CELERY_RESULT_BACKEND = "django-db"
CELERY_CACHE_BACKEND = "django-cache"
CELERY_ACCEPT_CONTENT = ["json", "pickle"]
CELERY_TASK_SERIALIZER = "json"
CELERY_RESULT_SERIALIZER = "json"
CELERY_BROKER_TRANSPORT_OPTIONS = {
"max_retries": environ.get("CELERY_PUBLISH_MAX_RETRIES", 1)
}
CELERY_SEND_TASK_ERROR_EMAILS = True
CELERY_IGNORE_RESULT = False
CELERY_SEND_EVENTS = True
DJANGO_CELERY_RESULTS_TASK_ID_MAX_LENGTH = 100

from celery.schedules import crontab

CELERY_BEAT_SCHEDULE = {
"mark_inactive_property_in_every_15_minutes": {
"task": "properties.tasks.mark_inactive_property",
"schedule": crontab(minute="*/15"),
}
}


EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = environ["EMAIL_HOST"]
EMAIL_HOST_USER = environ["EMAIL_HOST_USER"]
EMAIL_HOST_PASSWORD = environ["EMAIL_HOST_PASSWORD"]
EMAIL_PORT = environ["EMAIL_PORT"]
44 changes: 44 additions & 0 deletions astro/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""astro URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.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.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.shortcuts import render
from django.urls import include, path


def home(request):
return render(request, "index.html")


def about(request):
return render(request, "about.html")


def contact(request):
return render(request, "contact.html")


urlpatterns = [
path("", home, name="home"),
path("about/", about, name="about"),
path("contact/", contact, name="contact"),
path("admin/", admin.site.urls),
path("users/", include("users.urls")),
path("properties/", include("properties.urls")),
path("bids/", include("bids.urls")),
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
16 changes: 16 additions & 0 deletions astro/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for astro 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.1/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

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

application = get_wsgi_application()
Empty file added bids/__init__.py
Empty file.
Binary file added bids/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file added bids/__pycache__/admin.cpython-39.pyc
Binary file not shown.
Binary file added bids/__pycache__/apps.cpython-39.pyc
Binary file not shown.
Binary file added bids/__pycache__/models.cpython-39.pyc
Binary file not shown.
Binary file added bids/__pycache__/serializers.cpython-39.pyc
Binary file not shown.
Binary file added bids/__pycache__/urls.cpython-39.pyc
Binary file not shown.
Binary file added bids/__pycache__/views.cpython-39.pyc
Binary file not shown.
11 changes: 11 additions & 0 deletions bids/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.contrib import admin
from django.contrib.admin import ModelAdmin

from bids.models import Auction


@admin.register(Auction)
class AuctionAdmin(ModelAdmin):
list_display = ("id", "property", "buyer", "amount", "is_active", "date_created")
list_filter = ("is_active",)
search_fields = ("property__name", "buyer__email", "amount")
6 changes: 6 additions & 0 deletions bids/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class BidsConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "bids"
56 changes: 56 additions & 0 deletions bids/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Generated by Django 4.1.7 on 2023-03-25 17:41

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone


class Migration(migrations.Migration):
initial = True

dependencies = [
("properties", "0001_initial"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name="Auction",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("amount", models.PositiveBigIntegerField()),
("is_active", models.BooleanField(default=True)),
(
"date_created",
models.DateTimeField(default=django.utils.timezone.now),
),
(
"buyer",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
to=settings.AUTH_USER_MODEL,
),
),
(
"property",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
to="properties.property",
),
),
],
options={
"verbose_name": "Auction",
"verbose_name_plural": "Auctions",
},
),
]
Empty file added bids/migrations/__init__.py
Empty file.
Binary file not shown.
Binary file added bids/migrations/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Loading

0 comments on commit df9719e

Please sign in to comment.