def atualizarDados(request): form = '' user = request.user if request.POST != None: form = CustomUserChangeForm(request.POST or None, request.FILES or None, instance=user) if form.is_valid(): form.save() return redirect('index') return render(request, 'principal/atualizar_dados.html', { 'form': form, 'user': user })
def profile_edit(request, pk): user = User.objects.get(pk=pk) profile = user.user_profile if request.method == "POST": user_change_form = CustomUserChangeForm( request.POST, instance=user ) profile_form = SignupModelForm( request.POST, request.FILES, instance=profile ) if user_change_form.is_valid() and profile_form.is_valid(): user_change_form.save() profile = profile_form.save(commit=False) profile.name = request.user.last_name + request.user.first_name # user의 이름 -> profile.name profile.save() return redirect('myprofile:my_profile', request.user.pk) elif request.method == "GET": user_change_form = CustomUserChangeForm(instance=user) profile_form = SignupModelForm(instance=profile) print(profile.photo) return render(request, 'myprofile/profile_edit.html', { 'user_change_form': user_change_form, 'profile_form': profile_form, })
def ChangeUserData(request): if request.method == "POST": user = get_object_or_404(CustomUser, id=request.user.id) form = CustomUserChangeForm(request.POST, request.FILES, instance=user) form.password = user.password if form.is_valid(): change_data = form.save(commit=False) change_data.save() return redirect('show_user') else: return render(request, 'accounts/user_customize.html', { 'form': form, 'user': user }) else: user = get_object_or_404(CustomUser, id=request.user.id) form = CustomUserChangeForm( initial={ 'username': user.username, 'profile_icon': user.profile_icon, 'self_introduction': user.self_introduction }) return render(request, 'accounts/user_customize.html', {'form': form})
def ProfileNewPlayerView(request): if request.method == 'POST': form = CustomUserChangeForm(request.POST, instance=request.user) if form.is_valid: form.save() return redirect('profile-amended') else: form = CustomUserChangeForm(instance=request.user) if int(os.environ['RESULTSWEEK']) < 19: predweek = int(os.environ['PREDICTSEASON']+os.environ['RESULTSWEEK']) try: mypreds = Prediction.objects.filter(User=request.user, PredWeek=predweek) if mypreds.count() > 0: preds = "yes" else: preds="no" mypredweek = os.environ['RESULTSWEEK'] except Prediction.DoesNotExist: mypreds = [] preds = "no" mypredweek = "0" else: mypreds = [] preds="no" mypredweek = "0" context = { 'mypredweek': mypredweek, 'preds': preds, 'mypreds':mypreds, 'form': form } return render(request, 'predictor/profile-newplayer.html', context)
def edit_profile(request): if request.method == 'POST': form = CustomUserChangeForm(request.POST, instance=request.user) if form.is_valid(): form.save() return redirect(reverse('edit_profile')) else: form = CustomUserChangeForm(instance=request.user) args = {'form': form} return render(request, 'registration/edit_profile.html', args)
def update(request): if request.method == 'POST': form = CustomUserChangeForm(request.POST, instance=request.user) if form.is_valid(): form.save() return redirect('alcohols:index') else: form = CustomUserChangeForm(instance=request.user) context = { 'form': form, } return render(request, 'accounts/update.html', context)
def update(request): if request.method == 'POST': user_change_form = CustomUserChangeForm(request.POST, instance=request.user) if user_change_form.is_valid(): user_change_form.save() return redirect('/accounts/people/', request.user.username) else: user_change_form = CustomUserChangeForm(instance=request.user) return render(request, 'registration/update.html', {'user_change_form': user_change_form})
def update_my_profile(request): print(request.POST) if "cancel" in request.POST: return redirect('insurance:list-employee') user = get_object_or_404(CustomUser, pk=request.user.id) print(user.password) form = CustomUserChangeForm(request.POST or None, request.FILES or None, instance=user) form.fields['username'].widget.attrs['readonly'] = True # form.fields['is_admin'].widget.attrs['disabled'] = True # form.fields['is_admin'].widget.attrs['checked'] = True if request.method == 'POST': print(request.POST['username']) if form.is_valid(): user.save() return redirect('insurance:list-employee') else: messages.error(request, 'Please correct the error below.') password_form = AdminPasswordChangeForm(request.user) return render(request, 'accounts/update_my_profile.html', { 'form': form, 'password_form': password_form })
def ProfileView(request): if request.method == 'POST': form = CustomUserChangeForm(request.POST, instance=request.user) if form.is_valid: form.save() # Flush caches in case fave team changes and effects Divisional scoreboard for c in cachestoflush: cache.delete(c) return redirect('profile-amended') else: try: requestor = request.user alltime = ScoresAllTime.objects.get(User=requestor) except ScoresAllTime.DoesNotExist: return redirect('profile-newplayer') else: # if week one, show best from last season if int(os.environ['RESULTSWEEK']) == 1: profileseason = str((int(os.environ['PREDICTSEASON'])) -1) else: profileseason = os.environ['PREDICTSEASON'] if int(os.environ['RESULTSWEEK']) < 19: predweek = int(os.environ['PREDICTSEASON']+os.environ['RESULTSWEEK']) try: mypreds = Prediction.objects.filter(User=request.user, PredWeek=predweek) if mypreds.count() > 0: preds = "yes" else: preds="no" mypredweek = os.environ['RESULTSWEEK'] except Prediction.DoesNotExist: mypreds = [] preds = "no" mypredweek = "0" else: mypreds = [] preds="no" mypredweek = "0" # Points dict for Season Score Chart mypoints = {} try: for i in ScoresWeek.objects.filter(Season=int(os.environ['PREDICTSEASON']), User=request.user.pk).order_by('Week'): mypoints[str(i.Week)] = i.WeekScore # Return only latest 6 points if len(mypoints) > 6: mypoints = dict(list(mypoints.items())[len(mypoints)-6:]) # Fill in zero points for bar chart for missed weeks rw = int(os.environ['RESULTSWEEK']) if rw > 19: limit = 19 else: limit = rw if rw < 7: lowerlimit = 1 else: lowerlimit = rw-6 checklist = [] for i in range(lowerlimit,limit): checklist.append(str(i)) for i in checklist: if i not in mypoints.keys(): mypoints[i] = 0 except ScoresWeek.DoesNotExist: mypoints = None # Avg Points for Season Score Chart avgpoints = cache.get('AvgPointsCache') if not avgpoints: try: avgpoints = AvgScores.objects.get(Season=int(os.environ['PREDICTSEASON'])).AvgScores # Return only latest 6 points if len(avgpoints) > 6: avgpoints = dict(list(avgpoints.items())[len(avgpoints)-6:]) cache.set('AvgPointsCache', avgpoints, CacheTTL_1Week) except AvgScores.DoesNotExist: avgpoints = None form = CustomUserChangeForm(instance=request.user) template = "predictor/profile.html" try: positions = requestor.Positions['data'][os.environ['PREDICTSEASON']] except(TypeError, KeyError): positions = None current = ScoresSeason.objects.get(User=requestor, Season=profileseason) seasonhigh = current.SeasonBest seasonlow = current.SeasonWorst seasonpct = current.SeasonPercentage alltimehigh = alltime.AllTimeBest alltimelow = alltime.AllTimeWorst alltimepct = alltime.AllTimePercentage context = { 'avgpointsjson': avgpoints, 'mypointsjson': mypoints, 'positionsjson': positions, 'mypredweek': mypredweek, 'preds': preds, 'mypreds':mypreds, 'form': form, 'season': profileseason, 'seasonhigh': seasonhigh, 'seasonlow': seasonlow, 'seasonpct': seasonpct, 'alltimehigh': alltimehigh, 'alltimelow': alltimelow, 'alltimepct': alltimepct, 'title': 'My Profile' } return render(request, template, context)