Skip to content

Commit

Permalink
Merge pull request #29 from MannuVilasara/Workflow
Browse files Browse the repository at this point in the history
Add CI/CD workflow to check code Formatting
  • Loading branch information
neerajbelsare authored Oct 3, 2023
2 parents 77e0558 + 761d849 commit 4c285cb
Show file tree
Hide file tree
Showing 15 changed files with 402 additions and 221 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
on: [push, pull_request]

jobs:
python-black:
name: Python Black
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Python Black
uses: cytopia/[email protected]
with:
path: 'backend/'
69 changes: 55 additions & 14 deletions backend/accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,67 @@ class UserModelAdmin(BaseUserAdmin):
# The fields to be used in displaying the User model.
# These override the definitions on the base UserModelAdmin
# that reference specific fields on auth.User.
list_display = ('id', 'email', 'first_name', 'last_name', 'age', 'gender', 'address', 'preferred_lang', 'company',
'job_title', 'industry', 'experience', 'is_admin')
list_filter = ('is_admin',)
list_display = (
"id",
"email",
"first_name",
"last_name",
"age",
"gender",
"address",
"preferred_lang",
"company",
"job_title",
"industry",
"experience",
"is_admin",
)
list_filter = ("is_admin",)
fieldsets = (
('User Credentials', {'fields': ('email', 'password')}),
('Personal info', {'fields': ('first_name', 'last_name', 'age', 'gender', 'address', 'preferred_lang')}),
('Work info', {'fields': ('company', 'job_title', 'industry', 'experience')}),
('Permissions', {'fields': ('is_admin',)}),
("User Credentials", {"fields": ("email", "password")}),
(
"Personal info",
{
"fields": (
"first_name",
"last_name",
"age",
"gender",
"address",
"preferred_lang",
)
},
),
("Work info", {"fields": ("company", "job_title", "industry", "experience")}),
("Permissions", {"fields": ("is_admin",)}),
)
# add_fieldsets is not a standard ModelAdmin attribute. UserModelAdmin
# overrides get_fieldsets to use this attribute when creating a user.
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': ('email', 'first_name', 'last_name', 'age', 'gender', 'address', 'preferred_lang', 'company',
'job_title', 'industry', 'experience', 'password1', 'password2'),
}),
(
None,
{
"classes": ("wide",),
"fields": (
"email",
"first_name",
"last_name",
"age",
"gender",
"address",
"preferred_lang",
"company",
"job_title",
"industry",
"experience",
"password1",
"password2",
),
},
),
)
search_fields = ('email',)
ordering = ('email', 'id')
search_fields = ("email",)
ordering = ("email", "id")
filter_horizontal = ()


Expand Down
4 changes: 2 additions & 2 deletions backend/accounts/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class AccountsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'accounts'
default_auto_field = "django.db.models.BigAutoField"
name = "accounts"
62 changes: 39 additions & 23 deletions backend/accounts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,53 @@


class Migration(migrations.Migration):

initial = True

dependencies = [
]
dependencies = []

operations = [
migrations.CreateModel(
name='User',
name="User",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('email', models.EmailField(max_length=255, unique=True, verbose_name='Email')),
('first_name', models.CharField(max_length=200)),
('last_name', models.CharField(max_length=200)),
('age', models.PositiveIntegerField()),
('gender', models.CharField(max_length=200)),
('address', models.CharField(max_length=600)),
('preferred_lang', models.CharField(max_length=200)),
('company', models.CharField(max_length=200)),
('job_title', models.CharField(max_length=200)),
('industry', models.CharField(max_length=400)),
('experience', models.IntegerField()),
('is_active', models.BooleanField(default=True)),
('is_admin', models.BooleanField(default=False)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("password", models.CharField(max_length=128, verbose_name="password")),
(
"last_login",
models.DateTimeField(
blank=True, null=True, verbose_name="last login"
),
),
(
"email",
models.EmailField(
max_length=255, unique=True, verbose_name="Email"
),
),
("first_name", models.CharField(max_length=200)),
("last_name", models.CharField(max_length=200)),
("age", models.PositiveIntegerField()),
("gender", models.CharField(max_length=200)),
("address", models.CharField(max_length=600)),
("preferred_lang", models.CharField(max_length=200)),
("company", models.CharField(max_length=200)),
("job_title", models.CharField(max_length=200)),
("industry", models.CharField(max_length=400)),
("experience", models.IntegerField()),
("is_active", models.BooleanField(default=True)),
("is_admin", models.BooleanField(default=False)),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
],
options={
'abstract': False,
"abstract": False,
},
),
]
69 changes: 53 additions & 16 deletions backend/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,27 @@

# Custom User Manager
class UserManager(BaseUserManager):
def create_user(self, email, first_name, last_name, age, gender, address, preferred_lang, company, job_title,
industry, experience, password=None, password2=None):
def create_user(
self,
email,
first_name,
last_name,
age,
gender,
address,
preferred_lang,
company,
job_title,
industry,
experience,
password=None,
password2=None,
):
"""
Creates and saves a User with the given email, name, tc and password.
"""
Creates and saves a User with the given email, name, tc and password.
"""
if not email:
raise ValueError('User must have an email address')
raise ValueError("User must have an email address")

user = self.model(
email=self.normalize_email(email),
Expand All @@ -23,18 +37,31 @@ def create_user(self, email, first_name, last_name, age, gender, address, prefer
company=company,
job_title=job_title,
industry=industry,
experience=experience
experience=experience,
)

user.set_password(password)
user.save(using=self._db)
return user

def create_superuser(self, email, first_name, last_name, age, gender, address, preferred_lang, company, job_title,
industry, experience, password=None):
def create_superuser(
self,
email,
first_name,
last_name,
age,
gender,
address,
preferred_lang,
company,
job_title,
industry,
experience,
password=None,
):
"""
Creates and saves a superuser with the given email, name, tc and password.
"""
Creates and saves a superuser with the given email, name, tc and password.
"""
user = self.create_user(
email,
password=password,
Expand All @@ -47,7 +74,7 @@ def create_superuser(self, email, first_name, last_name, age, gender, address, p
company=company,
job_title=job_title,
industry=industry,
experience=experience
experience=experience,
)
user.is_admin = True
user.save(using=self._db)
Expand All @@ -57,7 +84,7 @@ def create_superuser(self, email, first_name, last_name, age, gender, address, p
# Custom User Model
class User(AbstractBaseUser):
email = models.EmailField(
verbose_name='Email',
verbose_name="Email",
max_length=255,
unique=True,
)
Expand All @@ -78,9 +105,19 @@ class User(AbstractBaseUser):

objects = UserManager()

USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['first_name', 'last_name', 'age', 'gender', 'address', 'preferred_lang', 'company',
'job_title', 'industry', 'experience']
USERNAME_FIELD = "email"
REQUIRED_FIELDS = [
"first_name",
"last_name",
"age",
"gender",
"address",
"preferred_lang",
"company",
"job_title",
"industry",
"experience",
]

def __str__(self):
return self.email
Expand All @@ -99,4 +136,4 @@ def has_module_perms(self, app_label):
def is_staff(self):
"""Is the user a member of staff?"""
# Simplest possible answer: All admins are staff
return self.is_admin
return self.is_admin
8 changes: 4 additions & 4 deletions backend/accounts/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@


class UserRenderer(renderers.JSONRenderer):
charset = 'utf-8'
charset = "utf-8"

def render(self, data, accepted_media_type=None, renderer_context=None):
response = ''
if 'ErrorDetail' in str(data):
response = json.dumps({'errors': data})
response = ""
if "ErrorDetail" in str(data):
response = json.dumps({"errors": data})
else:
response = json.dumps(data)

Expand Down
Loading

0 comments on commit 4c285cb

Please sign in to comment.