0.7.64
profile change photo
This commit is contained in:
@@ -5,6 +5,6 @@ from django.urls import path
|
||||
from .js_views import *
|
||||
|
||||
urlpatterns = [
|
||||
|
||||
path('get_articles_block/', get_articles_block_ajax, name='get_articles_block_ajax'),
|
||||
|
||||
]
|
||||
@@ -1,12 +1,9 @@
|
||||
from django.urls import path
|
||||
from .views import *
|
||||
from .js_views import *
|
||||
|
||||
urlpatterns = [
|
||||
path('articles/', ArticlesPageView, name=u'articles'),
|
||||
path('articles/<int:year>/', ArticlesPageView, name=u'articles_by_year'),
|
||||
path('article/<str:art_url>/', ArticlesOnePageView, name=u'article_one'),
|
||||
path('info_page/<str:page_url>/', UserPageView, name=u'user_page'),
|
||||
|
||||
path('get_articles_block/', get_articles_block_ajax, name='get_articles_block_ajax'),
|
||||
]
|
||||
@@ -23,4 +23,6 @@ urlpatterns = [
|
||||
|
||||
|
||||
path('change_profile/', change_profile_ajax, name='change_profile_ajax'),
|
||||
path('change_profile_confirm/', change_profile_confirm_ajax, name='change_profile_confirm_ajax'),
|
||||
path('change_avatar_confirm/', change_avatar_confirm_ajax, name='change_avatar_confirm_ajax'),
|
||||
]
|
||||
@@ -12,6 +12,10 @@ from datetime import datetime
|
||||
from django.template.loader import render_to_string
|
||||
from django.urls import reverse
|
||||
from .funcs import *
|
||||
from django.core.exceptions import ValidationError
|
||||
import json
|
||||
from django.core.files import File
|
||||
import base64
|
||||
|
||||
|
||||
# @login_required(login_url='/profile/login/')
|
||||
@@ -64,6 +68,64 @@ def support_tickets_ajax(request):
|
||||
return JsonResponse({'html': html}, status=200)
|
||||
|
||||
|
||||
@login_required(login_url='/profile/login/')
|
||||
def change_avatar_confirm_ajax(request):
|
||||
from django.core.files.base import ContentFile
|
||||
|
||||
if request.method != 'POST':
|
||||
raise Http404
|
||||
|
||||
data = json.loads(request.body)
|
||||
file_data = json.loads(data[0])
|
||||
head, content = file_data['file'].split(',')
|
||||
content = base64.b64decode(content)
|
||||
file = ContentFile(content)
|
||||
request.user.user_profile.avatar.save(file_data['file_name'], file)
|
||||
request.user.user_profile.save(update_fields=['avatar'])
|
||||
|
||||
return JsonResponse({'url': request.user.user_profile.avatar.url})
|
||||
|
||||
|
||||
@login_required(login_url='/profile/login/')
|
||||
def change_profile_confirm_ajax(request):
|
||||
if request.method != 'POST':
|
||||
raise Http404
|
||||
|
||||
data = request.POST
|
||||
|
||||
from .forms import RegistrationForm
|
||||
form = RegistrationForm(data)
|
||||
if not form.is_valid():
|
||||
raise ValidationError(form.errors)
|
||||
|
||||
data_for_save = {}
|
||||
if 'firstname' in data:
|
||||
data_for_save.update({'first_name': data['firstname']})
|
||||
if 'lastname' in data:
|
||||
data_for_save.update({'last_name': data['lastname']})
|
||||
if 'email' in data:
|
||||
data_for_save.update({'email': data['email']})
|
||||
data_for_save.update({'username': data['email']})
|
||||
request.user.update(**data_for_save)
|
||||
|
||||
data_for_save = {}
|
||||
if 'password' in data:
|
||||
data_for_save.update({'password': data['password']})
|
||||
if 'confirm_password' in data:
|
||||
data_for_save.update({'confirm_password': data['confirm_password']})
|
||||
request.user.u.set_password(data['password'])
|
||||
|
||||
data_for_save = {}
|
||||
if 'country' in data:
|
||||
data_for_save.update({'country': data['country']})
|
||||
if 'city' in data:
|
||||
data_for_save.update({'city': data['city']})
|
||||
if 'tel' in data:
|
||||
data_for_save.update({'phone': data['tel']})
|
||||
request.user.user_profile.update(**data_for_save)
|
||||
|
||||
html = get_profile_change_page_content_html(request)
|
||||
return JsonResponse({'html': html}, status=200)
|
||||
|
||||
@login_required(login_url='/profile/login/')
|
||||
def change_profile_ajax(request):
|
||||
|
||||
Reference in New Issue
Block a user