Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
HoYoungChun committed Feb 24, 2021
2 parents 187182f + 710d4e7 commit fd1a4d5
Show file tree
Hide file tree
Showing 105 changed files with 9,873 additions and 20 deletions.
Binary file added .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,5 @@ pip-selfcheck.json
*.code-workspace

# End of https://www.toptal.com/developers/gitignore/api/django,python,venv,vscode,pycharm+iml

.DS_STORE
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"python.formatting.provider": "yapf",
"git.ignoreLimitWarning": true
}
File renamed without changes.
2 changes: 2 additions & 0 deletions challenge/add.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def add(v1, v2):
print(v1 + v2)
19 changes: 19 additions & 0 deletions challenge/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
from django.contrib import admin
from .models import Challenge, Enrollment, EnrollmentDate
from .forms import ChallengeForm

# Register your models here.
@admin.register(Challenge)
class ChallengeAdmin(admin.ModelAdmin):
form = ChallengeForm
list_display = ['title', 'private', 'status']
list_display_links = ['title', 'private', 'status']

@admin.register(Enrollment)
class EnrollmentAdmin(admin.ModelAdmin):
list_display = ['challenge', 'player']
list_display_links = ['challenge', 'player']

@admin.register(EnrollmentDate)
class EnrollmentDateAdmin(admin.ModelAdmin):
list_display = ['enrollment', 'date']
list_display_links = ['enrollment', 'date']


18 changes: 18 additions & 0 deletions challenge/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django import forms
from .models import Challenge


class ChallengeForm(forms.ModelForm):
class Meta:
model = Challenge
fields = "__all__"

# def clean_max_pp(self):
# max_pp = self.cleaned_data.get("max_pp")
# min_pp = self.cleaned_data.get('min_pp')
# if max_pp < min_pp:
# raise forms.ValidationError("더 작음")
# return max_pp

class SearchForm(forms.Form):
search_word = forms.CharField(label = "")
53 changes: 53 additions & 0 deletions challenge/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Generated by Django 3.1.6 on 2021-02-23 06:59

import datetime
from django.db import migrations, models
import django.db.models.deletion
import hashid_field.field


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Challenge',
fields=[
('id', hashid_field.field.HashidAutoField(alphabet='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', min_length=7, primary_key=True, serialize=False)),
('title', models.CharField(max_length=100, verbose_name='제목')),
('desc', models.TextField(verbose_name='설명')),
('category', models.CharField(choices=[('language', '어학'), ('job', '취업'), ('NCS', '고시/공무원'), ('programming', '프로그래밍'), ('certificate', '자격증'), ('other', '기타')], max_length=100, verbose_name='분류')),
('private', models.IntegerField(choices=[(0, '전체 공개'), (1, '친구 공개'), (2, '나만 보기')], verbose_name='공개 상태')),
('status', models.IntegerField(blank=True, choices=[(0, '대기 중'), (1, '진행 중'), (2, '완료')], null=True, verbose_name='진행 상태')),
('min_pp', models.PositiveIntegerField(verbose_name='최소 인원')),
('max_pp', models.PositiveIntegerField(verbose_name='최대 인원')),
('cur_pp', models.IntegerField(blank=True, default=0)),
('start_date', models.DateField(default=datetime.date.today, verbose_name='시작일')),
('end_date', models.DateField(verbose_name='종료일')),
('created_date', models.DateField(auto_now_add=True, verbose_name='생성일')),
('invitation_key', models.CharField(blank=True, max_length=100, null=True)),
],
),
migrations.CreateModel(
name='Enrollment',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('result', models.BooleanField(default=False)),
('created_at', models.DateField(auto_now_add=True)),
('challenge', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='chEnrollment_set', to='challenge.challenge', verbose_name='챌린지')),
],
),
migrations.CreateModel(
name='EnrollmentDate',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date_result', models.BooleanField(default=False)),
('date', models.DateField(blank=True)),
('enrollment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='chEnrollmentDate_set', to='challenge.enrollment', verbose_name='인롤먼트')),
],
),
]
27 changes: 27 additions & 0 deletions challenge/migrations/0002_auto_20210223_1559.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 3.1.6 on 2021-02-23 06:59

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('challenge', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='enrollment',
name='player',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='chEnrollment_set', to=settings.AUTH_USER_MODEL, verbose_name='유저'),
),
migrations.AlterUniqueTogether(
name='enrollment',
unique_together={('challenge', 'player')},
),
]
133 changes: 132 additions & 1 deletion challenge/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,134 @@
from django.db import models
from django import forms
from login.models import User
import datetime
from hashid_field import HashidField, HashidAutoField

# Create your models here.
from django.core.exceptions import ValidationError

# User
# - is staff : 내부자냐 아니냐

# Challenge
# - HostUser : user_id
# - is_published : Boolean
# - link_url : /challenge/cr23ou89hnacefijlnsho
# python hash
# URLSAFE : 띄어쓰기, 덧셈이 urlsafe functionå


# def less_then_min_validator(value1, value2):
# if len(value1) < value2:
# raise forms.ValidationError("최소 인원보다 작은 수의 인원을 입력하셨습니다.")

def redirect_link(link):
challenges = Challenge.objects.filter(link=link)
if len(challenges) == 0:
return
else:
pass
return

# User <-> Challenge
# --> Enrollment
# - user_id (User)
# - challenge_id (Challenge)
# - result/success
# - day

# 이미지 저장
# 1. 파일 : Django File Upload
# 2. 외부 클라우드 스토리지 : 서버에서는 사진을 클라우드로 올리고, 클라우드 링크만 갖고있어요
# AWS S3, Microsoft, etc.


class Challenge(models.Model):
CATEGORY_LANGUAGE = 'language'
CATEGORY_JOB = 'job'
CATEGORY_NCS = 'NCS'
CATEGORY_PROGRAMMING = 'programming'
CATEGORY_CERTIFICATE = 'certificate'
CATEGORY_OTHER = 'other'

CATEGORY_OF_CHALLENGE = (
(CATEGORY_LANGUAGE, '어학'),
(CATEGORY_JOB, '취업'),
(CATEGORY_NCS, '고시/공무원'),
(CATEGORY_PROGRAMMING, '프로그래밍'),
(CATEGORY_CERTIFICATE, '자격증'),
(CATEGORY_OTHER, '기타')
)

PRIVATE_OF_CHALLENGE = (
(0, '전체 공개'),
(1, '친구 공개'),
(2, '나만 보기'),
)

STATUS_OF_CHALLENGE = (
(0, '대기 중'),
(1, '진행 중'),
(2, '완료'),
)

id = HashidAutoField(primary_key=True)
title = models.CharField(max_length=100, verbose_name="제목")
desc = models.TextField(verbose_name="설명")
category = models.CharField(
max_length=100, choices=CATEGORY_OF_CHALLENGE, verbose_name="분류")
private = models.IntegerField(
choices=PRIVATE_OF_CHALLENGE, verbose_name="공개 상태")
status = models.IntegerField(
choices=STATUS_OF_CHALLENGE, blank=True, null=True, verbose_name="진행 상태")
min_pp = models.PositiveIntegerField(verbose_name="최소 인원")
max_pp = models.PositiveIntegerField(verbose_name="최대 인원")
cur_pp = models.IntegerField(default=0, blank=True)
start_date = models.DateField(verbose_name="시작일", default=datetime.date.today)
end_date = models.DateField(verbose_name="종료일")
created_date = models.DateField(auto_now_add=True, verbose_name="생성일")
invitation_key = models.CharField(max_length=100, blank=True, null=True)

def __str__(self):
return self.title

#TODO 챌린지 바꾸기
#def clean(self, *args, **kwargs):
# error_list = []
# if self.min_pp > self.max_pp:
# error_list.append("최대 인원이 최소 인원보다 작을 수 없습니다.")
# if self.start_date > self.end_date:
# error_list.append("종료일이 시작일보다 빠를 수 없습니다.")
if self.min_pp == 0:
error_list.append("최소 인원은 0이 될 수 없습니다.")
if self.start_date < datetime.date.today():
error_list.append(f"시작일은 {datetime.date.today()} (오늘) 이전이 될 수 없습니다.")


if len(error_list) > 0:
raise ValidationError(error_list)

# return super(User, self).clean(*args, **kwargs)


class Enrollment(models.Model):
# player_total = 0
challenge = models.ForeignKey(
Challenge, on_delete=models.CASCADE, verbose_name="챌린지", related_name="chEnrollment_set")
player = models.ForeignKey(
User, on_delete=models.CASCADE, verbose_name="유저", related_name="chEnrollment_set")
result = models.BooleanField(default=False)
created_at = models.DateField(auto_now_add=True)

class Meta:
unique_together = ('challenge', 'player',)

def __str__(self):
return '{1} : {0}'.format(self.challenge.title, self.player.nickname)

class EnrollmentDate(models.Model):
enrollment = models.ForeignKey(Enrollment, on_delete=models.CASCADE, verbose_name="인롤먼트", related_name="chEnrollmentDate_set")
date_result = models.BooleanField(default=False)
date = models.DateField(blank=True) #12시 1분쯤 생성된 시간이 들어감

def __str__(self):
return str(self.enrollment.challenge.title) +' '+str(self.enrollment.player.username) + ' date: '+ str(self.date)
Loading

0 comments on commit fd1a4d5

Please sign in to comment.