add message

This commit is contained in:
baoliang 2020-11-28 22:01:26 +08:00
parent 8424e12a9a
commit 4175686f12
5 changed files with 16 additions and 11 deletions

View File

@ -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)

View File

@ -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()))

View File

@ -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)})