diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..29206cd --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,11 @@ +# Contributing Guidelines +Welcome to contributing in **Open Source Programs**! + +- You can join us on [AnitaB.org Open Source Zulip](https://anitab-org.zulipchat.com/). Each active repo has its own stream. OSP stream is [#open-source-progs](https://anitab-org.zulipchat.com/#narrow/stream/237907-open-source-progs). +- To ensure a safe, positive environment for all contributors, go through the full [Code of Conduct](https://github.com/anitab-org/open-source-programs-backend/blob/develop/CODE_OF_CONDUCT.md) +- Make your **Commit Message** descriptive including all the changes or additions you have made. +- Please consider raising an issue before submitting a **Pull Request (PR)** to solve a problem, if not present in the [issues list](https://github.com/anitab-org/open-source-programs-backend/issues). +- When submitting a PR, make your PR as descriptive as possible, follow the template, add screenshots and relevant information. +- When you are finished with your work, please squash your commits otherwise we will squash them on your PR. This will help maintain a clean commit history. +- For in-code documentation, follow [this guide](https://github.com/google/styleguide/blob/gh-pages/pyguide.md#38-comments-and-docstrings). +- The full guidelines for python can be found [here](https://github.com/google/styleguide/blob/gh-pages/pyguide.md). \ No newline at end of file diff --git a/.gitignore b/.gitignore index b6e4761..f347387 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,5 @@ dmypy.json # Pyre type checker .pyre/ + +.vscode/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..6871eaa --- /dev/null +++ b/README.md @@ -0,0 +1,55 @@ +# Open Source Programs (Backend) +Open Source Programs (OSP) is an application that simplifies the processing and selection procedure of Open Source Programs of AnitaB.org Open Source or other third-party programs. This is the Backend repo for OSP. + +## Tech Stack +- Django +- Django REST Framework + +## Setup +To setup the project locally go through [this wiki page](https://github.com/anitab-org/open-source-programs-web/wiki/Fork,-Clone,-Remote-and-Pull-Request). +Make sure you have installed the following: +* [pip](https://pip.pypa.io/en/stable/installing/) +* [virtualenv](https://pypi.org/project/virtualenv/) +* [PostgreSQL](https://www.postgresql.org/docs/9.5/install-procedure.html) + +Next follow these instructions. + +1. **Database Setup:** Before starting with the project create a db in you local using PostgreSQL with the following details. Refer to `main/settings.py` if you have any confusion. + + ``` + NAME: osp + USER: osp + PASSWORD: osp + HOST: localhost + ``` + You may run the following commands for local setup of DB: + + ``` + sudo -i -u postgres + createuser osp --pwprompt + psql + CREATE DATABASE osp; + \c osp; + GRANT ON PRIVILEGES ON DATABASE systersdb to osp; + ``` + + +2. To start the server: + + ``` + cd open-source-programs-backend + virtualenv venv + source venv/bin/activate + pip install -r requirements.txt + python manage.py runserver + ``` +3. Navigate to `http://localhost:8000/` in your browser. +4. To change the port you may run `python manage.py runserver 0.0.0.0:` +5. To run the migrations run: `python manage.py migrate` +6. You can terminate the process by `Ctrl+C` in your terminal. + +## Contributing +Please read the Contibuting guidelines, [Code of Conduct](https://github.com/anitab-org/open-source-programs-backend/blob/develop/CODE_OF_CONDUCT.md) and [Reporting Guidelines](https://github.com/anitab-org/open-source-programs-backend/blob/develop/REPORTING_GUIDELINES.md) + +## Contact +You can reach the admins, maintainers and our community on [AnitaB.org Open Source Zulip](https://anitab-org.zulipchat.com/). If you are interested in contributing to the OSP project, you may join the stream [#open-source-progs](https://anitab-org.zulipchat.com/#narrow/stream/237907-open-source-progs) and ask questions or intereact with the community. Join Us! \ No newline at end of file diff --git a/main/__init__.py b/main/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/main/asgi.py b/main/asgi.py new file mode 100644 index 0000000..fabf75e --- /dev/null +++ b/main/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for main 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', 'main.settings') + +application = get_asgi_application() diff --git a/main/settings.py b/main/settings.py new file mode 100644 index 0000000..4999861 --- /dev/null +++ b/main/settings.py @@ -0,0 +1,149 @@ +""" +Django settings for main project. + +Generated by 'django-admin startproject' using Django 3.0.5. + +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 +from datetime import timedelta + +# 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/3.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '7ibm!g0j@gs7kszwav!6$*lar(+!!l3tpm@09s%csl2bj)l+p4' + +# 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', + 'rest_framework', + 'corsheaders', + # 'osp', + # 'token_auth' +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'corsheaders.middleware.CorsMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'main.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + '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', + ], + }, + }, +] + +REST_FRAMEWORK = { + "DEFAULT_PERMISSION_CLASSES": ["rest_framework.permissions.IsAuthenticated",], + "DEFAULT_PARSER_CLASSES": ["rest_framework.parsers.JSONParser", ], + "DEFAULT_AUTHENTICATION_CLASSES": ( + "rest_framework.authentication.SessionAuthentication", + "rest_framework_simplejwt.authentication.JWTAuthentication", + ), +} + +SIMPLE_JWT = { + 'ACCESS_TOKEN_LIFETIME': timedelta(days=2), + 'REFRESH_TOKEN_LIFETIME': timedelta(days=30), +} + +CORS_ORIGIN_WHITELIST = [ + 'http://127.0.0.1:3000', + 'http://localhost:3000', +] + +WSGI_APPLICATION = 'main.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/3.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': "osp", + 'USER': "osp", + 'PASSWORD': "osp", + 'HOST': "localhost", + 'PORT': 5432, + } +} + + +# 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/' diff --git a/main/urls.py b/main/urls.py new file mode 100644 index 0000000..d87bfdd --- /dev/null +++ b/main/urls.py @@ -0,0 +1,23 @@ +"""main 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.contrib import admin +from django.urls import path, include + +urlpatterns = [ + path('admin/', admin.site.urls), + # path('api/', include('osp.urls')), + path('auth/', include('rest_framework.urls')) +] diff --git a/main/wsgi.py b/main/wsgi.py new file mode 100644 index 0000000..6512615 --- /dev/null +++ b/main/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for main 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', 'main.settings') + +application = get_wsgi_application() diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..063eacc --- /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', 'main.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/requirements.txt b/requirements.txt new file mode 100644 index 0000000..14be4a4 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,10 @@ +asgiref==3.2.7 +Django==3.0.6 +django-cors-headers==3.3.0 +djangorestframework==3.11.0 +djangorestframework-jwt==1.11.0 +djangorestframework-simplejwt==4.4.0 +psycopg2==2.8.5 +PyJWT==1.7.1 +pytz==2020.1 +sqlparse==0.3.1