Skip to content

Commit

Permalink
style: code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ljy2855 committed Feb 6, 2024
1 parent 8e67661 commit 2ba002c
Show file tree
Hide file tree
Showing 16 changed files with 294 additions and 167 deletions.
106 changes: 74 additions & 32 deletions app/apply/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,33 @@
from django.shortcuts import get_object_or_404



@admin.action(description='csv 파일 다운로드')
@admin.action(description="csv 파일 다운로드")
def get_all_resume(self, request, queryset):
meta = self.model._meta
field_names = ['name', 'applicant', 'phone', 'semester', 'introduce', 'motivate', 'to_do', 'etc', 'fixed_interview_time']
excel_row = ['이름', '학번', '전화번호','학기', '자기소개', '지원동기', '하고 싶은 것' , '기타', '면접 일자']
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename={}.csv'.format(
meta)
field_names = [
"name",
"applicant",
"phone",
"semester",
"introduce",
"motivate",
"to_do",
"etc",
"fixed_interview_time",
]
excel_row = [
"이름",
"학번",
"전화번호",
"학기",
"자기소개",
"지원동기",
"하고 싶은 것",
"기타",
"면접 일자",
]
response = HttpResponse(content_type="text/csv")
response["Content-Disposition"] = "attachment; filename={}.csv".format(meta)
writer = csv.writer(response)

writer.writerow(excel_row)
Expand All @@ -26,85 +44,109 @@ def get_all_resume(self, request, queryset):

return response

@admin.action(description='면접 시간 자동 배치')
def set_interview_time(self, request, queryset): #self = resume model , queryset = 체크했던 object들

@admin.action(description="면접 시간 자동 배치")
def set_interview_time(
self, request, queryset
): # self = resume model , queryset = 체크했던 object들
times = [queryset.time for queryset in InterviewTime.objects.all()]
meta = self.model._meta

q = Resume.objects.annotate(c=Count('interview_time_choice')).order_by('c')
q = Resume.objects.annotate(c=Count("interview_time_choice")).order_by("c")

for i in q:
for j in i.interview_time_choice.all():
if j.time in times :
if j.time in times:
time_num = 0
s = Resume.objects.annotate()
for _resume in s: #resume에 대해 call하는 부분 문제 어떤방식으로 call해야하나?
if j.time==_resume.fixed_interview_time: time_num = time_num + 1
if time_num==1:
for (
_resume
) in s: # resume에 대해 call하는 부분 문제 어떤방식으로 call해야하나?
if j.time == _resume.fixed_interview_time:
time_num = time_num + 1
if time_num == 1:
plus20 = j.time + datetime.timedelta(minutes=20)
a = Resume.objects.annotate()
for Res in a:
if plus20 == Res.fixed_interview_time: time_num = time_num + 1
if time_num == 2: #2개 있을 때
if plus20 == Res.fixed_interview_time:
time_num = time_num + 1
if time_num == 2: # 2개 있을 때
i.fixed_interview_time = plus20 + datetime.timedelta(minutes=20)
i.save()
j.is_fixed = True
j.save()
times.remove(j.time)
break
else: #1개 있을

else: # 1개 있을
i.fixed_interview_time = plus20
i.save()
break
else: # 0개일때

else: # 0개일때
i.fixed_interview_time = j.time
i.save()
break


@admin.action(description="면접 장소 일괄 지정")
def set_interview_place(self,request,queryset):
def set_interview_place(self, request, queryset):
place = get_object_or_404(InterviewPlace)
for query in queryset:
query.interview_place = place
query.save()


@admin.action(description="일괄 서류 불합격")
def set_doc_fail(self,request,queryset):
def set_doc_fail(self, request, queryset):
for _resume in queryset:
_resume.is_pass_document = False
_resume.save()


@admin.action(description="일괄 서류 합격")
def set_doc_pass(self,request,queryset):
def set_doc_pass(self, request, queryset):
for _resume in queryset:
_resume.is_pass_document = True
_resume.save()


@admin.action(description="일괄 최종 합격")
def set_final_pass(self,request,queryset):
def set_final_pass(self, request, queryset):
for _resume in queryset:
_resume.is_pass_final = True
_resume.save()


@admin.action(description="일괄 최종 불합격")
def set_final_fail(self,request,queryset):
def set_final_fail(self, request, queryset):
for _resume in queryset:
_resume.is_pass_final = False
_resume.save()


@admin.register(Resume)
class ResumeAdmin(admin.ModelAdmin):
list_display = ('name', 'semester',
'phone', 'fixed_interview_time','interview_place')
search_fields = ['name','applicant__student_id','introduce','motivate']
actions=[get_all_resume,set_interview_time,set_interview_place,set_doc_fail,set_doc_pass,set_final_pass,set_final_fail]

list_display = (
"name",
"semester",
"phone",
"fixed_interview_time",
"interview_place",
)
search_fields = ["name", "applicant__student_id", "introduce", "motivate"]
actions = [
get_all_resume,
set_interview_time,
set_interview_place,
set_doc_fail,
set_doc_pass,
set_final_pass,
set_final_fail,
]

def get_ordering(self, request):
return ['fixed_interview_time']

return ["fixed_interview_time"]


admin.site.register(InterviewPlace)
Expand Down
61 changes: 36 additions & 25 deletions app/apply/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
from django.utils import timezone
from user.models import Applicant


class TermType(models.TextChoices):
SPRING = 'spring'
FALL = 'fall'
SPRING = "spring"
FALL = "fall"


class RecruitProcess(models.TextChoices):
CLOSE = 'close'
APPLY = 'apply'
MIDDLE = 'middle'
FINAL = 'final'
CLOSE = "close"
APPLY = "apply"
MIDDLE = "middle"
FINAL = "final"


class Recruitment(models.Model):
year = models.PositiveSmallIntegerField()
Expand All @@ -21,54 +24,62 @@ class Recruitment(models.Model):
interview_start_time = models.DateField()
interview_end_time = models.DateField()
announce_final_time = models.DateTimeField()
process = models.CharField(max_length=10, choices=RecruitProcess.choices ,default=RecruitProcess.CLOSE)
process = models.CharField(
max_length=10, choices=RecruitProcess.choices, default=RecruitProcess.CLOSE
)

def check_process(self):
now = timezone.now()
if now >= self.announce_final_time :
if now >= self.announce_final_time:
self.process = RecruitProcess.FINAL
elif now >= self.announce_middle_time :
elif now >= self.announce_middle_time:
self.process = RecruitProcess.MIDDLE
elif now.date() >= self.start_time :
elif now.date() >= self.start_time:
self.process = RecruitProcess.APPLY
else :
else:
self.process = RecruitProcess.CLOSE
self.save()



class InterviewTime(models.Model):
time = models.DateTimeField()
is_fixed = models.BooleanField(default=False)

def __str__(self):
return self.time.strftime("%Y/%m/%d %H:%M:%S")



class InterviewPlace(models.Model):
place = models.CharField(max_length=20)

def __str__(self):
return self.place


class Resume(models.Model):
applicant = models.OneToOneField(Applicant,on_delete=models.CASCADE)
applicant = models.OneToOneField(Applicant, on_delete=models.CASCADE)
phone = models.CharField(max_length=20)
name = models.CharField(max_length=20)
semester = models.PositiveSmallIntegerField()
#지원서 답변
introduce = models.TextField(default='')
motivate = models.TextField(default='')
to_do = models.TextField(default='')
etc = models.TextField(default='')

interview_time_choice = models.ManyToManyField(InterviewTime,related_name="interview_time")
fixed_interview_time = models.DateTimeField(null=True,blank=True)
interview_requirement = models.TextField(default='')
interview_place = models.ForeignKey(InterviewPlace,on_delete=models.CASCADE,null=True,blank=True)
# 지원서 답변
introduce = models.TextField(default="")
motivate = models.TextField(default="")
to_do = models.TextField(default="")
etc = models.TextField(default="")

interview_time_choice = models.ManyToManyField(
InterviewTime, related_name="interview_time"
)
fixed_interview_time = models.DateTimeField(null=True, blank=True)
interview_requirement = models.TextField(default="")
interview_place = models.ForeignKey(
InterviewPlace, on_delete=models.CASCADE, null=True, blank=True
)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

is_pass_document = models.BooleanField(default=True)
is_pass_final = models.BooleanField(default=False)


def __str__(self):
return self.name
Expand Down
52 changes: 41 additions & 11 deletions app/apply/serializers.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
from rest_framework import serializers
from apply.models import *
from user.serializers import *


class RecruitSerializer(serializers.ModelSerializer):
class Meta:
model = Recruitment
fields = '__all__'
fields = "__all__"


class InterviewtimeSerializer(serializers.ModelSerializer):
class Meta:
model = InterviewTime
fields = '__all__'
fields = "__all__"


class ResumeSerializer(serializers.ModelSerializer):

class Meta:
model = Resume
fields = ['interview_time_choice', 'name', 'semester', 'phone',
'introduce', 'motivate', 'to_do', 'etc', 'applicant', 'updated_at']
fields = [
"interview_time_choice",
"name",
"semester",
"phone",
"introduce",
"motivate",
"to_do",
"etc",
"applicant",
"updated_at",
]

def __init__(self, *args, **kwargs):
# Don't pass the 'fields' arg up to the superclass
fields = kwargs.pop('interview_requirement', None)
fields = kwargs.pop("interview_requirement", None)

# Instantiate the superclass normally
super().__init__(*args, **kwargs)
Expand All @@ -33,6 +45,7 @@ def __init__(self, *args, **kwargs):
existing = set(self.fields)
for field_name in existing - allowed:
self.fields.pop(field_name)

# def update(self, instance, validated_data):
# nested_serializer = self.fields['interview_time_choice']
# nested_instance = instance.interview_time_choice
Expand All @@ -42,7 +55,7 @@ def __init__(self, *args, **kwargs):
# # this will not throw an exception,
# # as `profile` is not part of `validated_data`
# return super(ResumeSerializer, self).update(instance, validated_data)

# def create(self, validated_data):
# times = validated_data.pop('interview_time_choice')
# print(times)
Expand All @@ -54,15 +67,32 @@ def __init__(self, *args, **kwargs):
# resume.save()
# return resume


class ResumeRequestSerializer(serializers.ModelSerializer):
class Meta:
model = Resume
fields = ['interview_time_choice', 'name', 'semester', 'phone',
'introduce', 'motivate', 'to_do', 'etc', 'interview_requirement']
fields = [
"interview_time_choice",
"name",
"semester",
"phone",
"introduce",
"motivate",
"to_do",
"etc",
"interview_requirement",
]


class ResultSerializer(serializers.ModelSerializer):
interview_place = serializers.CharField(source='interview_place.place')
interview_place = serializers.CharField(source="interview_place.place")

class Meta:
model = Resume
fields = ['name','fixed_interview_time','interview_place','is_pass_document','is_pass_final']
fields = [
"name",
"fixed_interview_time",
"interview_place",
"is_pass_document",
"is_pass_final",
]
8 changes: 4 additions & 4 deletions app/apply/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from apply.views import *

urlpatterns = [
path('recruit/', get_recuit_session, name='get_recuit_session'),
path('resume/', ResumeAPI.as_view(), name='resume_api'),
path('interview/', get_interview_time_list, name='get_interview_time_list'),
path('result/', get_result, name='get_result'),
path("recruit/", get_recuit_session, name="get_recuit_session"),
path("resume/", ResumeAPI.as_view(), name="resume_api"),
path("interview/", get_interview_time_list, name="get_interview_time_list"),
path("result/", get_result, name="get_result"),
]
Loading

0 comments on commit 2ba002c

Please sign in to comment.