commit b003f98cbaf4cd1520542758159153373cdd198e Author: Surya-AI Date: Sat Jul 6 20:29:07 2024 +0530 initial commit diff --git a/BH/__init__.py b/BH/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/BH/__pycache__/__init__.cpython-310.pyc b/BH/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..3e164d9 Binary files /dev/null and b/BH/__pycache__/__init__.cpython-310.pyc differ diff --git a/BH/__pycache__/__init__.cpython-37.pyc b/BH/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..6790a59 Binary files /dev/null and b/BH/__pycache__/__init__.cpython-37.pyc differ diff --git a/BH/__pycache__/__init__.cpython-38.pyc b/BH/__pycache__/__init__.cpython-38.pyc new file mode 100644 index 0000000..f4e099d Binary files /dev/null and b/BH/__pycache__/__init__.cpython-38.pyc differ diff --git a/BH/__pycache__/settings.cpython-310.pyc b/BH/__pycache__/settings.cpython-310.pyc new file mode 100644 index 0000000..5db1f43 Binary files /dev/null and b/BH/__pycache__/settings.cpython-310.pyc differ diff --git a/BH/__pycache__/settings.cpython-37.pyc b/BH/__pycache__/settings.cpython-37.pyc new file mode 100644 index 0000000..7584244 Binary files /dev/null and b/BH/__pycache__/settings.cpython-37.pyc differ diff --git a/BH/__pycache__/settings.cpython-38.pyc b/BH/__pycache__/settings.cpython-38.pyc new file mode 100644 index 0000000..0019689 Binary files /dev/null and b/BH/__pycache__/settings.cpython-38.pyc differ diff --git a/BH/__pycache__/urls.cpython-310.pyc b/BH/__pycache__/urls.cpython-310.pyc new file mode 100644 index 0000000..07946e4 Binary files /dev/null and b/BH/__pycache__/urls.cpython-310.pyc differ diff --git a/BH/__pycache__/urls.cpython-37.pyc b/BH/__pycache__/urls.cpython-37.pyc new file mode 100644 index 0000000..a386431 Binary files /dev/null and b/BH/__pycache__/urls.cpython-37.pyc differ diff --git a/BH/__pycache__/urls.cpython-38.pyc b/BH/__pycache__/urls.cpython-38.pyc new file mode 100644 index 0000000..2d881e3 Binary files /dev/null and b/BH/__pycache__/urls.cpython-38.pyc differ diff --git a/BH/__pycache__/wsgi.cpython-310.pyc b/BH/__pycache__/wsgi.cpython-310.pyc new file mode 100644 index 0000000..83c58b9 Binary files /dev/null and b/BH/__pycache__/wsgi.cpython-310.pyc differ diff --git a/BH/__pycache__/wsgi.cpython-37.pyc b/BH/__pycache__/wsgi.cpython-37.pyc new file mode 100644 index 0000000..0099be2 Binary files /dev/null and b/BH/__pycache__/wsgi.cpython-37.pyc differ diff --git a/BH/__pycache__/wsgi.cpython-38.pyc b/BH/__pycache__/wsgi.cpython-38.pyc new file mode 100644 index 0000000..57c5d61 Binary files /dev/null and b/BH/__pycache__/wsgi.cpython-38.pyc differ diff --git a/BH/asgi.py b/BH/asgi.py new file mode 100644 index 0000000..334d6ae --- /dev/null +++ b/BH/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for TechBlog 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.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'BH.settings') + +application = get_asgi_application() diff --git a/BH/settings.py b/BH/settings.py new file mode 100644 index 0000000..8f510c3 --- /dev/null +++ b/BH/settings.py @@ -0,0 +1,130 @@ +""" +Django settings for TechBlog project. + +Generated by 'django-admin startproject' using Django 3.0.6. + +For more information on this file, see +https://docs.djangoproject.com/en/3.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/3.0/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +TEMPLATES_DIR = os.path.join(BASE_DIR + '/templates') + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '!2g)+m+_h9fq9%il5+t5#qnj^9502or6$=2!$==v=i2*c#7q*m' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'crispy_forms', + 'crispy_bootstrap4', + 'blog.apps.BlogConfig', + 'users.apps.UsersConfig', + '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 = 'BH.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [TEMPLATES_DIR], + '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 = 'BH.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/3.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/3.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/3.0/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.0/howto/static-files/ + +STATIC_URL = '/static/' +MEDIA_ROOT = os.path.join(BASE_DIR + '/media') +MEDIA_URL = '/media/' + +CRISPY_TEMPLATE_PACK = 'bootstrap4' +LOGIN_REDIRECT_URL = 'Home' +LOGIN_URL = 'Login' diff --git a/BH/urls.py b/BH/urls.py new file mode 100644 index 0000000..13801d3 --- /dev/null +++ b/BH/urls.py @@ -0,0 +1,28 @@ +"""TechBlog URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/3.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 path, include + +urlpatterns = [ + path('', include('blog.urls')), + path('users/', include('users.urls')), + path('admin/', admin.site.urls), +] + +if settings.DEBUG: + urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/BH/wsgi.py b/BH/wsgi.py new file mode 100644 index 0000000..ff12a9b --- /dev/null +++ b/BH/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for TechBlog 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.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'BH.settings') + +application = get_wsgi_application() diff --git a/blog/__init__.py b/blog/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/blog/__pycache__/__init__.cpython-310.pyc b/blog/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..8802351 Binary files /dev/null and b/blog/__pycache__/__init__.cpython-310.pyc differ diff --git a/blog/__pycache__/__init__.cpython-37.pyc b/blog/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..cbc0e52 Binary files /dev/null and b/blog/__pycache__/__init__.cpython-37.pyc differ diff --git a/blog/__pycache__/__init__.cpython-38.pyc b/blog/__pycache__/__init__.cpython-38.pyc new file mode 100644 index 0000000..5615897 Binary files /dev/null and b/blog/__pycache__/__init__.cpython-38.pyc differ diff --git a/blog/__pycache__/admin.cpython-310.pyc b/blog/__pycache__/admin.cpython-310.pyc new file mode 100644 index 0000000..749fc5a Binary files /dev/null and b/blog/__pycache__/admin.cpython-310.pyc differ diff --git a/blog/__pycache__/admin.cpython-37.pyc b/blog/__pycache__/admin.cpython-37.pyc new file mode 100644 index 0000000..15e3b75 Binary files /dev/null and b/blog/__pycache__/admin.cpython-37.pyc differ diff --git a/blog/__pycache__/admin.cpython-38.pyc b/blog/__pycache__/admin.cpython-38.pyc new file mode 100644 index 0000000..17f9a14 Binary files /dev/null and b/blog/__pycache__/admin.cpython-38.pyc differ diff --git a/blog/__pycache__/apps.cpython-310.pyc b/blog/__pycache__/apps.cpython-310.pyc new file mode 100644 index 0000000..928572b Binary files /dev/null and b/blog/__pycache__/apps.cpython-310.pyc differ diff --git a/blog/__pycache__/apps.cpython-37.pyc b/blog/__pycache__/apps.cpython-37.pyc new file mode 100644 index 0000000..ad826e3 Binary files /dev/null and b/blog/__pycache__/apps.cpython-37.pyc differ diff --git a/blog/__pycache__/apps.cpython-38.pyc b/blog/__pycache__/apps.cpython-38.pyc new file mode 100644 index 0000000..dd6c019 Binary files /dev/null and b/blog/__pycache__/apps.cpython-38.pyc differ diff --git a/blog/__pycache__/models.cpython-310.pyc b/blog/__pycache__/models.cpython-310.pyc new file mode 100644 index 0000000..8211a99 Binary files /dev/null and b/blog/__pycache__/models.cpython-310.pyc differ diff --git a/blog/__pycache__/models.cpython-37.pyc b/blog/__pycache__/models.cpython-37.pyc new file mode 100644 index 0000000..7d6f8b4 Binary files /dev/null and b/blog/__pycache__/models.cpython-37.pyc differ diff --git a/blog/__pycache__/models.cpython-38.pyc b/blog/__pycache__/models.cpython-38.pyc new file mode 100644 index 0000000..c989aa6 Binary files /dev/null and b/blog/__pycache__/models.cpython-38.pyc differ diff --git a/blog/__pycache__/urls.cpython-310.pyc b/blog/__pycache__/urls.cpython-310.pyc new file mode 100644 index 0000000..6aaf71f Binary files /dev/null and b/blog/__pycache__/urls.cpython-310.pyc differ diff --git a/blog/__pycache__/urls.cpython-37.pyc b/blog/__pycache__/urls.cpython-37.pyc new file mode 100644 index 0000000..82d2c4f Binary files /dev/null and b/blog/__pycache__/urls.cpython-37.pyc differ diff --git a/blog/__pycache__/urls.cpython-38.pyc b/blog/__pycache__/urls.cpython-38.pyc new file mode 100644 index 0000000..e53f2dc Binary files /dev/null and b/blog/__pycache__/urls.cpython-38.pyc differ diff --git a/blog/__pycache__/views.cpython-310.pyc b/blog/__pycache__/views.cpython-310.pyc new file mode 100644 index 0000000..26c9368 Binary files /dev/null and b/blog/__pycache__/views.cpython-310.pyc differ diff --git a/blog/__pycache__/views.cpython-37.pyc b/blog/__pycache__/views.cpython-37.pyc new file mode 100644 index 0000000..cf6a275 Binary files /dev/null and b/blog/__pycache__/views.cpython-37.pyc differ diff --git a/blog/__pycache__/views.cpython-38.pyc b/blog/__pycache__/views.cpython-38.pyc new file mode 100644 index 0000000..d193f82 Binary files /dev/null and b/blog/__pycache__/views.cpython-38.pyc differ diff --git a/blog/admin.py b/blog/admin.py new file mode 100644 index 0000000..2e1201d --- /dev/null +++ b/blog/admin.py @@ -0,0 +1,10 @@ +from django.contrib import admin +from .models import * + + +# Register your models here. +class BlogAdmin(admin.ModelAdmin): + list_display = ('title', 'author', 'date_posted') + + +admin.site.register(Blog, BlogAdmin) \ No newline at end of file diff --git a/blog/apps.py b/blog/apps.py new file mode 100644 index 0000000..7930587 --- /dev/null +++ b/blog/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class BlogConfig(AppConfig): + name = 'blog' diff --git a/blog/migrations/0001_initial.py b/blog/migrations/0001_initial.py new file mode 100644 index 0000000..0ad9371 --- /dev/null +++ b/blog/migrations/0001_initial.py @@ -0,0 +1,28 @@ +# Generated by Django 3.1.7 on 2021-04-29 07:06 + +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 = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Blog', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('content', models.TextField()), + ('title', models.CharField(max_length=100)), + ('date_posted', models.DateTimeField(default=django.utils.timezone.now)), + ('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/blog/migrations/0002_blog_likes_alter_blog_title_blogcomment_post_and_more.py b/blog/migrations/0002_blog_likes_alter_blog_title_blogcomment_post_and_more.py new file mode 100644 index 0000000..34e5371 --- /dev/null +++ b/blog/migrations/0002_blog_likes_alter_blog_title_blogcomment_post_and_more.py @@ -0,0 +1,58 @@ +# Generated by Django 5.0.2 on 2024-03-15 10:14 + +import django.db.models.deletion +import django.utils.timezone +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('blog', '0001_initial'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.AddField( + model_name='blog', + name='likes', + field=models.ManyToManyField(related_name='blog_like', to=settings.AUTH_USER_MODEL), + ), + migrations.AlterField( + model_name='blog', + name='title', + field=models.CharField(max_length=150), + ), + migrations.CreateModel( + name='BlogComment', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('content', models.CharField(max_length=250)), + ('date_posted', models.DateTimeField(default=django.utils.timezone.now)), + ('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ('blog', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='blog.blog')), + ('likes', models.ManyToManyField(related_name='blog_comment_like', to=settings.AUTH_USER_MODEL)), + ], + ), + migrations.CreateModel( + name='Post', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('content', models.TextField()), + ('date_posted', models.DateTimeField(default=django.utils.timezone.now)), + ('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ('likes', models.ManyToManyField(related_name='post_like', to=settings.AUTH_USER_MODEL)), + ], + ), + migrations.CreateModel( + name='PostComment', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('content', models.CharField(max_length=250)), + ('date_posted', models.DateTimeField(default=django.utils.timezone.now)), + ('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ('post', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='blog.post')), + ], + ), + ] diff --git a/blog/migrations/__init__.py b/blog/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/blog/migrations/__pycache__/0001_initial.cpython-310.pyc b/blog/migrations/__pycache__/0001_initial.cpython-310.pyc new file mode 100644 index 0000000..09b8ef5 Binary files /dev/null and b/blog/migrations/__pycache__/0001_initial.cpython-310.pyc differ diff --git a/blog/migrations/__pycache__/0001_initial.cpython-37.pyc b/blog/migrations/__pycache__/0001_initial.cpython-37.pyc new file mode 100644 index 0000000..8eaff9b Binary files /dev/null and b/blog/migrations/__pycache__/0001_initial.cpython-37.pyc differ diff --git a/blog/migrations/__pycache__/0001_initial.cpython-38.pyc b/blog/migrations/__pycache__/0001_initial.cpython-38.pyc new file mode 100644 index 0000000..4628c94 Binary files /dev/null and b/blog/migrations/__pycache__/0001_initial.cpython-38.pyc differ diff --git a/blog/migrations/__pycache__/0002_auto_20200510_1812.cpython-37.pyc b/blog/migrations/__pycache__/0002_auto_20200510_1812.cpython-37.pyc new file mode 100644 index 0000000..d022425 Binary files /dev/null and b/blog/migrations/__pycache__/0002_auto_20200510_1812.cpython-37.pyc differ diff --git a/blog/migrations/__pycache__/0002_blog_likes_alter_blog_title_blogcomment_post_and_more.cpython-310.pyc b/blog/migrations/__pycache__/0002_blog_likes_alter_blog_title_blogcomment_post_and_more.cpython-310.pyc new file mode 100644 index 0000000..9f0f47c Binary files /dev/null and b/blog/migrations/__pycache__/0002_blog_likes_alter_blog_title_blogcomment_post_and_more.cpython-310.pyc differ diff --git a/blog/migrations/__pycache__/0003_auto_20200517_1058.cpython-37.pyc b/blog/migrations/__pycache__/0003_auto_20200517_1058.cpython-37.pyc new file mode 100644 index 0000000..352c441 Binary files /dev/null and b/blog/migrations/__pycache__/0003_auto_20200517_1058.cpython-37.pyc differ diff --git a/blog/migrations/__pycache__/__init__.cpython-310.pyc b/blog/migrations/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..4e8b1f0 Binary files /dev/null and b/blog/migrations/__pycache__/__init__.cpython-310.pyc differ diff --git a/blog/migrations/__pycache__/__init__.cpython-37.pyc b/blog/migrations/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..9005b92 Binary files /dev/null and b/blog/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/blog/migrations/__pycache__/__init__.cpython-38.pyc b/blog/migrations/__pycache__/__init__.cpython-38.pyc new file mode 100644 index 0000000..f15357a Binary files /dev/null and b/blog/migrations/__pycache__/__init__.cpython-38.pyc differ diff --git a/blog/models.py b/blog/models.py new file mode 100644 index 0000000..5ada5ee --- /dev/null +++ b/blog/models.py @@ -0,0 +1,21 @@ +from django.contrib.auth.models import User +from django.db import models +from django.utils import timezone + + +# Create your models here. +class Blog(models.Model): + content = models.TextField() + title = models.CharField(max_length=150) + author = models.ForeignKey(User, on_delete=models.CASCADE) + date_posted = models.DateTimeField(default=timezone.now) + + def get_absolute_url(self): + return '/' + + + +class Post(models.Model): + content = models.TextField() + author = models.ForeignKey(User, on_delete=models.CASCADE) + date_posted = models.DateTimeField(default=timezone.now) diff --git a/blog/templatetags/__pycache__/markdown_extras.cpython-310.pyc b/blog/templatetags/__pycache__/markdown_extras.cpython-310.pyc new file mode 100644 index 0000000..5da7297 Binary files /dev/null and b/blog/templatetags/__pycache__/markdown_extras.cpython-310.pyc differ diff --git a/blog/templatetags/markdown_extras.py b/blog/templatetags/markdown_extras.py new file mode 100644 index 0000000..b3b708c --- /dev/null +++ b/blog/templatetags/markdown_extras.py @@ -0,0 +1,12 @@ +from django import template +from django.template.defaultfilters import stringfilter + +import markdown as md + + +register = template.Library() + +@register.filter() +@stringfilter +def markdown(value): + return md.markdown(value, extensions=['markdown.extensions.fenced_code']) \ No newline at end of file diff --git a/blog/tests.py b/blog/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/blog/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/blog/urls.py b/blog/urls.py new file mode 100644 index 0000000..11d896d --- /dev/null +++ b/blog/urls.py @@ -0,0 +1,11 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('', views.home, name='Home'), + path('blog/', views.BlogDetailView.as_view(), name='Blog'), + path('blog/create/', views.BlogCreateView.as_view(), name='Blog Create'), + path('post/', views.PostDetailView.as_view(), name='Post'), + path('post/create/', views.PostCreateView.as_view(), name='Post Create'), + path('about/', views.about, name='About') +] diff --git a/blog/views.py b/blog/views.py new file mode 100644 index 0000000..6c9e863 --- /dev/null +++ b/blog/views.py @@ -0,0 +1,77 @@ +from django.shortcuts import render +from django.contrib.auth.mixins import * +from django.views.generic import * +from .models import * + + +# Create your views here. +def home(request): + blogs = { + 'blog': Blog.objects.all() + } + + allow_empty = True + queryset = None + model = Post + paginate_by = None + paginate_orphans = 0 + context_object_name = 'posts' + # paginator_class = Paginator + # page_kwarg = "page" + ordering = ['-date_posted'] + + if queryset is not None: + queryset = queryset + if isinstance(queryset, QuerySet): + queryset = queryset.all() + elif model is not None: + queryset = model._default_manager.all() + else: + raise ImproperlyConfigured( + "%(cls)s is missing a QuerySet. Define " + "%(cls)s.model, %(cls)s.queryset, or override " + "%(cls)s.get_queryset()." % {"cls": self.__class__.__name__} + ) + + if ordering: + if isinstance(ordering, str): + ordering = (ordering,) + queryset = queryset.order_by(*ordering) + + return render(request, 'blog/home.html', { context_object_name: queryset, 'topics': ['Django', 'UkraineConflict', 'TechBlog'] }) + + +class BlogDetailView(DetailView): + model = Blog + template_name = 'blog/blogDetail.html' + + +class BlogCreateView(LoginRequiredMixin, CreateView): + model = Blog + template_name = 'blog/blogCreate.html' + fields = ['title', 'content'] + + def form_valid(self, form): + form.instance.author = self.request.user + return super().form_valid(form) + + + +class PostDetailView(DetailView): + model = Post + template_name = 'blog/postDetail.html' + + +class PostCreateView(LoginRequiredMixin, CreateView): + model = Post + template_name = 'blog/postCreate.html' + fields = ['content'] + + def form_valid(self, form): + form.instance.author = self.request.user + return super().form_valid(form) + + +def about(request): + return render(request, 'blog/about.html', {'title': 'About'}) + diff --git a/db.sqlite3 b/db.sqlite3 new file mode 100644 index 0000000..7bac968 Binary files /dev/null and b/db.sqlite3 differ diff --git a/manage.py b/manage.py new file mode 100644 index 0000000..869a0a8 --- /dev/null +++ b/manage.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'TechBlog.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/media/default.png b/media/default.png new file mode 100644 index 0000000..b895901 Binary files /dev/null and b/media/default.png differ diff --git a/media/logo.jpg b/media/logo.jpg new file mode 100644 index 0000000..9e7e52d Binary files /dev/null and b/media/logo.jpg differ diff --git a/media/profile_pics/AI_image.jpg b/media/profile_pics/AI_image.jpg new file mode 100644 index 0000000..7de2c65 Binary files /dev/null and b/media/profile_pics/AI_image.jpg differ diff --git a/media/profile_pics/default-male.png b/media/profile_pics/default-male.png new file mode 100644 index 0000000..8a2057d Binary files /dev/null and b/media/profile_pics/default-male.png differ diff --git a/server.bat b/server.bat new file mode 100644 index 0000000..0095694 --- /dev/null +++ b/server.bat @@ -0,0 +1,5 @@ +@ echo off +echo The devlopment server will start in a few seconds... +python manage.py makemigrations +python manage.py migrate +python manage.py runserver 3000 diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..e54a48c --- /dev/null +++ b/templates/base.html @@ -0,0 +1,99 @@ + + + + + + Beyond Heroes + + + + + + + + {% block content %} + + {% endblock %} + +
+
+
+ +
+
+ + + + + diff --git a/templates/base2.html b/templates/base2.html new file mode 100644 index 0000000..143ca67 --- /dev/null +++ b/templates/base2.html @@ -0,0 +1,85 @@ + + + + + + {% if title %} + WeBlog - {{ title }} + {% else %} + WeBlog - We connect your brains! + {% endif %} + + + + + + +
+ {% if messages %} + {% for message in messages %} +
+ {{ message }} +
+ {% endfor %} + {% endif %} + {% block content %} + {% endblock %} +
+ + + + + + diff --git a/templates/blog/about.html b/templates/blog/about.html new file mode 100644 index 0000000..a7e25b7 --- /dev/null +++ b/templates/blog/about.html @@ -0,0 +1,17 @@ +{% extends 'base.html' %} +{% block content %} +

About TechBlog

+
+
+
+

Why this community is built

+

The TechBlog™ community is buit for people who love to share and help other people whenever they get stuck. We have built this platform for people to help each other and make project making fun. We encourage people to get together and work in harmony for the wellbeing of all. People can make groups to work on a project or send blogs or videos that explain a topic or problem very significantly and make work much easier for other co-workers or users. Our main goal is to help everyone and enhance the art of Problem Solving through this platform.

+
+
+
+

What do we offer

+

The TechBlog™ community offers a platform for group work and online chat to all and allow our members to share text, images, videos, codes, projects and even more... with any other member.

+
+
+
+{% endblock %} \ No newline at end of file diff --git a/templates/blog/blog.html b/templates/blog/blog.html new file mode 100644 index 0000000..8c442b0 --- /dev/null +++ b/templates/blog/blog.html @@ -0,0 +1,42 @@ +{% extends 'base.html' %} +{% block content %} +

TechBlog

+

We provide a platform for people who want to help others.

+
+
+
    + {% for blog in blog %} + + + + + +
    + {{ blog.title }} +

    {{ blog.content }}

    + +
    +
    + + + + + + + + + + + + + + + + + + + + + {% endfor %} +
+{% endblock %} \ No newline at end of file diff --git a/templates/blog/blogCreate.html b/templates/blog/blogCreate.html new file mode 100644 index 0000000..3d6aab6 --- /dev/null +++ b/templates/blog/blogCreate.html @@ -0,0 +1,24 @@ +{% extends 'base.html' %} +{% block content %} +{% load crispy_forms_tags %} +
+
+ {% csrf_token %} +
+
+ Create a Blog +
+
+ {{ form | crispy }} +
+ +
+ +
+
+
+{% endblock %} diff --git a/templates/blog/blogDetail.html b/templates/blog/blogDetail.html new file mode 100644 index 0000000..e28952e --- /dev/null +++ b/templates/blog/blogDetail.html @@ -0,0 +1,12 @@ +{% extends 'base2.html' %} +{% block content %} + + {% load markdown_extras %} +
+
+

{{ object.title | markdown | safe }}

+

{{ object.content | markdown | safe }}

+ +
+
+{% endblock %} \ No newline at end of file diff --git a/templates/blog/blogList.html b/templates/blog/blogList.html new file mode 100644 index 0000000..28f6dbb --- /dev/null +++ b/templates/blog/blogList.html @@ -0,0 +1,32 @@ +{% extends 'base2.html' %} +{% block content %} + + {% load markdown_extras %} + +
+

We Blog

+

We connect your brains!

+
+
+ + +{% endblock %} diff --git a/templates/blog/home.html b/templates/blog/home.html new file mode 100644 index 0000000..2f712a1 --- /dev/null +++ b/templates/blog/home.html @@ -0,0 +1,56 @@ +{% extends 'base.html' %} +{% block content %} + +{% load markdown_extras %} + +
+
+
+ + +
+
+ Latest Posts +
+
+ {% for post in posts %} + +
+
+
{{ post.author.username }} @{{ post.author.id }}
+

{{ post.content | markdown | safe }}

+
+
+ + {% endfor %} +
+
+
+ + +
+
+
+ Trending Topics +
+
+
    + {% for topic in topics %} +
  • {{ topic }}
  • + {% endfor %} +
+
+
+
+ + {% if user.is_authenticated %} +
+ {% csrf_token %} + +
+ {% endif %} + +
+
+ +{% endblock %} \ No newline at end of file diff --git a/templates/blog/postCreate.html b/templates/blog/postCreate.html new file mode 100644 index 0000000..a735b5d --- /dev/null +++ b/templates/blog/postCreate.html @@ -0,0 +1,24 @@ +{% extends 'base.html' %} +{% block content %} +{% load crispy_forms_tags %} +
+
+ {% csrf_token %} +
+
+ Create a Post +
+
+ {{ form | crispy }} +
+ +
+ +
+
+
+{% endblock %} diff --git a/templates/blog/postDetail.html b/templates/blog/postDetail.html new file mode 100644 index 0000000..4a23eec --- /dev/null +++ b/templates/blog/postDetail.html @@ -0,0 +1,18 @@ +{% extends 'base2.html' %} +{% block content %} + + {% load markdown_extras %} +
+
+

{{ object.content | markdown | safe }}

+ +
+
+ {% for comment in object.comments %} +
+

{{ comment.content | markdown | safe }}

+ +
+
+ {% endfor %} +{% endblock %} \ No newline at end of file diff --git a/templates/favicon.ico b/templates/favicon.ico new file mode 100644 index 0000000..ad2bdf2 Binary files /dev/null and b/templates/favicon.ico differ diff --git a/templates/logo.jpg b/templates/logo.jpg new file mode 100644 index 0000000..9e7e52d Binary files /dev/null and b/templates/logo.jpg differ diff --git a/templates/users/explore.html b/templates/users/explore.html new file mode 100644 index 0000000..47aa888 --- /dev/null +++ b/templates/users/explore.html @@ -0,0 +1,18 @@ +{% extends 'base.html' %} +{% block content %} +

Explore

+

Know your potential

+
+
+
+

Why this community is built

+

The TechBlog™ community is buit for people who love to share and help other people whenever they get stuck. We have built this platform for people to help each other and make project making fun. We encourage people to get together and work in harmony for the wellbeing of all. People can make groups to work on a project or send blogs or videos that explain a topic or problem very significantly and make work much easier for other co-workers or users. Our main goal is to help everyone and enhance the art of Problem Solving through this platform.

+
+
+
+

What do we offer

+

The TechBlog™ community offers a platform for group work and online chat to all and allow our members to share text, images, videos, codes, projects and even more... with any other member.

+
+
+
+{% endblock %} \ No newline at end of file diff --git a/templates/users/login.html b/templates/users/login.html new file mode 100644 index 0000000..32f4f16 --- /dev/null +++ b/templates/users/login.html @@ -0,0 +1,24 @@ +{% extends 'base.html' %} +{% block content %} +{% load crispy_forms_tags %} +
+
+ {% csrf_token %} +
+
+ Login +
+
+ {{ form | crispy }} +
+ +
+ +
+
+
+{% endblock %} diff --git a/templates/users/logout.html b/templates/users/logout.html new file mode 100644 index 0000000..d21303a --- /dev/null +++ b/templates/users/logout.html @@ -0,0 +1,25 @@ +{% extends 'base.html' %} +{% block content %} +{% load crispy_forms_tags %} +{% if messages %} +{% for message in messages %} +
{{ message }}
+{% endfor %} +{% endif %} +
+
+
+ You have been Logged Out +
+
+ Hope you enjoyed Today! + +
+ +
+
+{% endblock %} diff --git a/templates/users/people.html b/templates/users/people.html new file mode 100644 index 0000000..fa7495c --- /dev/null +++ b/templates/users/people.html @@ -0,0 +1,25 @@ +{% extends 'base.html' %} +{% block content %} +

People

+

Know the people around you better!

+
+
    + {% for object in users %} +
  • +
    + {{ object.username }} + +

    Email: {{ object.email }}

    + +
    +
    +
  • + {% endfor %} +
+ + + + + +
+{% endblock %} \ No newline at end of file diff --git a/templates/users/profile.html b/templates/users/profile.html new file mode 100644 index 0000000..82ddf66 --- /dev/null +++ b/templates/users/profile.html @@ -0,0 +1,65 @@ + + +{% extends 'base.html' %} +{% block content %} + + {% load markdown_extras %} + +
+
+ +
+
+
+
+ Latest Posts +
+
+ {% for post in posts %} + {% if post.author == profileUser %} + +
+
+
{{ post.author.username }} @{{ post.author.id }}
+

{{ post.content | markdown | safe }}

+ +
+
+ + {% endif %} + {% endfor %} +
+
+
+
+ + +
+
+
+
+ Profile Image +
+
+

{{ profileUser.username }}

+

@{{ profileUser.id }}

+

Date Joined: Jan 1, 2022

+ {% if profileUser == user %} + Edit Profile + {% endif %} +
+
+
+
+ + {% if user.is_authenticated %} +
+ {% csrf_token %} + +
+ {% endif %} + +
+
+ +{% endblock %} diff --git a/templates/users/register.html b/templates/users/register.html new file mode 100644 index 0000000..f79c17e --- /dev/null +++ b/templates/users/register.html @@ -0,0 +1,24 @@ +{% extends 'base.html' %} +{% block content %} +{% load crispy_forms_tags %} +
+
+ {% csrf_token %} +
+
+ Create an Account +
+
+ {{ form | crispy }} +
+ +
+ +
+
+
+{% endblock %} \ No newline at end of file diff --git a/users/__init__.py b/users/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/users/__pycache__/__init__.cpython-310.pyc b/users/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..a2cf04f Binary files /dev/null and b/users/__pycache__/__init__.cpython-310.pyc differ diff --git a/users/__pycache__/__init__.cpython-37.pyc b/users/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..a5073fe Binary files /dev/null and b/users/__pycache__/__init__.cpython-37.pyc differ diff --git a/users/__pycache__/__init__.cpython-38.pyc b/users/__pycache__/__init__.cpython-38.pyc new file mode 100644 index 0000000..89e0c1a Binary files /dev/null and b/users/__pycache__/__init__.cpython-38.pyc differ diff --git a/users/__pycache__/admin.cpython-310.pyc b/users/__pycache__/admin.cpython-310.pyc new file mode 100644 index 0000000..4177616 Binary files /dev/null and b/users/__pycache__/admin.cpython-310.pyc differ diff --git a/users/__pycache__/admin.cpython-37.pyc b/users/__pycache__/admin.cpython-37.pyc new file mode 100644 index 0000000..e7461c7 Binary files /dev/null and b/users/__pycache__/admin.cpython-37.pyc differ diff --git a/users/__pycache__/admin.cpython-38.pyc b/users/__pycache__/admin.cpython-38.pyc new file mode 100644 index 0000000..1ed0856 Binary files /dev/null and b/users/__pycache__/admin.cpython-38.pyc differ diff --git a/users/__pycache__/apps.cpython-310.pyc b/users/__pycache__/apps.cpython-310.pyc new file mode 100644 index 0000000..9066c9a Binary files /dev/null and b/users/__pycache__/apps.cpython-310.pyc differ diff --git a/users/__pycache__/apps.cpython-37.pyc b/users/__pycache__/apps.cpython-37.pyc new file mode 100644 index 0000000..efa1fa3 Binary files /dev/null and b/users/__pycache__/apps.cpython-37.pyc differ diff --git a/users/__pycache__/apps.cpython-38.pyc b/users/__pycache__/apps.cpython-38.pyc new file mode 100644 index 0000000..9c0b2a1 Binary files /dev/null and b/users/__pycache__/apps.cpython-38.pyc differ diff --git a/users/__pycache__/forms.cpython-310.pyc b/users/__pycache__/forms.cpython-310.pyc new file mode 100644 index 0000000..871274a Binary files /dev/null and b/users/__pycache__/forms.cpython-310.pyc differ diff --git a/users/__pycache__/forms.cpython-37.pyc b/users/__pycache__/forms.cpython-37.pyc new file mode 100644 index 0000000..d4135e6 Binary files /dev/null and b/users/__pycache__/forms.cpython-37.pyc differ diff --git a/users/__pycache__/forms.cpython-38.pyc b/users/__pycache__/forms.cpython-38.pyc new file mode 100644 index 0000000..e180a3e Binary files /dev/null and b/users/__pycache__/forms.cpython-38.pyc differ diff --git a/users/__pycache__/models.cpython-310.pyc b/users/__pycache__/models.cpython-310.pyc new file mode 100644 index 0000000..249ea77 Binary files /dev/null and b/users/__pycache__/models.cpython-310.pyc differ diff --git a/users/__pycache__/models.cpython-37.pyc b/users/__pycache__/models.cpython-37.pyc new file mode 100644 index 0000000..253d2ce Binary files /dev/null and b/users/__pycache__/models.cpython-37.pyc differ diff --git a/users/__pycache__/models.cpython-38.pyc b/users/__pycache__/models.cpython-38.pyc new file mode 100644 index 0000000..f9f0592 Binary files /dev/null and b/users/__pycache__/models.cpython-38.pyc differ diff --git a/users/__pycache__/signals.cpython-310.pyc b/users/__pycache__/signals.cpython-310.pyc new file mode 100644 index 0000000..45687b1 Binary files /dev/null and b/users/__pycache__/signals.cpython-310.pyc differ diff --git a/users/__pycache__/signals.cpython-37.pyc b/users/__pycache__/signals.cpython-37.pyc new file mode 100644 index 0000000..7eb2b05 Binary files /dev/null and b/users/__pycache__/signals.cpython-37.pyc differ diff --git a/users/__pycache__/signals.cpython-38.pyc b/users/__pycache__/signals.cpython-38.pyc new file mode 100644 index 0000000..2b566b4 Binary files /dev/null and b/users/__pycache__/signals.cpython-38.pyc differ diff --git a/users/__pycache__/urls.cpython-310.pyc b/users/__pycache__/urls.cpython-310.pyc new file mode 100644 index 0000000..2edb560 Binary files /dev/null and b/users/__pycache__/urls.cpython-310.pyc differ diff --git a/users/__pycache__/urls.cpython-37.pyc b/users/__pycache__/urls.cpython-37.pyc new file mode 100644 index 0000000..8563347 Binary files /dev/null and b/users/__pycache__/urls.cpython-37.pyc differ diff --git a/users/__pycache__/urls.cpython-38.pyc b/users/__pycache__/urls.cpython-38.pyc new file mode 100644 index 0000000..8103cfa Binary files /dev/null and b/users/__pycache__/urls.cpython-38.pyc differ diff --git a/users/__pycache__/views.cpython-310.pyc b/users/__pycache__/views.cpython-310.pyc new file mode 100644 index 0000000..993654f Binary files /dev/null and b/users/__pycache__/views.cpython-310.pyc differ diff --git a/users/__pycache__/views.cpython-37.pyc b/users/__pycache__/views.cpython-37.pyc new file mode 100644 index 0000000..64d8ae8 Binary files /dev/null and b/users/__pycache__/views.cpython-37.pyc differ diff --git a/users/__pycache__/views.cpython-38.pyc b/users/__pycache__/views.cpython-38.pyc new file mode 100644 index 0000000..7c18f78 Binary files /dev/null and b/users/__pycache__/views.cpython-38.pyc differ diff --git a/users/admin.py b/users/admin.py new file mode 100644 index 0000000..33d2368 --- /dev/null +++ b/users/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin +from .models import Profile + + +# Register your models here. +admin.site.register(Profile) \ No newline at end of file diff --git a/users/apps.py b/users/apps.py new file mode 100644 index 0000000..0d276a3 --- /dev/null +++ b/users/apps.py @@ -0,0 +1,8 @@ +from django.apps import AppConfig + + +class UsersConfig(AppConfig): + name = 'users' + + def ready(self): + import users.signals \ No newline at end of file diff --git a/users/forms.py b/users/forms.py new file mode 100644 index 0000000..e8705bd --- /dev/null +++ b/users/forms.py @@ -0,0 +1,31 @@ +from django import forms +from django.contrib.auth.models import User +from django.contrib.auth.forms import UserCreationForm +from .models import Profile + + +class UserRegisterForm(UserCreationForm): + email = forms.EmailField() + + class Meta: + model = User + fields = ['username', 'email', 'password1', 'password2'] + + +class UserUpdateForm(forms.ModelForm): + email = forms.EmailField() + + class Meta: + model = User + fields = ['username', 'email'] + + +class ProfileUpdateForm(forms.ModelForm): + name = forms.TextInput() + about = forms.TextInput() + gender = forms.ChoiceField(choices=[('M', 'Male'), ('F', 'Female')]) + dob = forms.DateField() + + class Meta: + model = Profile + fields = ['name', 'gender', 'dob', 'about'] diff --git a/users/migrations/0001_initial.py b/users/migrations/0001_initial.py new file mode 100644 index 0000000..d448e60 --- /dev/null +++ b/users/migrations/0001_initial.py @@ -0,0 +1,28 @@ +# Generated by Django 3.1.7 on 2021-04-29 07:06 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Profile', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('biopic', models.TextField(default='Hi, I am new to TechBlog')), + ('gender', models.TextField(default='None')), + ('dob', models.DateField(default='1999-01-01')), + ('profile_pic', models.ImageField(default='default.png', upload_to='profile_pics')), + ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/users/migrations/0002_rename_biopic_profile_about_and_more.py b/users/migrations/0002_rename_biopic_profile_about_and_more.py new file mode 100644 index 0000000..dca3a9b --- /dev/null +++ b/users/migrations/0002_rename_biopic_profile_about_and_more.py @@ -0,0 +1,28 @@ +# Generated by Django 5.0.2 on 2024-03-15 10:14 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0001_initial'), + ] + + operations = [ + migrations.RenameField( + model_name='profile', + old_name='biopic', + new_name='about', + ), + migrations.RemoveField( + model_name='profile', + name='profile_pic', + ), + migrations.AddField( + model_name='profile', + name='name', + field=models.CharField(default='defname', max_length=100), + preserve_default=False, + ), + ] diff --git a/users/migrations/__init__.py b/users/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/users/migrations/__pycache__/0001_initial.cpython-310.pyc b/users/migrations/__pycache__/0001_initial.cpython-310.pyc new file mode 100644 index 0000000..cbd6648 Binary files /dev/null and b/users/migrations/__pycache__/0001_initial.cpython-310.pyc differ diff --git a/users/migrations/__pycache__/0001_initial.cpython-37.pyc b/users/migrations/__pycache__/0001_initial.cpython-37.pyc new file mode 100644 index 0000000..5fbfd09 Binary files /dev/null and b/users/migrations/__pycache__/0001_initial.cpython-37.pyc differ diff --git a/users/migrations/__pycache__/0001_initial.cpython-38.pyc b/users/migrations/__pycache__/0001_initial.cpython-38.pyc new file mode 100644 index 0000000..75446ac Binary files /dev/null and b/users/migrations/__pycache__/0001_initial.cpython-38.pyc differ diff --git a/users/migrations/__pycache__/0002_auto_20200517_1855.cpython-37.pyc b/users/migrations/__pycache__/0002_auto_20200517_1855.cpython-37.pyc new file mode 100644 index 0000000..170037b Binary files /dev/null and b/users/migrations/__pycache__/0002_auto_20200517_1855.cpython-37.pyc differ diff --git a/users/migrations/__pycache__/0002_rename_biopic_profile_about_and_more.cpython-310.pyc b/users/migrations/__pycache__/0002_rename_biopic_profile_about_and_more.cpython-310.pyc new file mode 100644 index 0000000..e1970da Binary files /dev/null and b/users/migrations/__pycache__/0002_rename_biopic_profile_about_and_more.cpython-310.pyc differ diff --git a/users/migrations/__pycache__/0003_auto_20200517_1856.cpython-37.pyc b/users/migrations/__pycache__/0003_auto_20200517_1856.cpython-37.pyc new file mode 100644 index 0000000..ac82309 Binary files /dev/null and b/users/migrations/__pycache__/0003_auto_20200517_1856.cpython-37.pyc differ diff --git a/users/migrations/__pycache__/__init__.cpython-310.pyc b/users/migrations/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..9b71671 Binary files /dev/null and b/users/migrations/__pycache__/__init__.cpython-310.pyc differ diff --git a/users/migrations/__pycache__/__init__.cpython-37.pyc b/users/migrations/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..326b7b4 Binary files /dev/null and b/users/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/users/migrations/__pycache__/__init__.cpython-38.pyc b/users/migrations/__pycache__/__init__.cpython-38.pyc new file mode 100644 index 0000000..500dee7 Binary files /dev/null and b/users/migrations/__pycache__/__init__.cpython-38.pyc differ diff --git a/users/models.py b/users/models.py new file mode 100644 index 0000000..3802880 --- /dev/null +++ b/users/models.py @@ -0,0 +1,16 @@ +from django.db import models +from django.contrib.auth.models import User + + +# Create your models here. +class Profile(models.Model): + user = models.OneToOneField(User, on_delete=models.CASCADE) + name = models.CharField(max_length=100) + about = models.TextField(default='Hi, I am new to TechBlog') + gender = models.TextField(default='None') + dob = models.DateField(default='1999-01-01') + # image = models.ImageField(default='default.png', name='profile_pic', upload_to='profile_pics') + + + def __str__(self): + return f"{self.user.username}'s Profile" diff --git a/users/signals.py b/users/signals.py new file mode 100644 index 0000000..894e1db --- /dev/null +++ b/users/signals.py @@ -0,0 +1,15 @@ +from django.db.models.signals import post_save +from django.contrib.auth.models import User +from django.dispatch import receiver +from .models import Profile + + +@receiver(post_save, sender=User) +def create_profile(sender, instance, created, **kwargs): + if created: + Profile.objects.create(user=instance) + + +@receiver(post_save, sender=User) +def save_profile(sender, instance, **kwargs): + instance.profile.save() \ No newline at end of file diff --git a/users/tests.py b/users/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/users/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/users/urls.py b/users/urls.py new file mode 100644 index 0000000..f9402a4 --- /dev/null +++ b/users/urls.py @@ -0,0 +1,14 @@ +from django.urls import path +from django.contrib.auth import views as login_view +from . import views + +urlpatterns = [ + # path('', views.users, name='Users'), + path('people/', views.UserListView.as_view(), name='People'), + path('profile/', views.profile, name='Profile'), + path('profile/', views.profile, name='NamedProfile'), + path('explore/', views.explore, name='Explore'), + path('login/', login_view.LoginView.as_view(template_name='users/login.html'), name='Login'), + path('logout/', login_view.LogoutView.as_view(template_name='users/logout.html'), name='Logout'), + path('register/', views.register, name='Register') +] diff --git a/users/views.py b/users/views.py new file mode 100644 index 0000000..6bac6ff --- /dev/null +++ b/users/views.py @@ -0,0 +1,91 @@ +from django.shortcuts import render, redirect +from django.contrib import messages +from django.contrib.auth.decorators import login_required +from .forms import UserRegisterForm +from blog.models import * +from .models import * +from django.views.generic import * + + +# Create your views here. +# def users(request): +# return render(request, 'users/users.html', {'title': 'Users'}) + +def getFromArr(arr, indices, *args, **kwargs): + x = [] + for i in indices: + x.append(arr[i]) + return x + + +@login_required +def profile(request, *args, **kwargs): + try: + user = User._default_manager.all()[kwargs['pk'] - 1] + except: + user = request.user + print(user.id) + + allow_empty = True + queryset = None + model = Post + paginate_by = None + paginate_orphans = 0 + context_object_name = 'posts' + ordering = ['-date_posted'] + + if queryset is not None: + queryset = queryset + if isinstance(queryset, QuerySet): + queryset = queryset.all() + elif model is not None: + queryset = model._default_manager.all() + else: + raise ImproperlyConfigured( + "%(cls)s is missing a QuerySet. Define " + "%(cls)s.model, %(cls)s.queryset, or override " + "%(cls)s.get_queryset()." % {"cls": self.__class__.__name__} + ) + + if ordering: + if isinstance(ordering, str): + ordering = (ordering,) + queryset = queryset.order_by(*ordering) + + return render(request, 'users/profile.html', {'title': 'Profile', 'profileUser': user, context_object_name: queryset}) + + +def people(request): + return render(request, 'users/people.html', {'title': 'People', 'users': User._default_manager.all()}) + + +users = { + 'user': User.objects.all() +} + + +class UserListView(ListView): + model = User + template_name = 'users/people.html' + context_object_name = 'users' + + +def explore(request): + return render(request, 'users/explore.html', {'title': 'Explore'}) + + +def login(request): + return render(request, 'users/login.html', {'title': 'Login'}) + + +def register(request): + if request.method == 'POST': + form = UserRegisterForm(request.POST) + if form.is_valid(): + form.save() + username = form.cleaned_data.get('username') + messages.success(request, f'{username}! Your account has been created.') + return redirect('Login') + else: + form = UserRegisterForm() + return render(request, 'users/register.html', {'title': 'Register', 'form': form})