Beispiel #1
0
 def post(self, request):
     form = SearchForm(request.POST)
     if form.is_valid():
         query = form.cleaned_data['query']
         tweets = Tweet.objects.filter(text__icontains=query)
         context = Context({"query": query, "tweets": tweets})
         return_str = render_to_string('partials/_tweet_search.html', context)
         return HttpResponse(json.dumps(return_str), content_type="application/json")
     else:
         HttpResponseRedirect("/search")
Beispiel #2
0
 def get(request):
     query = request.GET.get('query')
     tweets = Tweet.objects.filter(
         text__icontains=query).order_by('-created') if query else ' '
     form = SearchForm() if not query else SearchForm(
         initial={'query': query})
     return render(request, 'search.html', {
         'title': 'Search',
         'search': form,
         'tweets': tweets
     })
Beispiel #3
0
 def post(request):
     form = SearchForm(request.POST)
     if form.is_valid():
         query = form.cleaned_data['query']
         tweets = Tweet.objects.filter(
             text__icontains=query).order_by('-created')
         return_str = render_to_string('partials/_tweet_wall.html', {
             'query': query,
             'tweets': tweets
         })
         return HttpResponse(json.dumps(return_str),
                             content_type='application/json')
     else:
         return HttpResponse('')
Beispiel #4
0
 def get(self, request, username):
     params = {}
     userProfile = User.objects.get(username=username)
     try:
         userFollower = UserFollowers.objects.get(user=userProfile)
         if userFollower.followers.filter(username=request.user.username).exists():
             params["following"] = True
         else:
             params["following"] = False
     except:
         userFollower = []
     form = TweetForm(initial={'country': 'Global'})
     search_form = SearchForm()
     tweets = Tweet.objects.filter(user=userProfile).order_by('-created_date')
     paginator = Paginator(tweets, TWEET_PER_PAGE)
     page = request.GET.get('page')
     try:
         tweets = paginator.page(page)
     except PageNotAnInteger:
         # If page is not an integer, deliver first page.
         tweets = paginator.page(1)
     except EmptyPage:
         # If page is out of range (e.g. 9999), deliver last page of results.
         tweets = paginator.page(paginator.num_pages)
     params["tweets"] = tweets
     params["profile"] = userProfile
     params["form"] = form
     params["search"] = search_form
     return render(request, 'profile.html', params)
Beispiel #5
0
def home(request):
    user = request.user
    if not user.is_authenticated:
        return HttpResponseRedirect("/tweets/sign-in/")
    return render(request,
                  'tweets/home.html',
                  context={
                      'user': user,
                      'form': SearchForm(),
                  })
	def get(self, request, username):
		form = TweetForm()
		params = dict()
		user = User.objects.get(username=username) 
		userFollower = UserFollower.objects.get(user=userProfile)
		if userFollower.followers.filter(username=request.user.username).exists():
			params["following"] = True
		else:
			params["following"] = False
			form = TweetForm(initial={'country': 'Global'})
			search_form = SearchForm()
			tweets = Tweet.objects.filter(user=userProfile).order_by('-created_date')
			params["tweets"] = tweets
			params["profile"] = userProfile
			params["form"] = form
			params["search"] = search_form
			return render(request, 'profile.html', params)
Beispiel #7
0
 def get(self, request):
     form = SearchForm()
     params = dict()
     params["search"] = form
     return render(request, 'search.html', params)