コード例 #1
0
ファイル: views.py プロジェクト: soequelle/twissandra
def timeline(request):
    form = TweetForm(request.POST or None)
    if request.user['is_authenticated'] and form.is_valid():
        tweet_id = str(uuid.uuid1())
        cass.save_tweet(tweet_id, request.user['id'], {
            'id': tweet_id,
            'user_id': request.user['id'],
            'body': form.cleaned_data['body'],
        })
        return HttpResponseRedirect(reverse('timeline'))
    start = request.GET.get('start')
    if request.user['is_authenticated']:
        tweets = cass.get_timeline(request.user['id'], start=start,
            limit=NUM_PER_PAGE + 1)
    else:
        tweets = cass.get_userline(cass.PUBLIC_USERLINE_KEY, start=start,
            limit=NUM_PER_PAGE + 1)
    next = None
    if tweets and len(tweets) == NUM_PER_PAGE + 1:
        next = tweets[-1]['_ts']
    tweets = tweets[:NUM_PER_PAGE]
    context = {
        'form': form,
        'tweets': tweets,
        'next': next,
    }
    return render_to_response('tweets/timeline.html', context,
        context_instance=RequestContext(request))
コード例 #2
0
ファイル: views.py プロジェクト: latacita/mdd-cassandra
def timeline(request):
    form = TweetForm(request.POST or None)
    if request.user['is_authenticated'] and form.is_valid():
        tweet_id = str(uuid.uuid1())
        cass.save_tweet(
            tweet_id, request.session['username'], {
                'username': request.session['username'],
                'body': form.cleaned_data['body'],
            })
        return HttpResponseRedirect(reverse('timeline'))
    start = request.GET.get('start')
    if request.user['is_authenticated']:
        tweets, next = cass.get_timeline(request.session['username'],
                                         start=start,
                                         limit=NUM_PER_PAGE)
    else:
        tweets, next = cass.get_userline(cass.PUBLIC_USERLINE_KEY,
                                         start=start,
                                         limit=NUM_PER_PAGE)
    context = {
        'form': form,
        'tweets': tweets,
        'next': next,
    }
    return render_to_response('tweets/timeline.html',
                              context,
                              context_instance=RequestContext(request))
コード例 #3
0
ファイル: views.py プロジェクト: mah-qurashy/tweetme
def tweet_create(request, *args, **kwargs):
    form = TweetForm(request.POST)
    if form.is_valid():
        form.instance.author = request.user
        new_tweet = form.save()
        new_tweet_serializer = new_tweet.serializer(request.user) 
        return JsonResponse({"process": "success", "tweet": new_tweet_serializer})
    return JsonResponse({"process": "failed", "errors": form.errors})
コード例 #4
0
ファイル: views.py プロジェクト: shashankdass/Activibe
def timeline(request):
   # pdb.set_trace()
#print request.GET['status'] # for GET form method
#print request.POST['status'] # for POST form method
#debug
    try:
        if request.user['is_authenticated'] :
            status_opcode=101
            print request.POST['status'] # for POST form method
            print request.POST['user_id'] # for POST form method
            print request.POST['activibe'] # for POST form method
            user_status  = request.POST['status'] # for POST form method
            user_id      = request.POST['user_id'] # for POST form method
            user_domain  = request.POST['activibe'] # for POST form method
	    if user_domain == 101:
	        cass.save_user_status(user_status,user_id,user_domain)
                #start = request.GET.get('start')
                start=1
                status,next = cass.get_user_status(user_id)
                context = {
                   'status': status,
                   'next': next,
                }
                return render_to_response('tweets/timeline.html', context,
                    context_instance=RequestContext(request))
         #       return HttpResponseRedirect(reverse('timeline'))
	else:
 	    print "Invalid Request"
    except:
        print "Unexpected error:"
#debug

    form = TweetForm(request.POST or None)
    if request.user['is_authenticated'] and form.is_valid():
        tweet_id = str(uuid.uuid1())
        cass.save_tweet(tweet_id, request.session['username'], {
            'username': request.session['username'],
            'body': form.cleaned_data['body'],
        })
        return HttpResponseRedirect(reverse('timeline'))
    start = request.GET.get('start')
    if request.user['is_authenticated']:
        tweets,next = cass.get_timeline(request.session['username'],
            start=start, limit=NUM_PER_PAGE)
        #tweets,next = cass.get_friends(request.session['username'],
         #    limit=NUM_PER_PAGE)
    else:
        tweets,next = cass.get_userline(cass.PUBLIC_USERLINE_KEY, start=start,
            limit=NUM_PER_PAGE)
    context = {
        'form': form,
        'tweets': tweets,
        'next': next,
    }
    return render_to_response('tweets/timeline.html', context,
        context_instance=RequestContext(request))
コード例 #5
0
ファイル: views.py プロジェクト: Alexeysw4/dj
def tweet_create(request):
    if request.method == 'POST':
        tweet_form = TweetForm(request.POST)
        if tweet_form.is_valid():
            Tweet.objects.create(text=tweet_form.cleaned_data['text'], user=request.user)
            messages.success(request, 'Tвит добавлен успешно')
            return HttpResponseRedirect(reverse('dashboard'))
    else:
        tweet_form = TweetForm()
    return render(request, 'tweets/tweet/create.html', {'tweet_form': tweet_form})
コード例 #6
0
def nuevo_tweet(request):
    if request.method == 'POST':
        form = TweetForm(request.POST)
        if form.is_valid():
            tweet =form.save(commit=False)
            tweet.usuario = request.user
            tweet.save()
    form = TweetForm()
    context = RequestContext(request, {'form': form})
    return render_to_response('nuevo-tweet.html', context)
コード例 #7
0
ファイル: views.py プロジェクト: quinto7/django_mytweets
 def post(self, request, username):
     form = TweetForm(self.request.POST)
     if form.is_valid():
         user = User.objects.get(username=username)
         tweet = Tweet(text=form.cleaned_data['text'], user=user, country=form.cleaned_data['country'])
         tweet.save()
         words = form.cleaned_data['text'].split(" ")
         for word in words:
             if word[0] == "#": #Separamos todas las letras del tweet y si empieza con #, se va a crear un hashtag de esa palabra
                 hashtag, created = HashTag.objects.get_or_create(name=word[1:])
                 hashtag.tweet.add(tweet)
     return HttpResponseRedirect('/user/' +username)
コード例 #8
0
ファイル: views.py プロジェクト: gbartlett/twitter_clone
def submit(request):
    if request.method == "POST":
        tweet_form = TweetForm(data=request.POST)
        next_url = request.POST.get("next_url", "/")
        if tweet_form.is_valid():
            tweet = tweet_form.save(commit=False)
            tweet.user = request.user
            tweet.save()
            return redirect(next_url)
        else:
            return public(request, tweet_form)
    return redirect('/')
コード例 #9
0
ファイル: views.py プロジェクト: aomramete/Lab-04-AJAX
    def post(self, request, username):
        form = TweetForm(self.request.POST)
        if form.is_valid():
            user = User.objects.get(username=username)
##            tweet = Tweet(text=form.cleaned_data['text'], user=user, country=form.cleaned_data['country'])
            tweet = Tweet(text=form.cleaned_data['text'], user=user)
            tweet.save()
            words = form.cleaned_data['text'].split(" ")
            for word in words:
                 if word[0] == "#":
                    hashtag, created = HashTag.objects.get_or_create(name=word[1:])
                    hashtag.tweet.add(tweet)
        return HttpResponseRedirect('/user/'+username)
コード例 #10
0
ファイル: views.py プロジェクト: comunidad-devf/tuitclone
def new_tweet(request):
	if request.method == 'POST':
		form = TweetForm(request.POST)
		print request.POST
		return HttpResponse('')
		if form.is_valid():
			form.save()
			return HttpResponse('Guardado!')
		else:
			return render(request, 'tweets/create_tweet.html', {'tweet_form': form})

	form = TweetForm()
	return render(request, 'tweets/create_tweet.html', {'tweet_form': form})
コード例 #11
0
ファイル: views.py プロジェクト: florentio/minitweeter
 def post(self, request, username):
     form = TweetForm(self.request.POST)
     if form.is_valid():
         print("Valid form")
         user = User.objects.get(username=username)
         tweet = Tweet(text=form.cleaned_data['text'], user=user, country=form.cleaned_data['country'])
         tweet.save()
         words = form.cleaned_data['text'].split(" ")
         for word in words :
             if word[0] == "#" :
                 hashtag = HashTag.objects.get_or_create(name=word[1:])
                 hashtag.tweets.add(tweet)
                 hashtag.save()
     return HttpResponseRedirect('/user/'+username )
コード例 #12
0
ファイル: views.py プロジェクト: jokkiz/django-tweet
 def post(self, request, username):
     form = TweetForm(self.request.POST)
     if form.is_valid():
         user = User.objects.get(username=username)
         tweet = Tweet(text=form.cleaned_data["text"],
                       user=user,
                       country=form.cleaned_data["country"]
                       )
         tweet.save()
         words = form.cleaned_data["text"].split(" ")
         for word in words:
             if word[0] == "#":
                 hashTag, created = HashTag.objects.get_or_create(name=word[1:])
                 hashTag.tweet.add(tweet)
     return HttpResponseRedirect("/user/" + username + "/?page=1")
コード例 #13
0
ファイル: views.py プロジェクト: phonxis/mytweets
 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)
コード例 #14
0
	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)
コード例 #15
0
 def post(request, username):
     form = TweetForm(request.POST)
     if form.is_valid():
         user = User.objects.get(username=username)
         tweet = Tweet(
             text=form.cleaned_data['text'],
             user=user,
             country=form.cleaned_data['country'],
         )
         tweet.save()
         words = form.cleaned_data['text'].split(' ')
         for word in words:
             if word[0] == '#':
                 tag, created = HashTag.objects.get_or_create(name=word[1:])
                 tag.tweet.add(tweet)
         return HttpResponseRedirect(reverse('profile', args=[user]))
     return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
コード例 #16
0
 def get(self, request, username):
     form = TweetForm()
     params = dict()
     user = User.objects.get(username=username)
     tweets = Tweet.objects.filter(user=user)
     params["tweets"] = tweets
     params["user"] = user
     params["form"] = form
     return render(request, 'profile.html', params)
コード例 #17
0
ファイル: views.py プロジェクト: kabala/django-twitter-thing
 def get(self, request, username):
     params = {}
     user = User.objects.get(username=username)
     tweets = Tweet.objects.filter(user=user)
     form = TweetForm()
     params['tweets'] = tweets
     params['user'] = user
     params['form'] = form
     return render(request, 'profile.html', params)
コード例 #18
0
ファイル: views.py プロジェクト: JefferOliver28/twissandra
def timeline(request):
    form = TweetForm(request.POST or None)
    if request.user['is_authenticated'] and form.is_valid():
        cass.save_tweet(request.session['username'], form.cleaned_data['body'])
        return HttpResponseRedirect(reverse('timeline'))
    start = request.GET.get('start')
    if request.user['is_authenticated']:
        tweets,next = cass.get_timeline(request.session['username'],
            start=start, limit=NUM_PER_PAGE)
    else:
        tweets,next = cass.get_timeline(cass.PUBLIC_TIMELINE_KEY, start=start,
            limit=NUM_PER_PAGE)
    context = {
        'form': form,
        'tweets': tweets,
        'next': next,
    }
    return render_to_response('tweets/timeline.html', context,
        context_instance=RequestContext(request))
コード例 #19
0
def tweet_create_view(request, *args, **kwargs):
    user = request.user
    if not request.user.is_authenticated:
        user = None
        if request.is_ajax():
            return JsonResponse({}, status = 401)
        return redirect(settings.LOGIN_URL)
    
    form = TweetForm(request.POST or None)
    next_url  = request.POST.get("next") or None
    print("next_url", next_url)
    
    if form.is_valid():
        obj = form.save(commit=False)
        obj.user = user 
        obj.save()

        if request.is_ajax():
            return JsonResponse(obj.serialize(), status = 201)
        if next_url != None and is_safe_url(next_url, ALLOWED_HOSTS):
            return redirect(next_url)
        
        form= TweetForm()
    if form.errors:
        return JsonResponse(form.errors, status=400)
    
    return render(request,'components/form.html', context={"form": form})
コード例 #20
0
def tweet_create_view(request, *args, **kwargs):
    form = TweetForm(request.POST or None)
    if form.is_valid():
        obj = form.save(commit=False)
        obj.save()
        form = TweetForm()
    return render(request, 'components/form.html', context={"form": form})
コード例 #21
0
ファイル: views.py プロジェクト: ericflo/tweeak
def timeline(request):
    form = TweetForm(request.POST or None)
    if request.user['is_authenticated'] and form.is_valid():
        tweet_id = str(uuid.uuid1())
        riakapi.save_tweet(tweet_id, request.session['username'], {
            'username': request.session['username'],
            'body': form.cleaned_data['body'],
        })
        return HttpResponseRedirect(reverse('timeline'))
    start = request.GET.get('start')
    if request.user['is_authenticated']:
        tweets,next = riakapi.get_timeline(request.session['username'],
            start=start, limit=NUM_PER_PAGE)
    else:
        tweets,next = riakapi.get_publicline(start=start, limit=NUM_PER_PAGE)
    context = {
        'form': form,
        'tweets': tweets,
        'next': next,
    }
    return render_to_response('tweets/timeline.html', context,
        context_instance=RequestContext(request))
コード例 #22
0
def homepage(request):
    form = TweetForm()
    following_ids = request.user.following.values_list('id', flat=True)
    following_tweets = Tweet.objects.filter(author_id__in=following_ids)
    user_tweets = Tweet.objects.filter(author_id=request.user.id)
    all_tweets = following_tweets | user_tweets
    all_tweets = all_tweets.select_related('author', 'author__profile',)\
            .prefetch_related('mentions', 'users_like')

    context = {
        'form': form,
        'all_tweets': all_tweets,
    }

    return render(request, 'home.html', context)
コード例 #23
0
ファイル: views.py プロジェクト: nj-bay/twits
def home(request):
    if request.method == "POST":
        form = TweetForm(request.POST)
        if form.is_valid():
            if form.save():
                return redirect("/")
    else:
        form = TweetForm()
        data = {'form': form}
        return render(request, "home.html", data)
コード例 #24
0
ファイル: views.py プロジェクト: rodrisan/conociendo-django
def nuevo_tweet(request):
    if request.method == 'POST':
        form = TweetForm(request.POST)
        if form.is_valid():
            tweet = form.save(commit=False)
            tweet.usuario = request.user
            tweet.save()
    form = TweetForm()
    context = RequestContext(request, {'form': form})
    return render_to_response('nuevo-tweet.html', context)
コード例 #25
0
def new_tweet(request):
    if request.method == 'POST':
        form = TweetForm(request.POST)
        print request.POST
        return HttpResponse('')
        if form.is_valid():
            form.save()
            return HttpResponse('Guardado!')
        else:
            return render(request, 'tweets/create_tweet.html',
                          {'tweet_form': form})

    form = TweetForm()
    return render(request, 'tweets/create_tweet.html', {'tweet_form': form})
コード例 #26
0
def profile(request, username):

    obj = get_object_or_404(get_user_model(), username=username)
    obj_profile = obj.profile
    all_tweets = obj.tweets.all().select_related('author', 'author__profile')\
            .prefetch_related('mentions', 'users_like')
    form = TweetForm()

    context = {
        'obj': obj,
        'obj_profile': obj_profile,
        'all_tweets': all_tweets,
        'form': form,
        'tweet_and_mention_count':
        all_tweets.count() + obj.mentions.all().count(),
    }

    return render(request, 'profiles/profile.html', context)
コード例 #27
0
 def get(request, username):
     params = {'title': 'User profile'}
     user_profile = User.objects.get(username=username)
     user_follower = UserFollower.objects.get(user=user_profile)
     if user_follower.followers.filter(
             username=request.user.username).exists():
         params['following'] = True
     else:
         params['following'] = False
     form = TweetForm(initial={'country': 'Global'})
     tweets = Tweet.objects.filter(user=user_profile).filter(
         is_active=True).order_by('-created')
     retweets = Retweet.objects.filter(user=user_profile).filter(
         is_active=True).order_by('-created')
     all_tweets = sorted(chain(tweets, retweets),
                         key=attrgetter('created'),
                         reverse=True)
     paginator = Paginator(all_tweets, TWEETS_PER_PAGE)
     page = request.GET.get('page')
     try:
         tweets = paginator.page(page)
     except PageNotAnInteger:
         tweets = paginator.page(1)
     except EmptyPage:
         tweets = paginator.page(paginator.num_pages)
     params['tweets'] = tweets
     params['profile'] = user_profile
     params['form'] = form
     params['stat'] = {
         'tweets':
         len(all_tweets),
         'following':
         len(User.objects.get(userfollower=user_follower).followers.all()),
         'followers':
         UserFollower.objects.values_list('count').filter(
             user=user_profile).get()[0],
     }
     return render(request, 'profile.html', params)
コード例 #28
0
ファイル: views.py プロジェクト: yerm87/MyTweeter
def create_tweet(request):
    form = TweetForm()
    if request.method == 'POST':
        if not request.user.is_authenticated:
            if request.is_ajax():
                return JsonResponse({}, status=401)
            return redirect(settings.LOGIN_URL)
        form = TweetForm(request.POST)
        if form.is_valid():
            nextUrl = request.POST['next']
            tweet = form.save(commit=False)
            tweet.user = request.user
            tweet.save()
            if request.is_ajax():
                return JsonResponse(tweet.serialize(), status=201)
            return redirect(nextUrl)
        else:
            return JsonResponse(form.errors, status=400)
    return render(request, 'tweets/components/form.html', {'form': form})
コード例 #29
0
ファイル: views.py プロジェクト: Ghaiyur/techtweet-IS
def profile(request, username):
    if request.user.is_authenticated:
        user = User.objects.get(username=username)

        if request.method == 'POST':
            form = TweetForm(request.POST, request.FILES)

            if form.is_valid():
                tweet = form.save(commit=False)
                tweet.user = request.user
                tweet.save()

                redirecturl = request.POST.get('redirect', '/')

                return redirect(redirecturl)
        else:
            form = TweetForm()

        return render(request, 'profile.html', {'form': form, 'user': user})

    else:
        return redirect('/')
コード例 #30
0
ファイル: views.py プロジェクト: mah-qurashy/tweetme
def home_view(request, *args, **kwargs):
    form = TweetForm()
    return render(request, "pages/home.html", context={"form": form}, status=200)
コード例 #31
0
def timeline(request):
    # pdb.set_trace()
    #print request.GET['status'] # for GET form method
    #print request.POST['status'] # for POST form method
    #debug
    try:
        if request.user['is_authenticated']:
            status_opcode = 101
            print request.POST['status']  # for POST form method
            print request.POST['user_id']  # for POST form method
            print request.POST['activibe']  # for POST form method
            user_status = request.POST['status']  # for POST form method
            user_id = request.POST['user_id']  # for POST form method
            user_domain = request.POST['activibe']  # for POST form method
            if user_domain == 101:
                cass.save_user_status(user_status, user_id, user_domain)
                #start = request.GET.get('start')
                start = 1
                status, next = cass.get_user_status(user_id)
                context = {
                    'status': status,
                    'next': next,
                }
                return render_to_response(
                    'tweets/timeline.html',
                    context,
                    context_instance=RequestContext(request))
        #       return HttpResponseRedirect(reverse('timeline'))
        else:
            print "Invalid Request"
    except:
        print "Unexpected error:"


#debug

    form = TweetForm(request.POST or None)
    if request.user['is_authenticated'] and form.is_valid():
        tweet_id = str(uuid.uuid1())
        cass.save_tweet(
            tweet_id, request.session['username'], {
                'username': request.session['username'],
                'body': form.cleaned_data['body'],
            })
        return HttpResponseRedirect(reverse('timeline'))
    start = request.GET.get('start')
    if request.user['is_authenticated']:
        tweets, next = cass.get_timeline(request.session['username'],
                                         start=start,
                                         limit=NUM_PER_PAGE)
        #tweets,next = cass.get_friends(request.session['username'],
        #    limit=NUM_PER_PAGE)
    else:
        tweets, next = cass.get_userline(cass.PUBLIC_USERLINE_KEY,
                                         start=start,
                                         limit=NUM_PER_PAGE)
    context = {
        'form': form,
        'tweets': tweets,
        'next': next,
    }
    return render_to_response('tweets/timeline.html',
                              context,
                              context_instance=RequestContext(request))