示例#1
0
    def render(self, context, instance, placeholder):
        representatives = Representative.parliament.all()
        context['representatives'] = Representative.by_lastname_lastname_first(
            representatives=representatives)
        context['random'] = RandomRepresentative.get()

        try:
            # temporary:
            #latest = Question.public.order_by('-date')[0]
            latest = Question.answered.order_by('-date')[0]
        except IndexError:
            latest = None
        context['latest'] = latest
        # temporary:
        #return context

        if not latest:
            context['most_active'] = None
            context['least_active'] = None
            return context

        try:
            representative = representatives.order_by('-answered')[0]
            context['most_active'] = self._add_activity(representative)
        except IndexError:
            context['most_active'] = None

        try:
            representative = representatives.order_by('answered')[0]
            context['least_active'] = self._add_activity(representative)
        except IndexError:
            context['least_active'] = None

        return context
示例#2
0
    def __init__ (self, **kwargs):
        if not 'initial' in kwargs and 'session' in kwargs:
            try:
                s = kwargs.pop('session')['form_question']
            except KeyError:
                pass
            else:
                initial = {}
                for item in ['representative', 'first_name', 'last_name',
                    'email', 'mobile']:
                    try:
                        initial[item] = s[item]
                    except KeyError:
                        pass
                if initial:
                    kwargs['initial'] = initial

        super(QuestionForm, self).__init__(**kwargs)

        # bug in Django? shows georgian in english site otherwise...
        self.fields['first_name'].label = _('First Name')
        self.fields['last_name'].label = _('Last Name')
        self.fields['mobile'].label = _('Mobile Phone Number')
        self.fields['question'].label = _('Question')
        self.fields['representative'].label = _('Representative')

        representatives = Representative.parliament.all()
        self.fields['representative'].choices =\
            Representative.by_lastname_lastname_first(
                representatives=representatives, choices=True)
示例#3
0
    def render(self, context, instance, placeholder):
        representatives = Representative.parliament.all()
        context['representatives'] = Representative.by_lastname_lastname_first(
            representatives=representatives)
        context['random'] = RandomRepresentative.get()

        try:
            # temporary:
            #latest = Question.public.order_by('-date')[0]
            latest = Question.answered.order_by('-date')[0]
        except IndexError:
            latest = None
        context['latest'] = latest
        # temporary:
        #return context

        if not latest:
            context['most_active'] = None
            context['least_active'] = None
            return context

        try:
            representative = representatives.order_by('-answered')[0]
            context['most_active'] = self._add_activity(representative)
        except IndexError:
            context['most_active'] = None

        try:
            representative = representatives.order_by('answered')[0]
            context['least_active'] = self._add_activity(representative)
        except IndexError:
            context['least_active'] = None

        return context
示例#4
0
    def __init__(self, **kwargs):
        if not 'initial' in kwargs and 'session' in kwargs:
            try:
                s = kwargs.pop('session')['form_question']
            except KeyError:
                pass
            else:
                initial = {}
                for item in [
                        'representative', 'first_name', 'last_name', 'email',
                        'mobile'
                ]:
                    try:
                        initial[item] = s[item]
                    except KeyError:
                        pass
                if initial:
                    kwargs['initial'] = initial

        super(QuestionForm, self).__init__(**kwargs)

        # bug in Django? shows georgian in english site otherwise...
        self.fields['first_name'].label = _('First Name')
        self.fields['last_name'].label = _('Last Name')
        self.fields['mobile'].label = _('Mobile Phone Number')
        self.fields['question'].label = _('Question')
        self.fields['representative'].label = _('Representative')

        representatives = Representative.parliament.all()
        self.fields['representative'].choices =\
            Representative.by_lastname_lastname_first(
                representatives=representatives, choices=True)