Beispiel #1
0
def crea_tweet(request):
    if (request.method == 'GET'):
        context_form = TweetForm()
        return render(request, "crea.html", {"form": context_form.as_p()})

    if (request.method == 'POST'):
        tweet = TweetForm(request.POST)
        tweet.is_valid()
        data = tweet.cleaned_data
        db_istance = Tweet(text=data['text'], title=data['title'], user=request.user)
        db_istance.save()
        return redirect("home", utente=request.user)
Beispiel #2
0
def tweet(request):

    if request.method == 'POST':
        form = TweetForm(request.POST)
        if form.is_valid():
            twit = Tweet()
            status = twit.tweet = form.cleaned_data['tweet']
            twit.name = request.user.username
            twit.save()
            variables = RequestContext(request,{
                'status':status
            })
            return render_to_response('tweet.html',RequestContext(request),variables)
        else:
            return render_to_response('tweet.html',{'request':RequestContext(request)})

    else:
        tweets = []
        queryset=Tweet.objects.all()
        for query in queryset:
            if request.user.username == query.name:
                tweets.append(query)
        status = ''
        for tweet in tweets:
            status = tweet.tweet

        form = TweetForm()
        form.name = request.user
        variables = RequestContext(request, {
                'form': form,'status': status
            })

        return render_to_response('tweet.html',RequestContext(request),variables)
Beispiel #3
0
def tweet(request):

    if request.method == 'POST':
        form = TweetForm(request.POST)
        if form.is_valid():
            twit = Tweet()
            status = twit.tweet = form.cleaned_data['tweet']
            twit.name = request.user.username
            twit.save()
            variables = RequestContext(request, {'status': status})
            return render_to_response('tweet.html', RequestContext(request),
                                      variables)
        else:
            return render_to_response('tweet.html',
                                      {'request': RequestContext(request)})

    else:
        tweets = []
        queryset = Tweet.objects.all()
        for query in queryset:
            if request.user.username == query.name:
                tweets.append(query)
        status = ''
        for tweet in tweets:
            status = tweet.tweet

        form = TweetForm()
        form.name = request.user
        variables = RequestContext(request, {'form': form, 'status': status})

        return render_to_response('tweet.html', RequestContext(request),
                                  variables)
def post_tweet(request):
    c = {}
    if request.method == 'POST':
        form = TweetForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            first_name = cd['first_name']
            last_name = cd['last_name']
            tweet = cd['tweet']
            current_authors = Author.objects.filter(
                first_name=first_name).filter(last_name=last_name)
            if (len(current_authors) == 1):
                author = current_authors[0]
            else:
                author = Author.create(first_name=first_name,
                                       last_name=last_name)
                author.save()
            tweet = Tweet.create(tweet=tweet, author=author)
            tweet.save()
            form = TweetForm()
    else:
        form = TweetForm()
    c['form'] = form
    tweets = Tweet.objects.all()
    c['tweets'] = tweets
    return render_to_response('tweets.html', c)
Beispiel #5
0
def submit(request):
    if request.method == 'GET':
        form = TweetForm({'owner': request.user}, auto_id=True)
    else:
        form = TweetForm(request.POST.copy(), auto_id=True)
        if form.is_valid():
            if form.is_shameful():
                form.instance.blocked = True
            else:
                api = twitter.Api(consumer_key=settings.TW_C_KEY,
                    consumer_secret=settings.TW_C_SECRET, 
                    access_token_key=settings.TW_AT_KEY, 
                    access_token_secret=settings.TW_AT_SECRET)
                    
                api.PostUpdate(form.instance.content)
                
                form.instance.published = True
            
            form.instance.pub_date = datetime.now()
            form.instance.save()

            return HttpResponseRedirect(reverse('home') + '?shame=' + str(form.is_shameful()).lower())
        
    tpl_data = {
        'form': form
    }
    
    return render_to_response('tweet_brander/submit.html', tpl_data,
        context_instance=RequestContext(request))
Beispiel #6
0
 def post(self, request, *args, **kwargs):
     tf = TweetForm(data=request.POST)
     if tf.is_valid():
         tf_obj = tf.save(commit=False)
         tf_obj.tweeted_by = request.user
         tf_obj = parse_category_and_tweet(tf_obj)
         tf_obj.save()
         return HttpResponseRedirect("/")
     else:
         return render_to_response("tweet.html",
                               {"tweet_form": tf},
                               context_instance=RequestContext(request))
Beispiel #7
0
	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 = "Vietname" )#form.cleaned_data['country'])
			tweet.save()
			words = form.cleaned_data['text'].split(" ")
			for word in words:
				hashtag, created = HashTag.objects.get_or_create(name = word[1:])
				hashtag.tweet.add(tweet)
			return HttpResponseRedirect('/tweets/user/%s' % username)
		return redirect(Profile.as_view())
Beispiel #8
0
 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)
Beispiel #9
0
def homepage(request):
    """Renders homepage, with public timeline"""
    if request.method == 'POST': # If the form has been submitted...
        form = TweetForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            # Process the data in form.cleaned_data
            t=Tweet(text=form.cleaned_data['text'], owner=request.user)
            t.save()
            return HttpResponseRedirect('/') # Redirect after POST
    else:
        form = TweetForm() # An unbound form
    return render_to_response(request, 'homepage.html', {
        'form': form,
    })
Beispiel #10
0
def index(request):
    if request.method == "POST":
        form = TweetForm(request.POST)
        if form.is_valid():
            uid = request.session['uid']
            Tweet.create_post(text=form.cleaned_data["text"], uid=uid)
            return HttpResponseRedirect(reverse("twitter_home"))
    else:
        form = TweetForm()
    context = {
        'username': request.session['username'],
        'tweet_form': form,
        'timeline': Tweet.get_timeline(request.session['uid']),
    }
    return render(request, "twitter/index.html", context)
Beispiel #11
0
def tweet_submit(request):
    if request.method == "POST":
        tweets = Tweet.objects.filter(author=request.user.followed_by.all).order_by('-id')[:10]
        tweet_form = TweetForm(data=request.POST)
        if tweet_form.is_valid():
            tweet = tweet_form.save(commit=False)
            tweet.author = request.user
            tweet.save()
            return redirect('/')
        else:
            return render(request,
                      'public.html',
                      {'tweet_form': tweet_form,
                       'tweets': tweets})
    return redirect('/')   
Beispiel #12
0
def index(request):
    if request.method == "POST":
        form = TweetForm(request.POST)
        if form.is_valid():
            uid = request.session['uid']
            Tweet.create_post(text=form.cleaned_data["text"], uid=uid)
            return HttpResponseRedirect(reverse("twitter_home"))
    else:
        form = TweetForm()
    context = {
        'username': request.session['username'],
        'tweet_form': form,
        'timeline': Tweet.get_timeline(request.session['uid']),
    }
    return render(request, "twitter/index.html", context)
Beispiel #13
0
def add_tweet(request):

    if request.method == "POST":
        form = TweetForm(request.POST)
        if form.is_valid():
            tweet = form.save(commit=False)
            tweet.posted_by = request.user
            tweet.save()
            url = reverse("tweets-user_tweets", args=[request.user])
            return redirect(url)
    else:
        form = TweetForm()

    template_data = {
        "form": form,
    }
    template = "tweets/add_tweet.html"
    ctx = RequestContext(request)

    return render_to_response(template, template_data, context_instance=ctx)
def add_tweet(request):

    if request.method == "POST":
        form = TweetForm(request.POST)
        if form.is_valid():
            tweet = form.save(commit=False)
            tweet.posted_by = request.user
            tweet.save()
            url = reverse("tweets-user_tweets", args=[request.user])
            return redirect(url)
    else:
        form = TweetForm()
    
    template_data = {
        "form": form,
    }
    template = "tweets/add_tweet.html"
    ctx = RequestContext(request)

    return render_to_response(
        template, 
        template_data, 
        context_instance=ctx
    )
Beispiel #15
0
def post_tweet(request):
	c = {}
	if request.method == 'POST':
		form = TweetForm(request.POST)
		if form.is_valid():
			cd = form.cleaned_data
			first_name = cd['first_name']
			last_name = cd['last_name']
			tweet = cd['tweet']
			current_authors = Author.objects.filter(first_name=first_name).filter(last_name=last_name)
			if (len(current_authors) == 1):
				author = current_authors[0]
			else:
				author = Author.create(first=first_name, last=last_name)
				author.save()
			tweet = Tweet.create(tweet=tweet, author=author)
			tweet.save()
			form = TweetForm()
	else:
		form = TweetForm()
	c['form'] = form
	tweets = Tweet.objects.all()
	c['tweets'] = tweets
	return render_to_response('twitter.html', c)