def post(self, request, *args, **kwargs):
        ctx = self.get_context_data(**kwargs)
        form = PostQueueForm(request.POST or None)
        ctx['form'] = form

        # if twitter account exists, connect to Twitter
        api = connect_to_tweepy(request.user.id, self.kwargs['biz_id'])

        if form.is_valid():
            # add the missing values for created_by and created_on since
            # modelForms seem to have trouble automaticlly inheriting them
            the_post = form.save(commit=False)
            the_post.created_by = request.user
            the_post.created_on = datetime.now() 
            the_post.biz_id     = self.kwargs['biz_id'] # TODO: remove this 
            the_post.save()

            # see signals.py for adding this saved post to
            # the Celery queue via the post_save signal
            
            messages.info(request, 'Your post has been scheduled')
            return HttpResponseRedirect(reverse('likeriser_view', 
                                    args=(self.kwargs['biz_id'],)))

        messages.error(request, 'Your form did not validate')
        return self.render_to_response(ctx)
 def post_to_twitter(self, request, biz_id, msg):
     ''' Posts to Twitter wall
     TODO
     if connection to twitter fails, set a flag for the post
     that lets the user know the details of why it failed.
     '''
     api = connect_to_tweepy(request.user.id, biz_id)
     update = api.update_status(msg)
     return update.text
 def get(self, request, *args, **kwargs):
     # request.session['next'] = request.META['HTTP_REFERER']
     api = connect_to_tweepy(request.user.id, self.kwargs['biz_id'])
     ctx = { 'me': api.me() }
     return self.render_to_response(ctx)