Skip to content

Commit

Permalink
updated the head and the proffesoor and solved the ugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Fareed95 committed Nov 17, 2024
1 parent 142be45 commit ab47a32
Show file tree
Hide file tree
Showing 19 changed files with 114 additions and 9 deletions.
5 changes: 4 additions & 1 deletion server/events/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ def upload_image_to_drive(sender, instance, created, **kwargs):
# Only upload if the drive_file_id is not already set or if it's a new image
if not instance.drive_file_id:
file_path = instance.image.path
drive_file_id = upload_to_drive(file_path, instance.id) # Upload function, assumes it returns file ID
event_name = instance.gallery.name # Corresponding event's name
event_id = instance.id # Corresponding event's ID
file_name = f"{event_name}_{event_id}"
drive_file_id = upload_to_drive(file_path, file_name) # Upload function, assumes it returns file ID

# Update the model with the Google Drive file ID
instance.drive_file_id = drive_file_id
Expand Down
Binary file added server/media/galleries/CybSec_3_UOf2FwR.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/media/galleries/CybSec_3_d3Ka3nI.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/media/galleries/CybSec_4_EUAMbrz.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/media/galleries/CybSec_4_xtjTHpx.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/media/galleries/CybSec_5_ehoCBmM.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/media/galleries/CybSec_5_iS2vyfq.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/media/teams/Codeathon_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/media/teams/Codeathon_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/media/teams/CybSec_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/media/teams/CybSec_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/media/teams/CybSec_3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion server/teams/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.contrib import admin
from .models import TechTeam, ManagementTeam, MarketingTeam
from .models import TechTeam, ManagementTeam, MarketingTeam, Head , Professors

admin.site.register(TechTeam)
admin.site.register(ManagementTeam)
admin.site.register(MarketingTeam)
admin.site.register(Head)
admin.site.register(Professors)
43 changes: 43 additions & 0 deletions server/teams/migrations/0005_head_professors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Generated by Django 4.2.6 on 2024-11-17 09:05

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('teams', '0004_managementteam_drive_file_id_and_more'),
]

operations = [
migrations.CreateModel(
name='Head',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('profile_image', models.ImageField(blank=True, default='/default_profile_image.jpg', null=True, upload_to='teams/')),
('drive_file_id', models.CharField(blank=True, max_length=255, null=True)),
('about', models.CharField(blank=True, default='Team Member', max_length=250)),
('is_head', models.BooleanField(default=False)),
('is_core', models.BooleanField(default=False)),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='Professors',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('profile_image', models.ImageField(blank=True, default='/default_profile_image.jpg', null=True, upload_to='teams/')),
('drive_file_id', models.CharField(blank=True, max_length=255, null=True)),
('about', models.CharField(blank=True, default='Team Member', max_length=250)),
('is_head', models.BooleanField(default=False)),
('is_core', models.BooleanField(default=False)),
],
options={
'abstract': False,
},
),
]
11 changes: 11 additions & 0 deletions server/teams/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,14 @@ def __str__(self):
class MarketingTeam(Teams):
def __str__(self):
return self.name


class Head(Teams):
def __str__(self):
return self.name


class Professors(Teams):
def __str__(self):
return self.name

16 changes: 13 additions & 3 deletions server/teams/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# serializers.py
from rest_framework import serializers
from .models import TechTeam, ManagementTeam, MarketingTeam
from .models import TechTeam, ManagementTeam, MarketingTeam , Head, Professors

class TechTeamSerializer(serializers.ModelSerializer):
class Meta:
Expand All @@ -10,9 +10,19 @@ class Meta:
class ManagementTeamSerializer(serializers.ModelSerializer):
class Meta:
model = ManagementTeam
fields = ['id', 'name', 'profile_image', 'about', 'is_head', 'is_core']
fields = ['id', 'name', 'drive_file_id', 'about', 'is_head', 'is_core']

class MarketingTeamSerializer(serializers.ModelSerializer):
class Meta:
model = MarketingTeam
fields = ['id', 'name', 'profile_image', 'about', 'is_head', 'is_core']
fields = ['id', 'name', 'drive_file_id', 'about', 'is_head', 'is_core']

class HeadSerializer(serializers.ModelSerializer):
class Meta:
model = Head
fields = ['id', 'name', 'drive_file_id', 'about']

class ProfessorsSerializer(serializers.ModelSerializer):
class Meta:
model = Professors
fields = ['id', 'name', 'drive_file_id', 'about']
4 changes: 3 additions & 1 deletion server/teams/signals.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from django.db.models.signals import post_save
from django.dispatch import receiver
from .models import TechTeam, ManagementTeam, MarketingTeam
from .models import TechTeam, ManagementTeam, MarketingTeam,Head, Professors
from server.google_drive import upload_to_drive # Assuming you have this function to upload files

@receiver(post_save, sender=TechTeam)
@receiver(post_save, sender=ManagementTeam)
@receiver(post_save, sender=MarketingTeam)
@receiver(post_save, sender=Head)
@receiver(post_save, sender=Professors)
def upload_image_to_drive(sender, instance, created, **kwargs):
"""
Signal to automatically upload the profile image to Google Drive when a TechTeam, ManagementTeam, or MarketingTeam instance is created or updated.
Expand Down
3 changes: 2 additions & 1 deletion server/teams/urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from django.urls import path
from .views import TeamMemberListView
from .views import TeamMemberListView, ProffesorHeadListView
from django.conf import settings
from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

urlpatterns = [
path('team/<str:team_type>/<str:role_type>/', TeamMemberListView.as_view(), name='team-member-list'),
path('team/<str:proffession_type>/',ProffesorHeadListView.as_view(), name='proffession-type-list'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

urlpatterns += staticfiles_urlpatterns()
37 changes: 35 additions & 2 deletions server/teams/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework import status
from .models import TechTeam, ManagementTeam, MarketingTeam
from .serializers import TechTeamSerializer, ManagementTeamSerializer, MarketingTeamSerializer
from .models import TechTeam, ManagementTeam, MarketingTeam , Head, Professors
from .serializers import TechTeamSerializer, ManagementTeamSerializer, MarketingTeamSerializer , HeadSerializer , ProfessorsSerializer
from django.http import HttpResponse
from server.google_drive import download_from_drive

Expand Down Expand Up @@ -51,3 +51,36 @@ def get(self, request, team_type, role_type):
member['drive_file_id'] = None # Fallback if no image

return Response(serializer.data, status=status.HTTP_200_OK)



class ProffesorHeadListView(APIView):
def get(self, request, proffession_type):
# Map team_type to models and serializers
model_serializer_map = {
'head': (Head, HeadSerializer),
'professors': (Professors, ProfessorsSerializer),
}
model, serializer_class = model_serializer_map.get(proffession_type, (None, None))

if not model or not serializer_class:
return Response(
{"error": "it is not head or not proffesors"},
status=status.HTTP_400_BAD_REQUEST
)

# Get queryset based on filter criteria
queryset = model.objects.all()

# Serialize data
serializer = serializer_class(queryset, many=True)

# Update profile_image field with the endpoint URL
for member in serializer.data:
profile_image_id = member.get('drive_file_id') # Assuming this field exists
if profile_image_id:
member['drive_file_id'] = f'/api/images/{profile_image_id}'
else:
member['drive_file_id'] = None # Fallback if no image

return Response(serializer.data, status=status.HTTP_200_OK)

0 comments on commit ab47a32

Please sign in to comment.