-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Joel Varma
authored and
Joel Varma
committed
Aug 26, 2018
1 parent
92d5935
commit e0196b8
Showing
317 changed files
with
75,876 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
""" | ||
Django settings for django_project project. | ||
Generated by 'django-admin startproject' using Django 1.11.10. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/1.11/topics/settings/ | ||
For the full list of settings and their values, see | ||
https://docs.djangoproject.com/en/1.11/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__))) | ||
|
||
|
||
# Quick-start development settings - unsuitable for production | ||
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ | ||
|
||
# SECURITY WARNING: keep the secret key used in production secret! | ||
SECRET_KEY = '0yymcd9v+pd@)jse2af@r9hrkxv31wstwf_w63tsi+gtj53r#b' | ||
|
||
# SECURITY WARNING: don't run with debug turned on in production! | ||
DEBUG = True | ||
|
||
ALLOWED_HOSTS = [] | ||
|
||
|
||
# Application definition | ||
|
||
INSTALLED_APPS = [ | ||
'django.contrib.admin', | ||
|
||
'django.contrib.contenttypes', | ||
|
||
'django.contrib.sessions', | ||
'django.contrib.messages', | ||
'django.contrib.staticfiles', | ||
|
||
'posts', | ||
'django.contrib.auth', | ||
'django.contrib.sites', | ||
|
||
'allauth', | ||
'allauth.account', | ||
'allauth.socialaccount', | ||
'crispy_forms', | ||
|
||
] | ||
|
||
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 = 'django_project.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 = 'django_project.wsgi.application' | ||
|
||
|
||
# Database | ||
# https://docs.djangoproject.com/en/1.11/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/1.11/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/1.11/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/1.11/howto/static-files/ | ||
MEDIA_URL="/media/" | ||
|
||
STATIC_URL = '/docs/' | ||
STATIC_ROOT= os.path.join(BASE_DIR,"static","staticroot") | ||
MEDIA_ROOT= os.path.join(os.path.dirname(BASE_DIR),"media") | ||
|
||
STATICFILES_DIRS=( | ||
os.path.join(BASE_DIR,"static","ourstatic"), | ||
#'/var/www/static/', | ||
) | ||
|
||
|
||
AUTHENTICATION_BACKENDS = ( | ||
# Needed to login by username in Django admin, regardless of `allauth` | ||
'django.contrib.auth.backends.ModelBackend', | ||
|
||
# `allauth` specific authentication methods, such as login by e-mail | ||
'allauth.account.auth_backends.AuthenticationBackend', | ||
|
||
) | ||
LOGIN_REDIRECT_URL='/posts' | ||
SITE_ID=1 | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"""blog URL Configuration | ||
The `urlpatterns` list routes URLs to views. For more information please see: | ||
https://docs.djangoproject.com/en/1.9/topics/http/urls/ | ||
Examples: | ||
Function views | ||
1. Add an import: from my_app import views | ||
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') | ||
Class-based views | ||
1. Add an import: from other_app.views import Home | ||
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') | ||
Including another URLconf | ||
1. Add an import: from blog import urls as blog_urls | ||
2. Import the include() function: from django.conf.urls import url, include | ||
3. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls)) | ||
""" | ||
from django.conf.urls import url,include | ||
from django.contrib import admin | ||
from django.conf import settings | ||
from django.conf.urls.static import static | ||
|
||
|
||
urlpatterns = [ | ||
url(r'^admin/', admin.site.urls), | ||
url(r'^posts/', include("posts.urls")), | ||
url(r'^accounts/', include('allauth.urls')), | ||
|
||
] | ||
|
||
if settings.DEBUG: | ||
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) | ||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
WSGI config for jsmsite 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/1.11/howto/deployment/wsgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.wsgi import get_wsgi_application | ||
|
||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "jsmsite.settings") | ||
|
||
application = get_wsgi_application() |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
|
||
if __name__ == "__main__": | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_project.settings") | ||
try: | ||
from django.core.management import execute_from_command_line | ||
except ImportError: | ||
# The above import may fail for some other reason. Ensure that the | ||
# issue is really that Django is missing to avoid masking other | ||
# exceptions on Python 2. | ||
try: | ||
import django | ||
except ImportError: | ||
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?" | ||
) | ||
raise | ||
execute_from_command_line(sys.argv) |
Binary file not shown.
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from django.contrib import admin | ||
|
||
from .models import Post | ||
# Register your models here. | ||
|
||
|
||
|
||
class PostAdmin(admin.ModelAdmin): | ||
list_display = ['__unicode__','timestamp','updated'] | ||
search_fields = ['content','title'] | ||
class Meta: | ||
|
||
model=Post | ||
|
||
|
||
admin.site.register(Post,PostAdmin) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.apps import AppConfig | ||
|
||
|
||
class PostsConfig(AppConfig): | ||
name = 'posts' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import os | ||
|
||
from django import forms | ||
from django.core.exceptions import ValidationError | ||
|
||
|
||
from .models import Post | ||
|
||
|
||
from django.core.validators import MaxLengthValidator | ||
|
||
|
||
|
||
class PostForm(forms.ModelForm): | ||
|
||
title=forms.CharField(min_length=40) | ||
|
||
content=forms.TextInput() | ||
|
||
class Meta: | ||
model=Post | ||
fields=[ | ||
"title", | ||
|
||
"content", | ||
"fimage", | ||
] | ||
|
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.10 on 2018-02-07 04:44 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import posts.models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Post', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('title', models.CharField(max_length=1201)), | ||
('slugf', models.SlugField(unique=True)), | ||
('content', models.TextField(max_length=1230)), | ||
('fimage', models.ImageField(blank=True, null=True, upload_to=posts.models.upload_path)), | ||
('timestamp', models.DateTimeField(auto_now_add=True)), | ||
('updated', models.DateTimeField(auto_now=True)), | ||
], | ||
), | ||
] |
Binary file not shown.
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
from __future__ import unicode_literals | ||
|
||
import os | ||
from django.utils.text import slugify | ||
|
||
from django.conf.global_settings import MEDIA_ROOT | ||
from django.core.urlresolvers import reverse | ||
from django.db import models | ||
|
||
# Create your models here. | ||
from django.db.models.signals import post_save | ||
from django.dispatch import receiver | ||
|
||
from PIL import Image, ExifTags | ||
|
||
from django.db.models.signals import pre_save | ||
|
||
from jsmsite.settings import BASE_DIR | ||
|
||
|
||
def upload_path(instance,filename): | ||
print "id",instance.id | ||
return '{0}/{1}'.format("disforum", filename) | ||
|
||
class Post(models.Model): | ||
title=models.CharField(max_length=1201) | ||
slugf=models.SlugField(unique=True) | ||
|
||
content=models.TextField(max_length=1230) | ||
|
||
fimage=models.ImageField(upload_to=upload_path,null=True,blank=True) | ||
|
||
|
||
timestamp=models.DateTimeField(auto_now=False,auto_now_add=True) | ||
|
||
updated=models.DateTimeField(auto_now_add=False,auto_now=True) | ||
|
||
def __unicode__(self): | ||
return self.title | ||
|
||
def get_absolute_url(self): | ||
return reverse("postdetail",kwargs={"id": self.id}) | ||
#return "/posts/%s" %(self.id) | ||
|
||
def rotate_image(filepath): | ||
try: | ||
image = Image.open(filepath) | ||
for orientation in ExifTags.TAGS.keys(): | ||
if ExifTags.TAGS[orientation] == 'Orientation': | ||
break | ||
exif = dict(image._getexif().items()) | ||
|
||
if exif[orientation] == 3: | ||
image = image.rotate(180, expand=True) | ||
elif exif[orientation] == 6: | ||
image = image.rotate(270, expand=True) | ||
elif exif[orientation] == 8: | ||
image = image.rotate(90, expand=True) | ||
image.save(filepath) | ||
image.close() | ||
except (AttributeError, KeyError, IndexError): | ||
# cases: image don't have getexif | ||
pass | ||
|
||
@receiver(post_save, sender=Post, dispatch_uid="update_image_profile") | ||
def update_image(sender, instance, **kwargs): | ||
if instance.fimage: | ||
|
||
fullpath = os.path.join(os.path.dirname(BASE_DIR)) + instance.fimage.url | ||
rotate_image(fullpath) | ||
|
||
|
||
def pre_save_post_receiver(sender,instance,*args,**kwargs): | ||
slugf=slugify(instance.title) | ||
exists=Post.objects.filter(slugf=slugf).exists() | ||
if exists: | ||
print instance.id | ||
slugf="%s-%s"%(slugf,instance.id) | ||
|
||
instance.slugf=slugf | ||
|
||
|
||
|
||
pre_save.connect(pre_save_post_receiver,sender=Post) |
Binary file not shown.
Oops, something went wrong.