Пример #1
0
    def get(self, request, *args, **kwargs):
        search_form = SearchForm(self.request.GET)

        if search_form.is_valid():
            search_username = Account.objects.filter(
                user__username=search_form.cleaned_data['search']).values(
                    'user__username', 'prof_pic')
            serialize = {'data': list(search_username)}
            return JsonResponse(serialize, safe=False)
Пример #2
0
def search(request):
    if request.method == 'POST':
        form = SearchForm(request.POST)
        if form.is_valid():
            if 'user_search' in form.data:
                return redirect('/user/' +
                                form.cleaned_data.get('search_text') + '/')
            if 'tag_search' in form.data:
                return redirect('/tag/' +
                                form.cleaned_data.get('search_text') + '/')

    return redirect('/')
Пример #3
0
	def get(self,request,*args,**kwargs):
		username = kwargs.get('username')

		current_user = self.request.user
		
		account = User.objects.get(username=username)
		
		pictures = PicturesUser.objects.filter(user_id=account.id)
		
		search_form = SearchForm()

		try:
			followed = Followers.objects.values(
				'followed_user__username',
				'follower_username',
				'follow'
		
			).get(
		
				followed_user__username=account.username,
				follower_username=self.request.user.username
			)
		
		except:
		
			followed = False

		try: 	
			package = {
				'user_data':account,
				'followers':self.followers,
				'no_prof_pic':False,
				'pictures':pictures,
				'search_form':search_form,
				'current_user':current_user,
				'followed': followed,
			}
			
			return render(
				request,
				self.template_name,
				package
			)

		except:
			package = {
				'user_data': account,
				'followers':self.followers,
				'no_prof_pic':True,
				'pictures':pictures,
				'search_form':search_form,
				'current_user': current_user,
				'followed':followed,
			}
			
			return render(
				request,
				self.template_name,
				package
			)
Пример #4
0
	def post(self,request,*args,**kwargs):
		user = User.objects.get(username=request.user.username)
		account_user = Account.objects.get(user_id=request.user.id)
		search_form = SearchForm()
		edit = EditProfileForm(request.POST,instance=request.user)
		prof_pic_form = ProfPicForm(data=request.POST,files=request.FILES,instance=account_user)
		
		try:
			account.prof_pic.url
			prof_pic = account.prof_pic.url
		except:
			prof_pic = False

		if edit.is_valid() and prof_pic_form.is_valid():
			edit.save()
			prof_pic_form.save()
			serialize_edit = UserSerialize(User.objects.get(username=request.user.username))
			serialize_pic = ProfPicSerialize(Account.objects.get(user_id=request.user.id))
			data = {
				'profile': serialize_edit.data,
				'prof_account': serialize_pic.data
			}

			return JsonResponse(data, safe=False)

		else:
			return JsonResponse({'errors':edit.errors},safe=False)
Пример #5
0
	def get(self,request,*args,**kwargs):
		search_form = SearchForm()
		edit_form = EditProfileForm(instance=request.user)
		change_password_form = PasswordChangeForm(user=request.user)
		account = Account.objects.get(user_id=request.user.id)
		archived_post = Feeds.objects.filter(user_id=self.request.user.id,archived=True)
		prof_pic_form = ProfPicForm()

		try:
			account.prof_pic.url
			prof_pic = account.prof_pic.url
		except:
			prof_pic = False

		package = {
			'account_user':account,
			'current_user':request.user,
			'search_form':search_form,
			'edit_form': edit_form,
			'prof_pic_form':prof_pic_form,
			'archived_post':archived_post,	
			'change_password_form':change_password_form,
			'prof_pic':prof_pic,
		}
		
		return render(request,self.template_name,package)
Пример #6
0
    def get_context_data(self, **kwargs):
        context = super(ViewPost, self).get_context_data(**kwargs)
        context['comment_data'] = Comments.objects.filter(
            post_id=context.get('feeds').id)
        context['comment_form'] = CommentForm()
        context['search_form'] = SearchForm()
        context['user_data'] = self.request.user
        context['current_user'] = self.request.user
        context['feed_form'] = FeedForm()
        context['picture_form'] = PicturesForm()

        return context
Пример #7
0
	def post(self,request,*args,**kwargs):
		search_form = SearchForm()
		edit_form = EditProfileForm(instance=request.user)
		change_password_form = PasswordChangeForm(user=request.user)
		account = Account.objects.get(user_id=request.user.id)
		prof_pic_form = ProfPicForm()
		
		password_form = PasswordChangeForm(data=request.POST,user=request.user)

		try:
			account.prof_pic.url
			prof_pic = account.prof_pic.url
		except:
			prof_pic = False

		package = {
			'account_user':account,
			'current_user':request.user,
			'search_form':search_form,
			'edit_form': edit_form,
			'change_password_form': password_form,
			'prof_pic_form':prof_pic_form,
			'prof_pic':prof_pic,
		}

		if password_form.is_valid():
			password_form.save()
			update_session_auth_hash(request,password_form.user)
			print('if')
			package['success'] = "New Password Set"
			return render(request,self.template_name,package)


		else:
			print('else')
			package['errors'] = password_form.errors
			package['pic_errors'] = prof_pic_form.errors
			return render(request,self.template_name,package)
Пример #8
0
class FeedsView(TemplateView):
    """
	Feeds View
	GET - render template, send context data
	POST - return json response to display recently added comments

	"""
    template_name = 'feed/users_page.html'
    comment_form = CommentForm()
    feed_form = FeedForm()
    picture_form = PicturesForm()
    search_form = SearchForm()

    def get(self, request, *args, **kwargs):
        followers = Followers.objects.filter(
            follow=True,
            follower_username=request.user.username).values('followed_user_id')

        feed_data = Feeds.objects.filter(
            user_id__in=followers, archived=False) | Feeds.objects.filter(
                user_id=request.user.id, archived=False)

        comment_data = Comments.objects.filter(
            post_id__in=feed_data.values('id'))

        feed_data._result_cache = None

        comment_data._result_cache = None

        package = {
            'feed_data': feed_data.order_by('-id'),
            'comment_data': comment_data,
            'user_data': request.user,
            'comment_form': self.comment_form,
            'feed_form': self.feed_form,
            'picture_form': self.picture_form,
            'search_form': self.search_form,
            'current_user': self.request.user,
        }

        return render(request, self.template_name, package)

    def post(self, request, *args, **kwargs):
        form = CommentForm(self.request.POST)

        feed = Feeds.objects.get(id=kwargs.get('feed_id'))

        if form.is_valid():

            comment = form.save(commit=False)
            comment.post_id = feed.id
            comment.user_id = self.request.user.id
            comment.save()
            comment.refresh_from_db()

            serializer = CommentSerialize(Comments.objects.get(id=comment.id))
            serialized = serializer.data
            serialized['username'] = comment.user.username
            serialized['current_user'] = request.user.username

            return JsonResponse(serialized, safe=False)