def post(self, *args, **kwargs): context = self.get_context_data() instance = get_object_or_404(User, pk=self.request.user.id) form = ConcordiaUserEditForm( self.request.POST, self.request.FILES, instance=instance ) if form.is_valid(): obj = form.save(commit=True) obj.id = self.request.user.id if "password1" not in self.request.POST and "password2" not in self.request.POST: obj.password = self.request.user.password else: update_session_auth_hash(self.request, obj) obj.save() if "myfile" in self.request.FILES: myfile = self.request.FILES["myfile"] profile, created = UserProfile.objects.update_or_create( user=obj, defaults={"myfile": myfile} ) messages.success(self.request, "User profile information changed!") else: messages.error(self.request, form.errors) return HttpResponseRedirect("/account/profile/") return redirect(reverse("user-profile"))
def get_context_data(self, **kws): last_name = self.request.user.last_name if last_name: last_name = " " + last_name else: last_name = "" data = { "username": self.request.user.username, "email": self.request.user.email, "first_name": self.request.user.first_name + last_name, } profile = UserProfile.objects.filter(user=self.request.user) if profile: data["myfile"] = profile[0].myfile transcriptions = Transcription.objects.filter( user_id=self.request.user.id).order_by("-updated_on") for t in transcriptions: collection = Collection.objects.get(id=t.asset.collection.id) t.collection_name = collection.slug return super().get_context_data(**dict( kws, transcriptions=transcriptions, form=ConcordiaUserEditForm(initial=data), ))
def get_context_data(self, **kws): last_name = self.request.user.last_name if last_name: last_name = " " + last_name else: last_name = "" data = { "username": self.request.user.username, "email": self.request.user.email, "first_name": self.request.user.first_name + last_name, } response = requests.get( "%s://%s/ws/user_profile/%s/" % (self.request.scheme, self.request.get_host(), self.request.user.id), cookies=self.request.COOKIES, ) user_profile_json_val = json.loads(response.content.decode("utf-8")) if "myfile" in user_profile_json_val: data["myfile"] = user_profile_json_val["myfile"] response = requests.get( "%s://%s/ws/transcription_by_user/%s/" % (self.request.scheme, self.request.get_host(), self.request.user.id), cookies=self.request.COOKIES, ) transcription_json_val = json.loads(response.content.decode("utf-8")) for trans in transcription_json_val["results"]: campaign_response = requests.get( "%s://%s/ws/campaign_by_id/%s/" % ( self.request.scheme, self.request.get_host(), trans["asset"]["campaign"]["id"], ), cookies=self.request.COOKIES, ) trans["campaign_name"] = json.loads( campaign_response.content.decode("utf-8") )["slug"] trans["updated_on"] = datetime.strptime( trans["updated_on"], "%Y-%m-%dT%H:%M:%S.%fZ" ) return super().get_context_data( **dict( kws, transcriptions=transcription_json_val["results"], form=ConcordiaUserEditForm(initial=data), ) )
def post(self, *args, **kwargs): context = self.get_context_data() instance = get_object_or_404(User, pk=self.request.user.id) form = ConcordiaUserEditForm(self.request.POST, self.request.FILES, instance=instance) if form.is_valid(): obj = form.save(commit=True) obj.id = self.request.user.id if not self.request.POST['password1'] and not self.request.POST[ 'password2']: obj.password = self.request.user.password obj.save() if 'myfile' in self.request.FILES: myfile = self.request.FILES['myfile'] profile, created = UserProfile.objects.update_or_create( user=obj, defaults={'myfile': myfile}) else: return render(self.request, self.template_name, locals()) return redirect(reverse('user-profile'))
def post(self, *args, **kwargs): context = self.get_context_data() instance = get_object_or_404(User, pk=self.request.user.id) form = ConcordiaUserEditForm(self.request.POST, self.request.FILES, instance=instance) if form.is_valid(): obj = form.save(commit=True) obj.id = self.request.user.id if (not self.request.POST["password1"] and not self.request.POST["password2"]): obj.password = self.request.user.password obj.save() if "myfile" in self.request.FILES: myfile = self.request.FILES["myfile"] profile, created = UserProfile.objects.update_or_create( user=obj, defaults={"myfile": myfile}) else: return HttpResponseRedirect("/account/profile/") return redirect(reverse("user-profile"))
def get_context_data(self, **kws): last_name = self.request.user.last_name if last_name: last_name = " " + last_name else: last_name = '' data = { 'username': self.request.user.username, 'email': self.request.user.email, 'first_name': self.request.user.first_name + last_name } profile = UserProfile.objects.filter(user=self.request.user) if profile: data['myfile'] = profile[0].myfile return super().get_context_data( **dict(kws, transcriptions=Transcription.objects.filter( user_id=self.request.user.id).order_by('-updated_on'), form=ConcordiaUserEditForm(initial=data)))