def get(self, request, *args, **kwargs): ctx = self.get_context_data(**kwargs) ctx['form'] = PostQueueForm(initial={'status': 'active', 'social_sites': [u'facebook']}) ctx['biz_list'] = fever_utils.get_user_businesses(request.user) user_biz_ids = [x.id for x in ctx['biz_list'] if ctx['biz_list']] # get all posts that are scheduled for future deployment upcoming_posts = PostQueue.objects.filter(biz_id__in=user_biz_ids ).exclude(post_date__lt=datetime.datetime.utcnow().replace(tzinfo=utc) ).exclude(status__exact='draft').order_by('post_date') # create a list of of your post forms form_list = [] for post in upcoming_posts: form = PostQueueForm(instance=post) #form.fields['social_sites'].initial = post.social_sites form.fields['social_sites'].initial = u'Facebook' form_list.append(form) ctx['upcoming_posts'] = form_list # get all saved drafts ctx['drafts'] = [PostQueueForm(instance=draft) for draft in \ PostQueue.objects.filter( biz_id__in=user_biz_ids, status__exact='draft')] # get all posts that have already been sent ctx['past_posts'] = PostQueue.objects.filter( biz_id=self.kwargs['biz_id']).exclude( post_date__gt=datetime.datetime.now()).order_by('-post_date') # check if connected to facebook and if not then display # a link to the accounts page to connect to it accounts = UserSocialAuth.objects.filter(user_id=request.user.id) if accounts: for account in accounts: if account.provider == 'facebook': ctx['facebook_disconnect_id'] = account.id elif account.provider == 'twitter': ctx['twitter_disconnect_id'] = account.id return self.render_to_response(ctx)
def get(self, request, *args, **kwargs): ctx = {} ctx['form'] = PostQueueForm(initial={ 'status': 'active', 'social_sites': [u'facebook']} ) ctx['biz_list'] = get_user_businesses(request.user) # get all posts that are scheduled for future deployment upcoming_posts = PostQueue.objects.filter( biz_id=self.kwargs['biz_id']).exclude( post_date__lt=datetime.now()).order_by('post_date') # get all posts that have already been sent past_posts = PostQueue.objects.filter( biz_id=self.kwargs['biz_id']).exclude( post_date__gt=datetime.now()).order_by('-post_date') # make a formset out of the upcoming posts PostFormSet = modelformset_factory(PostQueue, form=PostQueueForm, extra=0) UpcomingFormSet = PostFormSet(queryset=upcoming_posts) ctx['upcoming_formset'] = UpcomingFormSet ctx['upcoming_posts'] = upcoming_posts ctx['past_posts'] = past_posts # check if connected to facebook. If not, then display # a link to the accounts page to connect to it accounts = UserSocialAuth.objects.filter(user_id=request.user.id) if accounts: for account in accounts: if account.provider == 'facebook': ctx['facebook_disconnect_id'] = account.id elif account.provider == 'twitter': ctx['twitter_disconnect_id'] = account.id return self.render_to_response(ctx)