Skip to content

Commit

Permalink
merge develop (#104)
Browse files Browse the repository at this point in the history
* 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
4 people authored Dec 5, 2023
1 parent db86ed8 commit 0936049
Show file tree
Hide file tree
Showing 78 changed files with 1,181 additions and 19 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/api-build.yml
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"
8 changes: 8 additions & 0 deletions Dockerfile
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 . .
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

<div align="center">

# 🛒 GETIT
Expand Down Expand Up @@ -32,6 +33,9 @@ TO BE UPDATED

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

## Frontend


### [![My Skills](https://skills.thijs.gg/icons?i=nodejs)](https://skills.thijs.gg)PREREQUISITS

The following software is required to be installed on your system:
Expand Down Expand Up @@ -88,6 +92,22 @@ $ npm run generate
```
For detailed explanation on how things work, check out the [documentation](https://nuxtjs.org).

## Backend
- **Framework** - [Django](https://www.djangoproject.com/)
- **Language** - Python 3.10
## Local Setup
Make sure you are using `python 3.10`.

- Change your working directory to `core`
- Create a new file in the same directory named: `.env` and copy all the content from `.env.template`
- Add a random string for `DJANGO_SECRET` or generate it online.
- Create a virtual environment: `$ python -m virtualenv .venv`
- Activate the virtual environment: `$ source .venv/bin/activate` (On windows: `> ./.venv/Scripts/activate`)
- Install the dependencies: `$ pip install -r requirements.txt`
- Make Migrations: `$ python manage.py makemigrations` (This commands generates migrations which would be used to update database schemas)
- Migrate the DB: `$ python manage.py migrate`
- Run server: `$ python manage.py runserver`

## Special Directories

You can create the following extra directories, some of which have special behaviors. Only `pages` is required; you can delete them if you don't want to use their functionality.
Expand Down Expand Up @@ -148,3 +168,4 @@ More information about the usage of this directory in [the documentation](https:

The [Contributing.md](https://github.com/bsoc-bitbyte/GetIt/blob/main/CONTRIBUTING.md) contains the step-by-step procedure for contributing for this project.


1 change: 1 addition & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
venv
1 change: 1 addition & 0 deletions backend/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DJANGO_SECRET=
14 changes: 14 additions & 0 deletions .gitignore → backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules
.nuxt
# Created by .ignore support plugin (hsz.mobi)
### Node template
# Logs
Expand Down Expand Up @@ -88,3 +90,15 @@ sw.*

# Vim swap files
*.swp

**/migrations
**/__pycache__
.pytest_cache
.DS_Store
.vscode/*
.idea
db.sqlite3
.venv
venv
.env
.vscode
Empty file added backend/accounts/__init__.py
Empty file.
48 changes: 48 additions & 0 deletions backend/accounts/admin.py
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)
6 changes: 6 additions & 0 deletions backend/accounts/apps.py
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'
68 changes: 68 additions & 0 deletions backend/accounts/models.py
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
33 changes: 33 additions & 0 deletions backend/accounts/serializers.py
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
Loading

0 comments on commit 0936049

Please sign in to comment.