diff --git a/.gitignore b/.gitignore index 7093270..7fef6d1 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ __pycache__/ local_settings.py db.sqlite3 -media \ No newline at end of file +media diff --git a/accounts/migrations/0001_initial.py b/accounts/migrations/0001_initial.py deleted file mode 100644 index 9a4982c..0000000 --- a/accounts/migrations/0001_initial.py +++ /dev/null @@ -1,47 +0,0 @@ -# Generated by Django 2.2.3 on 2019-08-05 01:47 - -import django.contrib.auth.models -import django.contrib.auth.validators -from django.db import migrations, models -import django.utils.timezone - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ('auth', '0011_update_proxy_permissions'), - ] - - operations = [ - migrations.CreateModel( - name='CustomUser', - fields=[ - ('id', models.AutoField(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')), - ('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')), - ('first_name', models.CharField(blank=True, max_length=30, verbose_name='first name')), - ('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')), - ('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')), - ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')), - ('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')), - ('gender', models.CharField(choices=[('M', '남성(Man)'), ('W', '여성(Woman)')], max_length=1, verbose_name='성별')), - ('birthdate', models.DateField(verbose_name='생년월일')), - ('nickname', models.CharField(max_length=15, unique=True, verbose_name='닉네임')), - ('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, - }, - managers=[ - ('objects', django.contrib.auth.models.UserManager()), - ], - ), - ] diff --git a/accounts/templates/accounts/home.html b/accounts/templates/accounts/home.html deleted file mode 100644 index 4a05f45..0000000 --- a/accounts/templates/accounts/home.html +++ /dev/null @@ -1,11 +0,0 @@ -{% if user.is_authenticated %} -환영합니다. {{ user.username }} 님!
-Update -Logout -
- {% csrf_token %} -
-{% else %} -Signup -Login -{% endif %} \ No newline at end of file diff --git a/accounts/templates/accounts/login.html b/accounts/templates/accounts/login.html index f6d98b2..8b2487c 100644 --- a/accounts/templates/accounts/login.html +++ b/accounts/templates/accounts/login.html @@ -2,34 +2,63 @@ {% block content %}
+
-
-
-
+ + -
- {% csrf_token %} -
아이디(ID):
-
비밀번호(Password):
-
-
-
-
-
- -
+
+ {% endblock %} \ No newline at end of file diff --git a/accounts/templates/accounts/signup.html b/accounts/templates/accounts/signup.html index 61a57b4..218133d 100644 --- a/accounts/templates/accounts/signup.html +++ b/accounts/templates/accounts/signup.html @@ -1,3 +1,5 @@ + + {% extends 'base.html' %} {% block content %} @@ -5,39 +7,106 @@
-
-
-
+ + -
- {% csrf_token %} -
아이디(ID):
-
비밀번호(Password):
-
비밀번호 확인(Confirm Password):
-
성별(Gender): 남성(Man) - 여성(Woman)
-
성(Last Name):
-
이름(First Name):
-
생년월일(birthdate):
-
닉네임(Nickname):
-
관리자아이디여부:
-
- -
-
-
-
- - +
diff --git a/accounts/templates/accounts/update.html b/accounts/templates/accounts/update.html index 6b5c29f..5c189af 100644 --- a/accounts/templates/accounts/update.html +++ b/accounts/templates/accounts/update.html @@ -5,44 +5,114 @@
-
-
-
+ + -
-
-
- - +
diff --git a/board/admin.py b/board/admin.py index de9ed08..a4d6f94 100644 --- a/board/admin.py +++ b/board/admin.py @@ -1,5 +1,6 @@ from django.contrib import admin -from .models import Board +from .models import Board, Comment # Register your models here. admin.site.register(Board) +admin.site.register(Comment) \ No newline at end of file diff --git a/board/migrations/0001_initial.py b/board/migrations/0001_initial.py deleted file mode 100644 index 933b7a8..0000000 --- a/board/migrations/0001_initial.py +++ /dev/null @@ -1,41 +0,0 @@ -# Generated by Django 2.2.3 on 2019-08-05 01:47 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ] - - operations = [ - migrations.CreateModel( - name='Board', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('title', models.CharField(max_length=200)), - ('date', models.DateTimeField(verbose_name='date published')), - ('category', models.CharField(max_length=20)), - ('body', models.TextField()), - ('product_price', models.PositiveIntegerField(blank=True, default=0)), - ('order_price', models.PositiveIntegerField(default=0)), - ('state', models.CharField(max_length=20)), - ('userName', models.CharField(max_length=50)), - ('image', models.ImageField(upload_to='images/')), - ], - ), - migrations.CreateModel( - name='Comment', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('author', models.CharField(max_length=200)), - ('text', models.TextField()), - ('created_date', models.DateTimeField(verbose_name='date published')), - ('approved_comment', models.BooleanField(default=False)), - ('post', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='comments', to='board.Board')), - ], - ), - ] diff --git a/board/migrations/0002_delete_comment.py b/board/migrations/0002_delete_comment.py deleted file mode 100644 index 7f02aac..0000000 --- a/board/migrations/0002_delete_comment.py +++ /dev/null @@ -1,16 +0,0 @@ -# Generated by Django 2.2.3 on 2019-08-05 12:34 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('board', '0001_initial'), - ] - - operations = [ - migrations.DeleteModel( - name='Comment', - ), - ] diff --git a/board/models.py b/board/models.py index b1e847f..9d9683c 100644 --- a/board/models.py +++ b/board/models.py @@ -5,15 +5,21 @@ class Board(models.Model) : #pk = models.AutoField() title = models.CharField(max_length=200) - date = models.DateTimeField('date published') + date = models.DateTimeField(auto_now_add=True) category = models.CharField(max_length=20) body = models.TextField() product_price = models.PositiveIntegerField(blank=True,default=0) order_price = models.PositiveIntegerField(default=0) - state = models.CharField(max_length=20) - userName = models.CharField(max_length=50) - image = models.ImageField(upload_to='images/') - + state = models.CharField(max_length=15) + userId = models.IntegerField() + userName = models.CharField(max_length=20) + image = models.ImageField(upload_to='images/', blank=True) + image1 = models.ImageField(upload_to='images/', blank=True) + image2 = models.ImageField(upload_to='images/', blank=True) + image3 = models.ImageField(upload_to='images/', blank=True) + image4 = models.ImageField(upload_to='images/', blank=True) + image5 = models.ImageField(upload_to='images/', blank=True) + def __str__(self) : return self.title #제목 @@ -23,4 +29,20 @@ def __str__(self) : #상품가격 #구입가격 #게시물 상태 - #작성자 \ No newline at end of file + #작성자 + +class Comment(models.Model): + post = models.IntegerField() + userId = models.IntegerField() + author = models.CharField(max_length=15) + text = models.TextField() + price = models.IntegerField() + created_date = models.DateTimeField(auto_now_add=True) + approved_comment = models.BooleanField(default=False) + + def approve(self): + self.approved_comment = True + self.save() + + def __str__(self): + return self.text \ No newline at end of file diff --git a/board/templates/board.html b/board/templates/board.html index d290635..7066ea1 100644 --- a/board/templates/board.html +++ b/board/templates/board.html @@ -1,53 +1,92 @@ {% extends 'base.html' %} - {% block content %} - - - -

GaSiRi Let's get it! man~

- -
- - - - - - - - - - - {% for board in posts %} - - - - - - - - {%endfor%} - -
순번글제목작성자작성일자
{{board.id}}{{board.title}}{{board.userName}}{{board.date}}
+{% block content %} + + +
+

GaSiRi

+ +
+ + + + + + + + + + + {% for board in posts %} + + + + + + + + + {%endfor%} + +
순번글제목작성자작성일자
{{board.id}}{{board.title}}{{board.userName}}{{board.date}}
-
-
- {%if posts.has_previous%} - First - Previous - {%endif%} - - {{posts.number}} - of - {{posts.paginator.num_pages}} - - {%if posts.has_next%} - Next - Last - {%endif%} +
+
+
- + {% if user.is_authenticated %} + + {% else %} + + {% endif %}
- {% endblock %} +
+ +
+{% endblock %} \ No newline at end of file diff --git a/board/templates/board_new.html b/board/templates/board_new.html index d3d0478..ba51dc7 100644 --- a/board/templates/board_new.html +++ b/board/templates/board_new.html @@ -1,58 +1,227 @@ {% extends 'base.html' %} +{% load static %} {% block content %} -
+ +
-
-
-
+ -
+ + +
+ +
diff --git a/board/templates/chart.html b/board/templates/chart.html new file mode 100644 index 0000000..aeef0bc --- /dev/null +++ b/board/templates/chart.html @@ -0,0 +1,68 @@ +{% extends 'base.html' %} + +{% block content %} + + + + + + + + + + +
+ +
+ +
+ + + + 글목록 +
+ + + + + +{% endblock %} \ No newline at end of file diff --git a/board/templates/csstest.html b/board/templates/csstest.html new file mode 100644 index 0000000..98805d1 --- /dev/null +++ b/board/templates/csstest.html @@ -0,0 +1,37 @@ + + + +{% load static %} + + + + + + + + div 태그 + + + + + + + + + + +
+ +
top
+ +
left
+ +
main
+ +
bottom
+ +
+ + + + \ No newline at end of file diff --git a/board/templates/test.html b/board/templates/test.html index 64e2531..f1bc21f 100644 --- a/board/templates/test.html +++ b/board/templates/test.html @@ -1,29 +1,75 @@ {% extends 'base.html' %} {% block content %} + -
-

{{ board.title }}

-

{{ board.date }}

+
+

{{ board.title }}

+

{{ board.date }}

-
-
-
-
-
-
-
-

{{ board.body }}

-
+
+
+
+
+
+
+
+

{{ board.body }}

-
-
+
+
+
+ +
+
+ + + + 글목록 + 차트보기 + +
+
+ +

댓글

+ + + {% csrf_token %} +
+ +

가격 :

+
+
+
+ +


- 글목록 + + +
+ {% for comments in comment.all %} +
+
+ {{ comments.author }} + {{ comments.created_date }} +
+

{{ comments.text|linebreaks }}

+

제시한 가격 : {{comments.price}}

+
+
+ {% empty %} +

No comments here yet :(

+ {% endfor %}
+
+
{% endblock %} \ No newline at end of file diff --git a/board/urls.py b/board/urls.py new file mode 100644 index 0000000..c968b63 --- /dev/null +++ b/board/urls.py @@ -0,0 +1,12 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('new/',views.board_new, name="board_new"), + path('create/',views.create, name="board_create"), + path('test/',views.test, name="test"), + path('test//create/comment',views.createcomment, name="createcomment"), + path('test/chart/', views.chart, name='chart'), + path('', views.board, name="board"), +] + diff --git a/board/views.py b/board/views.py index 9340d3a..fb6cde2 100644 --- a/board/views.py +++ b/board/views.py @@ -2,45 +2,122 @@ from django.shortcuts import render, get_object_or_404, redirect from django.utils import timezone from django.core.paginator import Paginator -from .models import Board - -# Create your views here. +from .models import Board, Comment +from accounts.models import CustomUser +import os +import random +import string +# Create your views here. +def rand_str(): + return "".join(random.choice(string.ascii_uppercase + string.digits) for _ in range(8)) def board_new(request) : - return render(request,'board_new.html') + return render(request,'board_new.html') def create(request) : - for key in request.POST: - if len(request.POST[key]) == 0: + ''' + for key in request.POST: + print("----") + print(request.POST[key]) + if len(request.POST[key]) == 0 or request.POST[key] is None : return render(request, 'board_new.html', {'error': '빈칸이 있습니다.'}) - + ''' if request.method == 'POST': boards = Board() + + if request.user.id is None : + return render(request, 'accounts/login.html', {'error': '게시물 작성을 위해 로그인해주세요.'}) + else : + boards.userId = request.user.id + boards.title = request.POST['title'] boards.order_price = request.POST['order_price'] - boards.date = timezone.datetime.now() boards.body = request.POST['body'] boards.category = request.POST['category'] boards.state = "판매중" + + count = 0 + for file in request.FILES : + if count == 0 : + fileStr = "file" + else : + fileStr = "file" + str(count) + + file = request.FILES[fileStr] + filename = rand_str()+".PNG" + print(filename) + module_dir = os.path.dirname(__file__) # get current directory + upload_path = module_dir.split('\\board') + + fp = open('%s/%s' % (upload_path[0]+"\\media\\images", filename) , 'wb') + for chunk in file.chunks(): + fp.write(chunk) + fp.close() + if count == 0 : + boards.image = 'images/'+filename # POST로 전달한 이미지로 + elif count == 1 : + boards.image1 = 'images/'+filename + elif count == 2 : + boards.image2 = 'images/'+filename + elif count == 3 : + boards.image3 = 'images/'+filename + elif count == 4 : + boards.image4 = 'images/'+filename + elif count == 5 : + boards.image5 = 'images/'+filename + + count = count + 1 + # 보완 - 로그인 상태 아닐 경우, #if(request.user.username is None) - boards.userName = request.user.username + + print(request.user.id ) + #boards.userId = request.user.id + ## 수정필요 ## - boards.image = 'images/선풍기.jpg' # POST로 전달한 이미지로 + boards.save() - return redirect('/test/' + str(boards.id)) # URL 경로 board로 + return redirect('/board/test/' + str(boards.id)) # URL 경로 board로 -def test(request, board_id) : - board_detail = get_object_or_404(Board, pk=board_id) - return render(request,'test.html',{'board' : board_detail}) +def test(request, board_id): + comment = Comment.objects.filter(post=board_id) + board_detail = get_object_or_404(Board, pk=board_id) + return render(request,'test.html',{'board' : board_detail, 'comment' : comment}) +def csstest(request) : + return render(request,'csstest.html') + def board(request): - boards = Board.objects - boards_list = Board.objects.all() - paginator = Paginator(boards_list,3) - page = request.GET.get('page') - posts = paginator.get_page(page) + boards = Board.objects + boards_list = Board.objects.all() + paginator = Paginator(boards_list,3) + if(request.GET.get('page') == None): + page=1 + else: + page = int(request.GET.get('page')) + + posts = paginator.get_page(page) + page_range = 5 #페이지 범위 지정 예 1, 2, 3, 4, 5 / 6, 7, 8, 9, 10 + current_block = math.ceil(page/page_range) #해당 페이지가 몇번째 블럭인가 + start_block = (current_block-1) * page_range + end_block = start_block + page_range + p_range = paginator.page_range[start_block:end_block] + return render(request, 'board.html',{'boards' : boards , 'posts':posts , 'p_range':p_range , 'page': page}) + +def createcomment(request, board_id): + #board = get_object_or_404(Board, pk=board_id) #게시글들에서 하나 뽑음 + + comments = Comment() + comments.userId = request.user.id + comments.author = request.user.nickname + comments.text = request.POST['text'] + comments.price = request.POST['price'] + comments.post = board_id + comments.save() + + return redirect('test', board_id) - return render(request, 'board.html',{'boards' : boards , 'posts':posts}) \ No newline at end of file +def chart(request, board_id): + return render(request, 'chart.html') \ No newline at end of file diff --git a/chart/apps.py b/chart/apps.py deleted file mode 100644 index 16aa43d..0000000 --- a/chart/apps.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.apps import AppConfig - - -class ChartConfig(AppConfig): - name = 'chart' diff --git a/chart/templates/home.html b/chart/templates/home.html deleted file mode 100644 index 26c5d96..0000000 --- a/chart/templates/home.html +++ /dev/null @@ -1 +0,0 @@ -

test

\ No newline at end of file diff --git a/chart/views.py b/chart/views.py deleted file mode 100644 index b44ed0e..0000000 --- a/chart/views.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.shortcuts import render - -# query Set 결과물을 [ list ] 로 변환한다 -def chart(request): - return render(request, 'home.html') \ No newline at end of file diff --git a/gasili/settings.py b/gasili/settings.py index 6fb4682..2bb545a 100644 --- a/gasili/settings.py +++ b/gasili/settings.py @@ -32,16 +32,18 @@ # Application definition INSTALLED_APPS = [ - 'accounts.apps.AccountsConfig', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - 'chart.apps.ChartConfig', 'home.apps.HomeConfig', - 'board.apps.BoardConfig' + 'board.apps.BoardConfig', + 'accounts.apps.AccountsConfig', + 'mypage.apps.MypageConfig', + 'service.apps.ServiceConfig', + ] MIDDLEWARE = [ @@ -133,6 +135,7 @@ STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'home', 'static') + ] diff --git a/gasili/templates/base.html b/gasili/templates/base.html index 83aaae0..2375842 100644 --- a/gasili/templates/base.html +++ b/gasili/templates/base.html @@ -1,4 +1,5 @@ +{% load static %} @@ -18,178 +19,300 @@ + + + - - - - + + + + + + - + +
{% load staticfiles %} -
+ +
+ +
+ +
-
-
- -
- - {% if user.is_authenticated %} - - {% else %} - - - {% endif %} -
+
-
-
+
+ -
-
-
+
+ {% block content %} + {% endblock %} +
+ +
- -
-
-
-{% block content %} -{% endblock %} - -
-
- {% if user.is_authenticated %} - -
-
...
-
{{ user.nickname }}
-
-
등급 : ...
-
최근 글 : ...
-
최근 댓글 : ...
-
답장 : ...
-
- -
+ + -{% else %} -{% endif %} -
-
+ + \ No newline at end of file diff --git a/gasili/templates/base.html.rej b/gasili/templates/base.html.rej deleted file mode 100644 index c75ca03..0000000 --- a/gasili/templates/base.html.rej +++ /dev/null @@ -1,9 +0,0 @@ -diff a/gasili/templates/base.html b/gasili/templates/base.html (rejected hunks) -@@ -148,6 +148,7 @@ - {% load staticfiles %} -
-
-+
-
-