def get_context_data(self, **kwargs): common = CommonView(self, **kwargs) context = super(IndexView, self).get_context_data(**kwargs) context['common'] = common.infos context['titre'] = _('Home') current = common.infos['personne'] # À partir de là on a les id -> ressortir les personnes avec ces ids. # Pagination des résultats contacts = [ {'form': MessageSendForm(obj_bd=p, champ='id_personne'), 'contact': p, } for p in current.relations_of_type(PersonneEnums.RELATION_AMI)] paginator = HQFPaginator(contacts, 6) try: page = int(self.request.GET.get('page', 1)) except ValueError: page = 1 try: paginator.set_around(page, 3) contacts = paginator.page(page) except PageNotAnInteger: # Si page n'est pas un entier, renvoyer la page 1. contacts = paginator.page(1) except EmptyPage: # Si page hors limites (ex. 9999) renvoyer la dernière page. contacts = paginator.page(paginator.num_pages) context['contacts'] = contacts if self.request.session.get('message', None): context['message'] = self.request.session['message'] del self.request.session['message'] return context
def get_context_data(self, **kwargs): # 'contact_id' = param de l'URL => dans kwargs => faire suivre kwargs : common = CommonView(self, **kwargs) context = super(ContactDetailView, self).get_context_data(**kwargs) context['common'] = common.infos try: contact = Personne.objects.get(pk=kwargs['contact_id']) except Personne.DoesNotExist: # pas d'index 'contact' crée -> gestion plus tard via get() return context context['contact'] = contact # pagination for contacts contact_contacts = contact.contacts # Pagination paginator = HQFPaginator(contact_contacts, 6) try: page = int(self.request.GET.get('page', 1)) except ValueError: page = 1 try: paginator.set_around(page, 3) contact_contacts = paginator.page(page) except PageNotAnInteger: # Si page n'est pas un entier, renvoyer la page 1. contact_contacts = paginator.page(1) except EmptyPage: # Si page est hors limites, (ex. 9999), renvoyer la dernière page. contact_contacts = paginator.page(paginator.num_pages) context['contact_contacts'] = contact_contacts context['form_send_message'] = MessageSendForm(obj_bd=contact, champ='id_personne') p = common.infos['personne'] convs = Conversation.between(p, contact) if len(convs): # get() = pour avoir un objet (!= QuerySet) # normalement qu'une seule conversation avec des messages : c = Conversation.objects.get(pk=convs[0]) context['conversation'] = c context['conversation_form'] = MessageSendForm( obj_bd=c, champ='id_conversation') if self.request.session.get('message', None): context['message'] = self.request.session['message'] del self.request.session['message'] return context
def get_context_data(self, **kwargs): common = CommonView(self, **kwargs) context = super(NotificationsView, self).get_context_data(**kwargs) context['common'] = common.infos # Pagination : écraser les likes likes = context['common']['notifications']['likes'] paginator = HQFPaginator(likes, 5) try: page = int(self.request.GET.get('p_like', 1)) except ValueError: page = 1 try: paginator.set_around(page, 3) likes = paginator.page(page) except PageNotAnInteger: # Si page n'est pas un entier, renvoyer la page 1. likes = paginator.page(1) except EmptyPage: # Si page est hors limites, (ex. 9999), renvoyer la dernière page. likes = paginator.page(paginator.num_pages) context['common']['notifications']['likes'] = likes context['titre'] = _(u'Notifications') p = common.infos['personne'] convs_non_lues = Conversation.objects.filter( Q(messages__dst=p, messages__is_read=False, messages__date_v_fin__isnull=True)).distinct() context['conversations'] = [{ 'form': MessageSendForm(obj_bd=c, champ='id_conversation'), 'conversation': c } for c in convs_non_lues] l = [] for m in Message.objects.filter(dst=p, dst_visible=True)\ .order_by('date_last_modif'): for c in m.conversations.all().exclude(pk__in=convs_non_lues): if c.pk not in l: l.append(c.pk) convs_lues = [Conversation.objects.get(pk=int(pk)) for pk in l] context['conversations_lues'] = [{ 'form': MessageSendForm(obj_bd=c, champ='id_conversation'), 'conversation': c } for c in convs_lues] # Pagination paginator = HQFPaginator(context['conversations_lues'], 8) try: page = int(self.request.GET.get('p_convs', 1)) except ValueError: page = 1 try: paginator.set_around(page, 3) context['conversations_lues'] = paginator.page(page) except PageNotAnInteger: # Si page n'est pas un entier, renvoyer la page 1. context['conversations_lues'] = paginator.page(1) except EmptyPage: # Si page est hors limites, (ex. 9999), renvoyer la dernière page. context['conversations_lues'] = paginator.page(paginator.num_pages) return context
def get_context_data(self, **kwargs): common = CommonView(self) context = super(IndexView, self).get_context_data(**kwargs) context['common'] = common.infos context['titre'] = _('Home') p = Personne.objects.get(user=self.request.user) context['activites'] = self.activites(p, common.infos['locale']) context['liked'] = [ liked.activite for liked in PersonneLiked.objects.filter( activite__in=context['activites'], liked__exact=True, src=p, date_v_fin__isnull=True) ] context['liked_person'] = [ liked_p.dst for liked_p in PersonneLiked.objects.filter( activite__isnull=True, liked__exact=True, src=p, date_v_fin__isnull=True) ] context['activites'] = [{ 'objet': a, 'form': MessageSendForm(obj_bd=a, champ='id_activite'), 'form_comment': CommentSendForm(obj_bd=a, champ='id_comment_activite'), 'comments': ActiviteComments.objects.filter(activite_dst=a) } for a in context['activites']] context['express_yourself'] = ExpressYourselfForm() # Pagination paginator = HQFPaginator(context['activites'], 8) try: page = int(self.request.GET.get('page', 1)) except ValueError: page = 1 try: paginator.set_around(page, 3) context['activites'] = paginator.page(page) except PageNotAnInteger: # If not integer, back to page 1. context['activites'] = paginator.page(1) except EmptyPage: # If out of bound (ex. 9999), send latest page context['activites'] = paginator.page(paginator.num_pages) # Message (if there's one) if self.request.session.get('message', None): context['message'] = self.request.session['message'] del self.request.session['message'] # Publicités context['publicites_gauche'] = \ self.publicites(Publicite.PUBLICITE_FIL_ACTUALITE_GAUCHE) context['publicites_droite'] = \ self.publicites(Publicite.PUBLICITE_FIL_ACTUALITE_DROITE) # Travels if self.request.session.get('warn_no_travels', None) is None: self.request.session['warn_no_travels'] = True if PersonneTravel.objects.filter( personne=p, date_v_fin__isnull=True).count() == 0: self.request.session['warn_no_travels'] = True context['warn_no_travels'] = True # Progression if self.request.session.get('progression', None) is None: self.request.session['progression'] = False if not self.request.session['progression']: self.request.session['progression'] = True context['progression'] = self.progression(self.request.user, p) return context