Skip to content

Commit

Permalink
新增响应式瀑布流
Browse files Browse the repository at this point in the history
  • Loading branch information
xishandong committed Jul 27, 2023
1 parent 000e4cc commit b38e34e
Show file tree
Hide file tree
Showing 46 changed files with 46 additions and 18 deletions.
Binary file modified Server01/__pycache__/models.cpython-39.pyc
Binary file not shown.
23 changes: 23 additions & 0 deletions Server01/migrations/0012_image_height_image_width.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.1 on 2023-07-27 05:39

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("Server01", "0011_remove_user_followed"),
]

operations = [
migrations.AddField(
model_name="image",
name="height",
field=models.IntegerField(default=0, verbose_name="图片高度"),
),
migrations.AddField(
model_name="image",
name="width",
field=models.IntegerField(default=0, verbose_name="图片宽度"),
),
]
Binary file not shown.
2 changes: 2 additions & 0 deletions Server01/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def delete(self, *args, **kwargs):
class Image(models.Model):
post = models.ForeignKey(Post, on_delete=models.CASCADE, related_name='imgs')
imagePath = models.CharField(max_length=256, verbose_name='帖子图片')
height = models.IntegerField(default=0, verbose_name='图片高度')
width = models.IntegerField(default=0, verbose_name='图片宽度')


class Comment(models.Model):
Expand Down
Binary file added Server01/static/img/avatar/11-iu6.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added Server01/static/img/post/102-img2.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 Server01/static/img/post/102-img3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added Server01/static/img/post/103-iu1.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 Server01/static/img/post/103-iu2.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 Server01/static/img/post/103-iu3.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 Server01/static/img/post/104-iu6.jpeg
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 Server01/static/img/post/105-iu4.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 Server01/static/img/post/105-iu5.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 Server01/static/img/post/106-user.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 Server01/static/img/post/107-loading.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 removed Server01/static/img/post/52-05.png
Binary file not shown.
Binary file removed Server01/static/img/post/53-06.jpg
Binary file not shown.
Binary file removed Server01/static/img/post/54-html_table.jpg
Binary file not shown.
Binary file removed Server01/static/img/post/55-search.png
Binary file not shown.
Binary file removed Server01/static/img/post/56-ikun.jpg
Binary file not shown.
Binary file removed Server01/static/img/post/59-池秀媛.jpg
Binary file not shown.
Binary file removed Server01/static/img/post/62-桥本环奈.jpg
Diff not rendered.
Binary file removed Server01/static/img/post/63-张娜英.jpg
Diff not rendered.
Binary file removed Server01/static/img/post/65-project.png
Diff not rendered.
File renamed without changes
File renamed without changes
File renamed without changes
Binary file modified Server01/util/__pycache__/auxiliaryFuction.cpython-39.pyc
Binary file not shown.
Binary file modified Server01/util/__pycache__/verifyJWT.cpython-39.pyc
Binary file not shown.
4 changes: 4 additions & 0 deletions Server01/util/auxiliaryFuction.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def combine_index_post(posts):
'title': post.title,
'id': post.id,
'img': imgs[0].imagePath,
'img_info': {
'height': imgs[0].height,
'width': imgs[0].width,
},
'user': {
'id': post.user.id,
'username': post.user.username,
Expand Down
5 changes: 0 additions & 5 deletions Server01/util/verifyJWT.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ def wrapper(request, *args, **kwargs):
except jwt.InvalidTokenError:
error_message = {'error': '非法的token'}
return JsonResponse(error_message, status=401)
except AttributeError as e:
print(e)
error_message = {'error': '未查询到登录信息,请重新登录'}
return JsonResponse(error_message, status=403)

return wrapper


Expand Down
Binary file modified Server01/views/__pycache__/comment.cpython-39.pyc
Binary file not shown.
Binary file modified Server01/views/__pycache__/post.cpython-39.pyc
Binary file not shown.
Binary file modified Server01/views/__pycache__/user.cpython-39.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion Server01/views/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ def load_reply(request):
} for comment in filter_replies if comment
]
return JsonResponse({'info': data, 'count': len(data)}, status=200)
return JsonResponse({'error': '错误的操作'}, status=404)
return JsonResponse({'error': '错误的操作'}, status=404)
20 changes: 14 additions & 6 deletions Server01/views/post.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json

from PIL import Image
from django.db.models import Q
from django.http import JsonResponse

Expand All @@ -14,6 +15,9 @@ def upload_post(request, payload):
file = request.FILES['file']
id = request.POST.get('id')
file_path = SYSTEM_PATH + 'post/' + str(id) + '-' + file.name
with Image.open(file) as img:
image_height = img.height
image_width = img.width
with open(file_path, 'wb') as destination:
for chunk in file.chunks():
destination.write(chunk)
Expand All @@ -23,7 +27,7 @@ def upload_post(request, payload):
}
post = models.Post.objects.filter(id=id).first()
if post:
models.Image.objects.create(imagePath=result['filepath'], post=post)
models.Image.objects.create(imagePath=result['filepath'], post=post, height=image_height, width=image_width)
return JsonResponse({'data': 'success'}, status=200)
return JsonResponse({'error': '错误的操作'}, status=401)

Expand Down Expand Up @@ -79,7 +83,7 @@ def query_post_index(request):
)
else:
posts = models.Post.objects
posts = filter_querySet(posts, offset, limit=10)
posts = filter_querySet(posts, offset, limit=5)
if posts:
return JsonResponse({'info': list(combine_index_post(posts))}, status=200)
# 没有内容了
Expand Down Expand Up @@ -116,7 +120,11 @@ def post_delete(request, payload):
data = json.loads(request.body)
id = data['id']
post = models.Post.objects.filter(id=id).first()
if post.user.id == payload['user_id']:
post.delete()
return JsonResponse({'success': '帖子删除成功'}, status=200)
return JsonResponse({'error': '错误操作'}, status=404)
if post:
if post.user.id == payload['user_id']:
post.delete()
return JsonResponse({'success': '帖子删除成功'}, status=200)
print(payload)
print(data, post)
# return JsonResponse({'error': '错误操作'}, status=404)
# return JsonResponse({'error': '未查询到帖子信息'}, status=404)
8 changes: 2 additions & 6 deletions Server01/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import Server01.models as models
from Server01.util.auxiliaryFuction import check_email, combine_index_post, check_and_delete, filter_querySet, \
convert_to_timezone, get_user_post_info, get_user_info
get_user_post_info, get_user_info
from Server01.util.verifyJWT import create_token, authenticate_request
from webServer.settings import SYSTEM_PATH, TIME_ZONE
from webServer.settings import SYSTEM_PATH


# 用户登录
Expand Down Expand Up @@ -202,7 +202,3 @@ def user_control_index(request, payload):
total = user_data.count()
return JsonResponse({'info': info, 'total': total}, status=200)
return JsonResponse({'error': '错误的操作'}, status=404)




Binary file modified webServer/__pycache__/settings.cpython-39.pyc
Binary file not shown.

0 comments on commit b38e34e

Please sign in to comment.