Ejemplo n.º 1
0
def create_sms_sender(request):
    message = Message.objects.get(pk=request.POST['id'])
    imageform = local_forms.UploadImageForm(request.POST, request.FILES)
    if imageform.is_valid():
        if message.phone_number == "+1" + request.POST[
                'areacode'] + request.POST['first'] + request.POST['second']:
            photo = request.FILES.get('photo')
            sender = MessageSender()
            sender.phone_number = message.phone_number
            sender.name = imageform.cleaned_data['name']
            if photo:
                photoname = photo.name.split('.')[0]
                resizedphoto = _handle_uploaded_photo(photo)
                sender.image.save(photoname + '.png', resizedphoto)
            sender.save()

            message.sender = sender
            message.save()

            if imageform.cleaned_data['claimall']:
                for othermessage in Message.objects.get(
                        phone_number=message.phone_number):
                    othermessage.sender = sender
                    othermessage.save()
    print imageform.errors
    return HttpResponseRedirect(
        reverse('main.views.display_messages',
                args=[
                    Message.objects.get(
                        pk=request.POST['id']).wall.hashtag.strip("#")
                ]))
Ejemplo n.º 2
0
def twitter_oauth(request, id=None):
    auth = tweepy.OAuthHandler(settings.TWITTER_CONSUMER_KEY,
                               settings.TWITTER_CONSUMER_SECRET)
    if 'request_token' in request.session:
        token = request.session['request_token']
        del request.session['request_token']
        auth.set_request_token(token[0], token[1])
        verifier = request.GET['oauth_verifier']
        auth.get_access_token(verifier)

        api = tweepy.API(auth)
        user = api.me()

        sender = MessageSender()
        sender.name = user.name
        sender.twitter_username = user.screen_name
        sender.image_url = user.profile_image_url
        sender.save()

        wall = Wall.objects.get(pk=request.session['wall_id'])
        message = Message.objects.get(pk=request.session['message_id'])
        message.sender = sender
        message.wall = wall
        message.save()

        if request.session['claimall']:
            for message in wall.message_set.filter(
                    twitter_account=sender.twitter_username):
                message.sender = sender
                message.wall = wall
                message.save()

        if 'message_page' in request.session:
            return HttpResponseRedirect(request.session['message_page'])
        return HttpResponseRedirect(reverse('main.views.index'))
    auth_url = auth.get_authorization_url()
    request.session['request_token'] = (auth.request_token.key,
                                        auth.request_token.secret)
    request.session['wall_id'] = id
    request.session['claimall'] = json.loads(request.GET.get('claimall'))
    request.session['message_id'] = request.GET.get('message')
    request.session.modified = True
    return HttpResponseRedirect(auth_url)