From 4175686f12ec85f1bce44d59fbcae1e8897bb9d1 Mon Sep 17 00:00:00 2001 From: baoliang Date: Sat, 28 Nov 2020 22:01:26 +0800 Subject: [PATCH] add message --- polls/urls.py | 2 +- polls/utils.py | 2 -- .../views/__pycache__/__init__.cpython-38.pyc | Bin 1605 -> 1630 bytes polls/views/__pycache__/user.cpython-38.pyc | Bin 6219 -> 7129 bytes polls/views/user.py | 23 ++++++++++++------ 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/polls/urls.py b/polls/urls.py index bf199ab..ffe2097 100644 --- a/polls/urls.py +++ b/polls/urls.py @@ -73,7 +73,7 @@ urlpatterns = [ path('app/intro.html', views.app_intro, name='polls_app_intro'), path('app/download/', views.download, name='polls_app_download'), path('app/has/update/', views.has_update, name='polls_app_has_update'), - path('app/profile/image/upload/', views.upload_image, name='polls_profile_upload'), + path('app/profile/image/upload/', views.upload_profile, name='polls_profile_upload'), ] tasks.process_notify_task(repeat=5) \ No newline at end of file diff --git a/polls/utils.py b/polls/utils.py index 84107f6..5733698 100644 --- a/polls/utils.py +++ b/polls/utils.py @@ -11,7 +11,6 @@ from aliyunsdkcore.client import AcsClient import uuid from aliyunsdkcore.profile import region_provider - def sent_sms_code(phone, code): clnt = YunpianClient('304eb08353f7ebf00596737acfc31f53') param = {YC.MOBILE: phone, @@ -131,7 +130,6 @@ def queryset_to_list(q, fields): l.append(r) return l - if __name__ == '__main__': # r = sent_sms_code('13993199566', 4321) # print(r.code(), type(r.code())) diff --git a/polls/views/__pycache__/__init__.cpython-38.pyc b/polls/views/__pycache__/__init__.cpython-38.pyc index 552b9a2b3ae626f457902f4e06d1dd6a9f146b42..08a71cfa3e77c87941489b4a56883bdff88d603b 100644 GIT binary patch delta 550 zcmW-d%Wl(95Qgp4X-aITY10Le#%V5X6VhDkq-mR$F4-e0G@Ht*-6-PxaX4|sk_TWF z`4L#LMqAIzOyGmi@-IvzmInpWp9(uk4cUu3G&rOfq%N z*Zh>QV3Um;<*-fL$WtCWw1ZvRMS%)QW<#t#J^P3v6_eEv`zTQf4ml`OIdN%mfC^Pm zr7CJvL!Ii0-xP;9q9YvBF&flBlbVUoh!<#43nz4fHnq{A4!YDuk9z1+9|IaBxh-)D zms~Z!()=f4h#?IzqET|piZhI9jB`521zq5hE)#Ex2_`hb6EiIK>Z_dMLb|1vw49AiMHfaR@%!~gT z&RhAMg)t94EM-xRa-UIRnL#+8MWK`qt1{z&QBhbMk+*y&tGw43b;coI(o-2eF5=sC z?N+vxAoD)N!jln#c_cfW>oR&A&LCJWy=fr(tOkrzhRYZ-MvOCsFPgmJ`6m9Ap6Q_^t|f-0kI{4KL7v# delta 525 zcmW-dy;9pi6on-t;b2Q(z#%x;!oT1jY|Fs}gCR8ZDKcqplks51A3G*H)W{vHuv!1_rfih{-V|En#R}| zCqx3a zyO;QwFyF*qt%18-orTf#CXkL=$Gjw~R2Ws>*b^CkzLT{T72;2JrAg_V5O*UP yA(%z7&BYF*%k3nB`Fu19q|fyqwzu|V$SYo7#eeNd);FtavgWRuy6Ko1b^iy9pLb0F diff --git a/polls/views/__pycache__/user.cpython-38.pyc b/polls/views/__pycache__/user.cpython-38.pyc index 5f2f14c0e072d7db4c37491b9b32b3477a334f23..746cda5321f782c21266ab420846664bc4e25690 100644 GIT binary patch delta 3589 zcma)9U2GKB6`s30GyA_@uXoor2Adxnm;eUKPx_NYrVUUC1R5YDL+EzBcf6kU%+BV{ zZ20L~n+Q}IS|@2Ht)dnQyOpXE3Gx7HDM_2EmHHC(ty0z7r>eGrM;`K4DLvW+V+lSJBnj0>e+x$Pr0fa~E0E2+!3W%W{jBQ!#5r zX1v-knL+&_Vs;T8bq&umYZVvtqG?}gtZDd8Upe9imsDw{~R|0m_S_>%K}Ufs8= z03+}Ilz?@dOk2iP+wjI6${_e8)`y@1@Q5>7HOijL)iKlZ491l)lK~fse_72Rz;*Iu ziQ2$vupkz}p-2hCfaa-+;T0WLEHk6z8C<4jIUtgUCyX;}6DkfPY<@Q~Xl_LbS<~V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B@&=JO^U4WQkOU*^~dqL+ZyCImmY3#-O*ui%wPSPYR9!w>` I=L;ME29BUC?*IS* diff --git a/polls/views/user.py b/polls/views/user.py index cbd4921..52b9393 100644 --- a/polls/views/user.py +++ b/polls/views/user.py @@ -6,9 +6,11 @@ from django.views.decorators.csrf import csrf_exempt from django_token.models import Token import datetime from django.conf import settings -import tempfile import shutil import uuid +import os +from pathlib import Path + from polls.models import Notice, VerifyCode @@ -225,14 +227,19 @@ def reset_password(request): @csrf_exempt @polls_login_required def upload_profile(request): + u = request.user source = request.FILES['photo'] - ext = source.split('.')[-1] + ext = source.name.split('.')[-1] if ext not in ['jpg', 'png', 'jpeg', 'gif']: return JsonResponse({'status': 'error', 'message': '上传的文件不是图片'}) - + filename = "%s.%s" % (uuid.uuid4(), ext) - # fd, filepath = tempfile.mkstemp( - # prefix=source.name, dir=settings.MEDIA_ROOT) - # with open(filepath, 'wb') as dest: - # shutil.copyfileobj(source, dest) - return JsonResponse({'status': 'success', 'message': filename}) + foldpath = os.path.join(settings.MEDIA_ROOT, 'profile') + Path(foldpath).mkdir(parents=True, exist_ok=True) + filepath = os.path.join(foldpath, filename) + with open(filepath, 'wb') as dest: + shutil.copyfileobj(source, dest) + profile = Userprofile.objects.filter(user=u).first() + profile.image = '/profile/%s' % filename + profile.save() + return JsonResponse({'status': 'success', 'message': request.build_absolute_uri('/media/profile/%s' % filename)})