-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore(global): change file structure to accommodate for backend (#34) * feat(core): backend setup (#38) * fix: move dot files to frontend * feat(core): backend setup * fix(docs): update readme for backend * fix(backend): move .env.template and add requirements.txt * fix: remove duplicate .env.template * build : Added build.py to setup the backend and incorporated a global .gitignore (#41) * added global gitignore and build script for run and setup * Using venv through shell * updated build.py * build : updated build.py * feat(backend): add lint and build workflow and rename core (#44) * feat(backend): add lint and build workflow and rename core * change file structure * fix(backend): minor fixes * feat(backend): setup authentication (#46) * feat(backend) : added account models (#50) * updated requirements * created account app * updated setting.py * updated url to incorporate routes * accounts directory changed * duplicacy of core removed * Removed username field * removed routers * fix(backend): linting account and build file (#79) * fix(backend): fix account and build file * fix linting * remove json_api package * fix(backend): add address field to account model * feat(backend): add endpoints for accounts (#82) * feat(backend): add endpoints for account * fix linting and build errors * fix linting and build errors * feat (backend) : Added Product Models (#87) * Merge branch develop into Priyansh61/product-model * Done requested changes * Feat : docker initialised : backend (#101) * docker initialised: backend * changes * changes * Feat : Added Event Model (#102) Signed-off-by: Priyansh61 <[email protected]> * Feat : Added Ticket and Event_Form (#103) * Added Evnet Model Signed-off-by: Priyansh61 <[email protected]> * Added Tickets App Signed-off-by: Priyansh61 <[email protected]> * Added Event Form Model Signed-off-by: Priyansh61 <[email protected]> * minor fixes * Update models.py --------- Signed-off-by: Priyansh61 <[email protected]> Co-authored-by: Armin Patel <[email protected]> * Added Tickets App Signed-off-by: Priyansh61 <[email protected]> * Added Event Form Model Signed-off-by: Priyansh61 <[email protected]> * chore(global): change file structure to accommodate for backend (#34) * feat(core): backend setup (#38) * fix: move dot files to frontend * feat(core): backend setup * fix(docs): update readme for backend * fix(backend): move .env.template and add requirements.txt * fix: remove duplicate .env.template * build : Added build.py to setup the backend and incorporated a global .gitignore (#41) * added global gitignore and build script for run and setup * Using venv through shell * updated build.py * build : updated build.py * feat(backend): add lint and build workflow and rename core (#44) * feat(backend): add lint and build workflow and rename core * change file structure * fix(backend): minor fixes * feat(backend): setup authentication (#46) * feat(backend) : added account models (#50) * updated requirements * created account app * updated setting.py * updated url to incorporate routes * accounts directory changed * duplicacy of core removed * Removed username field * removed routers * fix(backend): fix account and build file * move dockerfile inside backend * minor file movements * minor fixes * move docker files to root --------- Signed-off-by: Priyansh61 <[email protected]> Co-authored-by: Priyansh Mehta <[email protected]> Co-authored-by: Priyansh61 <[email protected]> Co-authored-by: Raman Chaudhary <[email protected]>
- Loading branch information
1 parent
db86ed8
commit 0936049
Showing
78 changed files
with
1,181 additions
and
19 deletions.
There are no files selected for viewing
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,58 @@ | ||
name: API Tests | ||
|
||
on: | ||
push: | ||
branches: [ develop, main ] | ||
paths: | ||
- backend/** | ||
- .github/workflows/api-build.yml | ||
pull_request: | ||
branches: [ develop, main ] | ||
paths: | ||
- backend/** | ||
- .github/workflows/api-build.yml | ||
|
||
env: | ||
DJANGO_SECRET: random-key | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
working-directory: backend | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
max-parallel: 4 | ||
matrix: | ||
python-version: ["3.10"] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install Dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- name: Run Tests | ||
run: | | ||
pytest --cache-clear | ||
flake8-lint: | ||
runs-on: ubuntu-latest | ||
name: Lint | ||
steps: | ||
- name: Check out source repository | ||
uses: actions/checkout@v3 | ||
- name: Set up Python environment | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.10" | ||
- name: flake8 Lint | ||
uses: py-actions/flake8@v2 | ||
with: | ||
max-line-length: "100" | ||
path: "backend" |
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 @@ | ||
FROM python:3.10-alpine | ||
WORKDIR /usr/src/app | ||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
ENV PYTHONUNBUFFERED 1 | ||
RUN pip install --upgrade pip | ||
COPY requirements.txt . | ||
RUN pip install -r requirements.txt | ||
COPY . . |
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
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 @@ | ||
venv |
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 @@ | ||
DJANGO_SECRET= |
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
Empty file.
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,48 @@ | ||
from django.contrib import admin | ||
from django import forms | ||
from django.contrib.auth.admin import UserAdmin | ||
from .models import Account | ||
|
||
|
||
class AccountAddForm(forms.ModelForm): | ||
class Meta: | ||
model = Account | ||
fields = ('email', | ||
'first_name', | ||
'last_name', | ||
'password', | ||
'is_active', | ||
'is_staff') | ||
|
||
|
||
class AccountAdmin(UserAdmin): | ||
add_form = AccountAddForm | ||
list_display = ('email', | ||
'first_name', | ||
'last_name', | ||
'last_login', | ||
'date_joined', | ||
'is_active', | ||
'is_staff') | ||
add_fieldsets = ( | ||
(None, { | ||
'classes': ('wide',), | ||
'fields': ('email', | ||
'first_name', | ||
'last_name', | ||
'password', | ||
'is_active', | ||
'is_staff') | ||
}), | ||
) | ||
|
||
list_display_links = ('email', 'first_name', 'last_name') | ||
readonly_fields = ('last_login', 'date_joined') | ||
ordering = ('-date_joined',) | ||
|
||
filter_horizontal = () | ||
list_filter = () | ||
fieldsets = () | ||
|
||
|
||
admin.site.register(Account, AccountAdmin) |
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,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class AccountsConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'accounts' |
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,68 @@ | ||
from django.db import models | ||
from django.core.validators import RegexValidator | ||
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager | ||
|
||
class MyAccountManager(BaseUserManager): | ||
def create_user(self, first_name, last_name, email, password=None): | ||
if not email: | ||
raise ValueError("Users must have an email address") | ||
|
||
user = self.model( | ||
email=self.normalize_email(email), | ||
first_name=first_name, | ||
last_name=last_name | ||
) | ||
|
||
user.set_password(password) | ||
user.save(using=self._db) | ||
|
||
return user | ||
|
||
def create_superuser(self, first_name, last_name, email, password): | ||
user = self.create_user( | ||
email=self.normalize_email(email), | ||
first_name=first_name, | ||
last_name=last_name, | ||
password=password | ||
) | ||
|
||
user.is_admin = True | ||
user.is_active = True | ||
user.is_staff = True | ||
user.is_superadmin = True | ||
|
||
user.save(using=self._db) | ||
|
||
return user | ||
|
||
|
||
class Account(AbstractBaseUser): | ||
phone_regex = RegexValidator(regex=r'^(\+91)?\d{10}$', message="Invalid phone number") | ||
|
||
first_name = models.CharField(max_length=50) | ||
last_name = models.CharField(max_length=50) | ||
email = models.EmailField(unique=True) | ||
phone_number = models.CharField(max_length=13, validators=[phone_regex], blank=True) | ||
address = models.CharField(max_length=128, blank=True) | ||
|
||
# required | ||
date_joined = models.DateTimeField(auto_now_add=True) | ||
last_login = models.DateTimeField(auto_now=True) | ||
is_admin = models.BooleanField(default=False) | ||
is_staff = models.BooleanField(default=False) | ||
is_superadmin = models.BooleanField(default=False) | ||
is_active = models.BooleanField(default=True) | ||
|
||
USERNAME_FIELD = 'email' | ||
REQUIRED_FIELDS = ['first_name', 'last_name'] | ||
|
||
objects = MyAccountManager() | ||
|
||
def __str__(self): | ||
return str(self.email) | ||
|
||
def has_perm(self, perm, obj=None): | ||
return self.is_admin | ||
|
||
def has_module_perms(self, add_label): | ||
return True |
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,33 @@ | ||
from rest_framework import serializers | ||
from .models import Account | ||
|
||
|
||
class AccountSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Account | ||
fields = ['id', | ||
'first_name', | ||
'last_name', | ||
'email', | ||
'password', | ||
'address', | ||
'phone_number', | ||
'date_joined', | ||
'last_login'] | ||
extra_kwargs = { | ||
'password': {'write_only': True}, | ||
'date_joined': {'read_only': True}, | ||
'last_login': {'read_only': True}, | ||
} | ||
|
||
def create(self, validated_data): | ||
password = validated_data.pop('password', None) | ||
|
||
if not password: | ||
raise serializers.ValidationError('Password is required') | ||
|
||
account = self.Meta.model(**validated_data) | ||
account.set_password(password) | ||
account.save() | ||
|
||
return account |
Oops, something went wrong.