-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] created users, team members fetch api and frontend utils
- Loading branch information
1 parent
36c844f
commit dd4fa70
Showing
22 changed files
with
602 additions
and
3 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
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,18 @@ | ||
from oauth2_provider.models import Application | ||
from rest_framework.exceptions import ParseError | ||
import utils.errors as em | ||
from rest_framework.views import APIView | ||
|
||
class ApplicationBaseView(APIView): | ||
def initial(self, request, *args, **kwargs): | ||
super().initial(request, *args, **kwargs) | ||
data = request.data | ||
client_id = data.get('client_id', None) | ||
client_secret = data.get('client_secret', None) | ||
if not client_secret or not client_secret: | ||
raise ParseError(em.EMPTY_FIELD('Client ID or Client secret')) | ||
try: | ||
app = Application.objects.get(client_id=client_id, client_secret=client_secret) | ||
except: | ||
raise ParseError(em.INVALID_FIELD_PARAMETER('Client ID or Client secret')) | ||
request.app = app |
Empty file.
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,5 @@ | ||
from django.contrib import admin | ||
from .models import Team_Member | ||
|
||
admin.site.register(Team_Member) | ||
# Register your models here. |
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 UserConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "user" |
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,34 @@ | ||
from django.contrib.auth.base_user import BaseUserManager | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
|
||
class UserManager(BaseUserManager): | ||
""" | ||
Custom user model manager where email is the unique identifiers | ||
for authentication instead of usernames. | ||
""" | ||
def create_user(self, email, password, **extra_fields): | ||
""" | ||
Create and save a user with the given email and password. | ||
""" | ||
if not email: | ||
raise ValueError(_("The Email must be set")) | ||
email = self.normalize_email(email) | ||
user = self.model(email=email, **extra_fields) | ||
user.set_password(password) | ||
user.save() | ||
return user | ||
|
||
def create_superuser(self, email, password, **extra_fields): | ||
""" | ||
Create and save a SuperUser with the given email and password. | ||
""" | ||
extra_fields.setdefault("is_staff", True) | ||
extra_fields.setdefault("is_superuser", True) | ||
extra_fields.setdefault("is_active", True) | ||
|
||
if extra_fields.get("is_staff") is not True: | ||
raise ValueError(_("Superuser must have is_staff=True.")) | ||
if extra_fields.get("is_superuser") is not True: | ||
raise ValueError(_("Superuser must have is_superuser=True.")) | ||
return self.create_user(email, password, **extra_fields) |
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,185 @@ | ||
# Generated by Django 4.2.4 on 2023-08-08 11:51 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import django.utils.timezone | ||
|
||
|
||
class Migration(migrations.Migration): | ||
initial = True | ||
|
||
dependencies = [ | ||
("auth", "0012_alter_user_first_name_max_length"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
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" | ||
), | ||
), | ||
( | ||
"is_superuser", | ||
models.BooleanField( | ||
default=False, | ||
help_text="Designates that this user has all permissions without explicitly assigning them.", | ||
verbose_name="superuser status", | ||
), | ||
), | ||
( | ||
"first_name", | ||
models.CharField( | ||
blank=True, max_length=150, verbose_name="first name" | ||
), | ||
), | ||
( | ||
"last_name", | ||
models.CharField( | ||
blank=True, max_length=150, verbose_name="last name" | ||
), | ||
), | ||
( | ||
"is_active", | ||
models.BooleanField( | ||
default=True, | ||
help_text="Designates whether this user should be treated as active. Unselect this instead of deleting accounts.", | ||
verbose_name="active", | ||
), | ||
), | ||
( | ||
"date_joined", | ||
models.DateTimeField( | ||
default=django.utils.timezone.now, verbose_name="date joined" | ||
), | ||
), | ||
( | ||
"email", | ||
models.EmailField( | ||
max_length=254, unique=True, verbose_name="email address" | ||
), | ||
), | ||
("is_staff", models.BooleanField(default=False)), | ||
("blocked", models.BooleanField(default=False)), | ||
( | ||
"groups", | ||
models.ManyToManyField( | ||
blank=True, | ||
help_text="The groups this user belongs to. A user will get all permissions granted to each of their groups.", | ||
related_name="user_set", | ||
related_query_name="user", | ||
to="auth.group", | ||
verbose_name="groups", | ||
), | ||
), | ||
( | ||
"user_permissions", | ||
models.ManyToManyField( | ||
blank=True, | ||
help_text="Specific permissions for this user.", | ||
related_name="user_set", | ||
related_query_name="user", | ||
to="auth.permission", | ||
verbose_name="user permissions", | ||
), | ||
), | ||
], | ||
options={ | ||
"verbose_name": "user", | ||
"verbose_name_plural": "users", | ||
"abstract": False, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name="Team_Member", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("created_at", models.DateTimeField(auto_now_add=True)), | ||
("updated_at", models.DateTimeField(auto_now=True)), | ||
("json_field", models.JSONField(blank=True, default=dict, null=True)), | ||
("first_name", models.CharField(max_length=50)), | ||
("last_name", models.CharField(max_length=50)), | ||
("phone_number", models.CharField(max_length=20)), | ||
( | ||
"profile_pic", | ||
models.ImageField(blank=True, upload_to="profile_pics/"), | ||
), | ||
("github", models.URLField(blank=True, null=True)), | ||
("linkdin", models.URLField(blank=True, null=True)), | ||
("additional_url", models.URLField(blank=True, null=True)), | ||
( | ||
"user", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="team", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
], | ||
options={ | ||
"verbose_name": "Team Member", | ||
"verbose_name_plural": "Team Members", | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name="Alum", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("created_at", models.DateTimeField(auto_now_add=True)), | ||
("updated_at", models.DateTimeField(auto_now=True)), | ||
("json_field", models.JSONField(blank=True, default=dict, null=True)), | ||
("first_name", models.CharField(max_length=50)), | ||
("last_name", models.CharField(max_length=50)), | ||
("phone_number", models.CharField(max_length=20)), | ||
( | ||
"profile_pic", | ||
models.ImageField(blank=True, upload_to="profile_pics/"), | ||
), | ||
("linkdin", models.URLField(blank=True, null=True)), | ||
("facebook_url", models.URLField(blank=True, null=True)), | ||
("additional_url", models.URLField(blank=True, null=True)), | ||
( | ||
"user", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="alum", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
], | ||
options={ | ||
"verbose_name": "Alum", | ||
"verbose_name_plural": "Alums", | ||
}, | ||
), | ||
] |
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,61 @@ | ||
from django.contrib.auth.models import AbstractUser | ||
from django.db import models | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from utils.mixins import JsonModel, TimestampedModel | ||
from utils.path import get_profile_pics_path | ||
|
||
from .managers import UserManager | ||
|
||
|
||
class User(AbstractUser): | ||
username = None | ||
email = models.EmailField(_("email address"), unique=True) | ||
is_staff = models.BooleanField(default=False) | ||
blocked = models.BooleanField(default=False) | ||
USERNAME_FIELD = "email" | ||
REQUIRED_FIELDS = [] | ||
objects = UserManager() | ||
|
||
def __str__(self): | ||
return self.email | ||
|
||
|
||
class Team_Member(JsonModel, TimestampedModel): | ||
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="team") | ||
first_name = models.CharField(max_length=50) | ||
last_name = models.CharField(max_length=50) | ||
phone_number = models.CharField(max_length=20) | ||
profile_pic = models.ImageField(upload_to=get_profile_pics_path(), blank=True) | ||
github = models.URLField(null=True,blank=True) | ||
linkdin = models.URLField(null=True,blank=True) | ||
additional_url = models.URLField(null=True,blank=True) | ||
|
||
class Meta: | ||
verbose_name = "Team Member" | ||
verbose_name_plural = "Team Members" | ||
|
||
|
||
|
||
def __str__(self): | ||
return f"{self.first_name} {self.last_name} {self.user.email}" | ||
|
||
|
||
|
||
|
||
|
||
class Alum(JsonModel, TimestampedModel): | ||
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="alum") | ||
first_name = models.CharField(max_length=50) | ||
last_name = models.CharField(max_length=50) | ||
phone_number = models.CharField(max_length=20) | ||
profile_pic = models.ImageField(upload_to=get_profile_pics_path(), blank=True) | ||
linkdin = models.URLField(null=True,blank=True) | ||
facebook_url = models.URLField(null=True,blank=True) | ||
additional_url = models.URLField(null=True,blank=True) | ||
def __str__(self): | ||
return f"{self.first_name} {self.last_name} {self.user.email}" | ||
class Meta: | ||
verbose_name = "Alum" | ||
verbose_name_plural = "Alums" | ||
|
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,15 @@ | ||
from rest_framework import serializers | ||
|
||
from .models import Alum, Team_Member | ||
|
||
class TeamMemberSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Team_Member | ||
fields = "__all__" | ||
|
||
class AlumSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Alum | ||
fields = "__all__" | ||
|
||
|
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,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
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.urls import path | ||
from .views import TeamMemberView | ||
|
||
urlpatterns = [ | ||
path('team/', TeamMemberView.as_view()), | ||
] |
Oops, something went wrong.