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
103 changes: 103 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
### OSX ###
.DS_Store
.AppleDouble
.LSOverride

# Icon must ends with two \r.
Icon

# Thumbnails
._*

# Files that might appear on external disk
.Spotlight-V100
.Trashes


### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
*.egg-info/
.installed.cfg
*.egg

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
.tox/
.coverage
.cache
nosetests.xml
coverage.xml
htmlcov/

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# Rope
.ropeproject

# Django stuff:
*.log
*.pot
.staticfiles/
.media/

# Sphinx documentation
docs/_build/

# npm
node_modules/

# Campass
.sass-cache

# Celery
celerybeat-schedule

# Vagrant
.vagrant

# Redis
dump.rdb

# python-dotenv
.env

# Others
_docs_html/
media/
provisioner/site.retry
*.sqlite3

# Virtualenv
venv/

### Vim ###
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
*.un~
Session.vim
.netrwhist

# Pycharm
.idea/

# Local Files
.static_media/*
.cache/*
../.vscode/
File renamed without changes.
8 changes: 0 additions & 8 deletions code_share/.gitignore

This file was deleted.

Empty file added code_share/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion code_share/api_app/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from rest_framework import serializers
from app_code_share.models import CodeShare
from code_share.app_code_share.models import CodeShare


class Codeserializer(serializers.ModelSerializer):
Expand Down
2 changes: 1 addition & 1 deletion code_share/api_app/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.shortcuts import get_object_or_404 as goo404, redirect
from rest_framework.decorators import api_view
from .serializers import Codeserializer
from app_code_share.models import CodeShare
from code_share.app_code_share.models import CodeShare
from rest_framework.response import Response
import random

Expand Down
29 changes: 29 additions & 0 deletions code_share/app_code_share/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Migrations shouldn't be here. Please add migration folders to .gitignore file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any specific reason? for adding migrations folder to .gitignore

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI

The migration files for each app live in a “migrations” directory inside of that app, and are designed to be committed to, and distributed as part of, its codebase. You should be making them once on your development machine and then running the same migrations on your colleagues’ machines, your staging machines, and eventually your production machines.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stand corrected for this. Read more here as to why one should commit migrations.

# Generated by Django 1.11.2 on 2017-09-28 09:10
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='CodeShare',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('code', models.TextField(blank=True, max_length=100000, null=True)),
('hash_value', models.SlugField(blank=True, max_length=100, null=True, unique=True)),
('file_name', models.CharField(blank=True, max_length=50, null=True)),
('language', models.CharField(blank=True, default=None, max_length=20, null=True)),
],
options={
'verbose_name': 'CodeShare',
},
),
]
Empty file.
4 changes: 2 additions & 2 deletions code_share/app_code_share/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def home(request):
"""

if request.method == 'GET':
return render(request, 'app_code_share/homepage.html', {})
return render(request, 'homepage.html', {})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to have app_code_share/<template_name> format I suppose since we are having folder structure as templates/<app_name>/<template_name>

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so technically code_share is your main app_name_folder/templates :) and the rest of the things such as wsgi etc. remains outside hence I have kept it to this. Also I have made changes in settings.settings in STATIC_DIRS part to accomodate the change I've done :)

It would be good to have all static files in one place :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your take on this one? @sourabhtk37

Copy link
Owner

@sourabhtk37 sourabhtk37 Sep 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the changes you made are good, global template file with sub folders and configuration related files in root dir and all.

What I requested to be changed is this:
'DIRS': ['code_share/templates/app_code_share', 'code_share/templates/error', ],

If we changed to having 'code_share/templates/' only, then writing in views something like return render(request, 'homepage.html', {}) would become return render(request, 'app_code_share/homepage.html', {}) which is better to find the file. Just my opinion since in case we have many sub folders it becomes quite hard for new contributors to find the file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm.. makes sense. Let me go through it. Will it push it by tonight :)


if request.method == 'POST':
code_share = request.POST.get('code_snippet')
Expand Down Expand Up @@ -68,7 +68,7 @@ def view_by_hash(request, hash_id):
except CodeShare.DoesNotExist:
raise Http404("Codeshare does not exist")
context = {'code_share': code_share}
return render(request, 'app_code_share/code_view.html', context)
return render(request, 'code_view.html', context)

if request.method == 'POST':
code_share = request.POST.get('code_snippet')
Expand Down
12 changes: 5 additions & 7 deletions code_share/code_share/urls.py → code_share/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
from .views import (
page_not_found_view,
my_custom_error_view,
permission_denied_view,
bad_request_view,
from .code_share.views import (
page_not_found_view, my_custom_error_view,
permission_denied_view, bad_request_view,
)


urlpatterns = [
url(r'^admin', admin.site.urls),
url(r'^', include('app_code_share.urls', namespace='code_share')),
url(r'^api/', include('api_app.urls')),
url(r'^', include('code_share.app_code_share.urls', namespace='code_share')),
url(r'^api/', include('code_share.api_app.urls')),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

if settings.DEBUG:
Expand Down
2 changes: 1 addition & 1 deletion code_share/manage.py → manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "code_share.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.settings")
try:
from django.core.management import execute_from_command_line
except ImportError:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added settings/__init__.py
Empty file.
35 changes: 12 additions & 23 deletions code_share/code_share/settings.py → settings/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app_code_share',
'code_share.app_code_share',
'rest_framework',
'api_app',
'code_share.api_app',
]

MIDDLEWARE = [
Expand All @@ -46,7 +46,7 @@
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['app_code_share/templates/app_code_share'],
'DIRS': ['code_share/templates/app_code_share', 'code_share/templates/error', ],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
Expand All @@ -59,7 +59,7 @@
},
]

WSGI_APPLICATION = 'code_share.wsgi.application'
WSGI_APPLICATION = 'wsgi.application'


# Database
Expand Down Expand Up @@ -129,29 +129,18 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/

STATIC_ROOT = os.path.join(BASE_DIR, 'static_media')
STATIC_ROOT = os.path.join(BASE_DIR, '.static_media')

STATIC_PATH = os.path.join(BASE_DIR, 'static')
STATIC_PATH = os.path.join(BASE_DIR, 'code_share/static')
STATICFILES_DIRS = (
STATIC_PATH,
)

STATIC_URL = '/static/'

'''
Settings for running on heroku

'''
# DATABASES['default'] = dj_database_url.config()
# print (DATABASES['default'])

# SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

# ALLOWED_HOSTS = ['*']

# DEBUG = True

# try:
# from .local_settings import *
# except ImportError:
# pass
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion code_share/uwsgi.ini → uwsgi.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[uwsgi]
chdir=/home/sourabh/projects/CodeShare/code_share
module=code_share.wsgi:application
module=wsgi:application
master=True
pidfile=/tmp/code_share-master.pid
vacuum=True
Expand Down
2 changes: 1 addition & 1 deletion code_share/code_share/wsgi.py → wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from whitenoise.django import DjangoWhiteNoise


os.environ.setdefault("DJANGO_SETTINGS_MODULE", "code_share.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.settings")

application = get_wsgi_application()

Expand Down