Exemple #1
0
    def get_context_data (self, **kwargs):
        context = super(Detail, self).get_context_data(**kwargs)
        obj = context['obj']
        context['url_feed'] = reverse('draftlaw_feed_detail', args=[obj.pk])

        set_language_changer(self.request, obj.get_absolute_url)
        return context
Exemple #2
0
    def get(self, request, *args, **kwargs):
        try:
            category = self.get_category()
        except FallbackLanguageResolved as flr:
            # We have the category, but it is in a fallback language.
            category = flr.object

        # only look at questions within this category
        queryset = self.get_queryset().filter(category=category.pk)
        question = self.get_object(queryset=queryset)
        set_language_changer(request, question.get_absolute_url)

        if hasattr(request, 'toolbar'):
            request.toolbar.set_object(question)

        setattr(request, request_faq_category_identifier, question.category)
        setattr(request, request_faq_question_identifier, question)
        response = super(FaqAnswerView, self).get(request, *args, **kwargs)

        # FIXME: We should check for unique visitors using sessions.
        # update number of visits
        question_only_queryset = self.get_queryset().filter(pk=question.pk)
        question_only_queryset.update(
            number_of_visits=models.F('number_of_visits') + 1)
        return response
Exemple #3
0
    def get(self, request, *args, **kwargs):
        """
        This handles non-permalinked URLs according to preferences as set in
        NewsBlogConfig.
        """
        if not hasattr(self, 'object'):
            self.object = self.get_object()
        user = self.request.user
        user_can_edit = user.is_staff or user.is_superuser
        if not (self.edit_mode or user_can_edit):
            if not self.object.published_for_language(self.get_language()):
                raise Http404('Object not found.')
        set_language_changer(request, self.object.get_public_url)
        url = self.object.get_absolute_url()
        if (self.config.non_permalink_handling == 200 or request.path == url):
            # Continue as normal
            #return super(ArticleDetail, self).get(request, *args, **kwargs)
            context = self.get_context_data(object=self.object)
            return self.render_to_response(context)

        # Check to see if the URL path matches the correct absolute_url of
        # the found object
        if self.config.non_permalink_handling == 302:
            return HttpResponseRedirect(url)
        elif self.config.non_permalink_handling == 301:
            return HttpResponsePermanentRedirect(url)
        else:
            raise Http404('This is not the canonical uri of this object.')
Exemple #4
0
def blog_archive_day(request, **kwargs):
    blog_slug = kwargs.pop('blog_slug')
    kwargs['queryset'] = kwargs['queryset'].published().filter(
        blog__slug=blog_slug)
    set_language_changer(request, language_changer)
    return archive_day(request, extra_context={ 'blog_slug': blog_slug },
                       **kwargs)
Exemple #5
0
    def get(self, request, *args, **kwargs):
        try:
            category = self.get_category()
        except FallbackLanguageResolved as flr:
            # We have the category, but it is in a fallback language.
            category = flr.object

        # only look at questions within this category
        queryset = self.get_queryset().filter(category=category.pk)
        question = self.get_object(queryset=queryset)
        set_language_changer(request, question.get_absolute_url)

        if hasattr(request, 'toolbar'):
            request.toolbar.set_object(question)

        setattr(request, request_faq_category_identifier, question.category)
        setattr(request, request_faq_question_identifier, question)
        response = super(FaqAnswerView, self).get(request, *args, **kwargs)

        # FIXME: We should check for unique visitors using sessions.
        # update number of visits
        question_only_queryset = self.get_queryset().filter(pk=question.pk)
        question_only_queryset.update(
            number_of_visits=models.F('number_of_visits') + 1)
        return response
Exemple #6
0
def blog_archive_tagged(request, **kwargs):
    blog_slug = kwargs.pop('blog_slug')
    kwargs['queryset_or_model'] = (kwargs['queryset_or_model'].published()
                                   .filter(blog__slug=blog_slug))
    set_language_changer(request, language_changer)
    return tagged_object_list(request, extra_context={ 'blog_slug': blog_slug },
                              **kwargs)
Exemple #7
0
def blog_archive_tagged(request, **kwargs):
    blog_slug = kwargs.pop('blog_slug')
    kwargs['queryset_or_model'] = (
        kwargs['queryset_or_model'].published().filter(blog__slug=blog_slug))
    set_language_changer(request, language_changer)
    return tagged_object_list(request,
                              extra_context={'blog_slug': blog_slug},
                              **kwargs)
Exemple #8
0
def blog_archive_day(request, **kwargs):
    blog_slug = kwargs.pop('blog_slug')
    kwargs['queryset'] = kwargs['queryset'].published().filter(
        blog__slug=blog_slug)
    set_language_changer(request, language_changer)
    return archive_day(request,
                       extra_context={'blog_slug': blog_slug},
                       **kwargs)
Exemple #9
0
    def get(self, request, *args, **kwargs):
        category = self.get_category()
        self.category = category

        setattr(request, request_faq_category_identifier, self.category)
        set_language_changer(request, self.category.get_absolute_url)
        response = super(FaqByCategoryView, self).get(request, *args, **kwargs)
        return response
Exemple #10
0
    def get_context_data(self, **kwargs):
        context = super(Detail, self).get_context_data(**kwargs)

        context['form'] = _get_form(self, context['obj'].representative)
        context['url_feed'] = reverse('question_feed_list')
        set_language_changer(self.request, context['obj'].get_absolute_url)

        return context
Exemple #11
0
 def get(self, request, *args, **kwargs):
     response = super(PostDetailView, self).get(request, *args, **kwargs)
     post = response.context_data.get('post', None)
     if post:
         setattr(request, request_post_identifier, post)
         if post.language:
             set_language_changer(request, post_language_changer)
     return response
Exemple #12
0
    def get_context_data (self, **kwargs):
        context = super(Detail, self).get_context_data(**kwargs)

        context['form'] = _get_form(self, context['obj'].representative)
        context['url_feed'] = reverse('question_feed_list')
        set_language_changer(self.request, context['obj'].get_absolute_url)

        return context
Exemple #13
0
def blog_archive_author(request, **kwargs):
    author = kwargs.pop('author')
    kwargs['queryset'] = kwargs['queryset'].published().filter(entrytitle__author__username=author)
    kwargs['extra_context'] = {
        'author': get_object_or_404(User, username=author),
    }
    set_language_changer(request, language_changer)
    return object_list(request, **kwargs)
Exemple #14
0
    def get(self, request, *args, **kwargs):
        category = self.get_category()
        self.category = category

        setattr(request, request_faq_category_identifier, self.category)
        set_language_changer(request, self.category.get_absolute_url)
        response = super(FaqByCategoryView, self).get(request, *args, **kwargs)
        return response
Exemple #15
0
def blog_archive_author(request, **kwargs):
    author = kwargs.pop('author')
    kwargs['queryset'] = kwargs['queryset'].published().filter(
        entrytitle__author__username=author)
    kwargs['extra_context'] = {
        'author': author,
    }
    set_language_changer(request, language_changer)
    return object_list(request, **kwargs)
    def get_object(self, queryset=None):
        instance = super().get_object(queryset=queryset)

        # Translate the slug while changing the language:
        set_language_changer(self.request, instance.get_absolute_url)

        self.extend_toolbar(publisher_instance=instance)

        return instance
Exemple #17
0
    def get_context_data(self, **kwargs):
        context = super(Detail, self).get_context_data(**kwargs)
        obj = context['obj']
        if obj.representative:
            context['url_feed'] = reverse('representative_feed_detail', args=[obj.representative.pk])
        else:
            context['url_feed'] = reverse('representative_feed_list')

        set_language_changer(self.request, obj.get_absolute_url)
        return context
Exemple #18
0
    def get_context_data (self, **kwargs):
        context = super(Detail, self).get_context_data(**kwargs)
        draftlaw_url = 'https://matsne.gov.ge/index.php?geo=on&searchTarget=title&searchDocumentsFilter=all&courtDecisionsARGUMENT=&sortCombo=signingDate_asc&queryString=&option=com_ldmssearch&view=docSearchResults&searchType=advanced&limitstart=0&lang=ge&documentNumber='
        obj = context['obj']
        context['stages'] = DraftLawForList(obj,obj.bureau_date) 
        context['url_feed'] = reverse('draftlaw_feed_detail', args=[obj.pk])
        context['draftlaw_url'] = draftlaw_url

        set_language_changer(self.request, obj.get_absolute_url)
        return context
Exemple #19
0
def blog_archive_author(request, **kwargs):
    blog_slug = kwargs.pop('blog_slug')
    author = kwargs.pop('author')
    kwargs['queryset'] = kwargs['queryset'].published().filter(
        blog__slug=blog_slug, entrytitle__author__username=author).distinct()
    kwargs['extra_context'] = {
        'author': author,
        'blog_slug': blog_slug,
    }
    set_language_changer(request, language_changer)
    return object_list(request, **kwargs)
Exemple #20
0
    def get_context_data(self, **kwargs):
        context = super(Detail, self).get_context_data(**kwargs)
        obj = context['obj']
        if obj.representative:
            context['url_feed'] = reverse('representative_feed_detail',
                                          args=[obj.representative.pk])
        else:
            context['url_feed'] = reverse('representative_feed_list')

        set_language_changer(self.request, obj.get_absolute_url)
        return context
Exemple #21
0
def blog_archive_author(request, **kwargs):
    blog_slug = kwargs.pop('blog_slug')
    author = kwargs.pop('author')
    kwargs['queryset'] = kwargs['queryset'].published().filter(
        blog__slug=blog_slug, entrytitle__author__username=author).distinct()
    kwargs['extra_context'] = {
        'author': author,
        'blog_slug': blog_slug,
    }
    set_language_changer(request, language_changer)
    return object_list(request, **kwargs)
Exemple #22
0
    def get_context_data (self, **kwargs):
        context = super(Detail, self).get_context_data(**kwargs)

        context['form'] = _get_form(self, context['obj'].representative)
        context['url_feed'] = reverse('question_feed_list')
        set_language_changer(self.request, context['obj'].get_absolute_url)

        question = context['obj']
        context["total_questions"] = Question.objects.filter(representative=question.representative_id, is_public='t').count()
        context["answered_questions"] = Question.objects.filter(representative=question.representative_id, is_public='t').exclude(answer__isnull=True).exclude(answer__exact='').count()

        return context
Exemple #23
0
    def get_object(self, queryset=None):
        instance = super().get_object(queryset=queryset)

        # Translate the slug while changing the language:
        set_language_changer(self.request, instance.get_absolute_url)

        # append publisher buttons:
        self.extend_toolbar(publisher_instance=instance)

        # Set django-meta stuff from LandingPageModel instance:
        self.set_meta(instance)

        return instance
Exemple #24
0
    def get_context_data (self, **kwargs):
        context = super(Detail, self).get_context_data(**kwargs)

        context['counts'] = VotingRecordResult.get_counts(record=context['obj'])

        order_by = VotingRecord._meta.ordering
        context['amended_by'] =\
            context['obj'].amended_by.all().order_by(*order_by)
        context['amending'] =\
            context['obj'].amending.all().order_by(*order_by)

        set_language_changer(self.request, context['obj'].get_absolute_url)
        return context
Exemple #25
0
    def get_context_data(self, **kwargs):
        context = super(Detail, self).get_context_data(**kwargs)

        context['form'] = _get_form(self, context['obj'].representative)
        context['url_feed'] = reverse('question_feed_list')
        set_language_changer(self.request, context['obj'].get_absolute_url)

        question = context['obj']
        context["total_questions"] = Question.objects.filter(
            representative=question.representative_id, is_public='t').count()
        context["answered_questions"] = Question.objects.filter(
            representative=question.representative_id, is_public='t').exclude(
                answer__isnull=True).exclude(answer__exact='').count()

        return context
Exemple #26
0
	def process_request(self, request):
		set_language_changer(request, _SimpleLanguageChanger(request))
		
		host = request.get_host().lower().strip()
		if 'localhost' in host or not host or host=='testserver' or settings.INSIDE_TESTING:
			return None

		if host[:3] in ('www','dev'):
			host = host[4:]
		if ':' in host:
			host = host[:host.find(':')]

		host_hash = md5(host+'iddqd').hexdigest()


		return None
Exemple #27
0
class LanguageFallbackEntryDateDetailView(EntryDateDetailView):
    """
    An EntryDateDetailView that falls back to the default language for 
    entries not in the current language without redirecting.
    """
    def get_object(self):
        try:
            obj = super(LanguageFallbackEntryDateDetailView, self).get_object()
        except Http404, e:
            # No entry has been found for a given language, we fallback to
            # search for an entry in any language.
            if is_multilingual():
                try:
                    queryset = self.get_unfiltered_queryset()
                    obj = super(LanguageFallbackEntryDateDetailView,
                                self).get_object(queryset=queryset)
                except (TypeError, Entry.MultipleObjectsReturned):
                    # Could find multiple entries, in this way we cannot decide
                    # which one is the right one, so we let exception be
                    # propagated.
                    raise e

                # Returning here without Redirect! This is the part that
                # differs from EntryDateDetailView.
                return obj
            else:
                raise e

        set_language_changer(self.request, obj.language_changer)
        return obj
Exemple #28
0
    def get_context_data(self, **kwargs):
        context = super(Detail, self).get_context_data(**kwargs)
        obj = context['obj']

        context['form'] = self._get_form(obj)
        context['questions'] = self._get_questions(obj)
        context['votecounts'] = VotingRecordResult.get_counts(representative=obj)
        context['url_feed'] = reverse('representative_feed_detail', args=[obj.pk])
        context['url_votingrecords'] = reverse(
            'representative_votingrecords', args=[obj.pk, obj.slug])
        try:
            context['decl'] = obj.incomedeclaration.all()[0]
        except IndexError:
            context['decl'] = None

        set_language_changer(self.request, obj.get_absolute_url)
        return context
Exemple #29
0
    def dispatch(self, request, *args, **kwargs):
        self.namespace, self.config = get_app_instance(request)
        language = get_language_from_request(request, check_path=True)
        self.queryset = (Event.objects.namespace(
            self.namespace).published().language(language).order_by(
                *ORDERING_FIELDS))
        self.event = self.queryset.active_translations(
            language, slug=kwargs['slug']).first()
        if not self.event:
            raise Http404("Event not found")

        set_language_changer(request, self.event.get_absolute_url)
        setattr(self.request, request_events_event_identifier, self.event)

        if hasattr(request, 'toolbar'):
            request.toolbar.set_object(self.event)

        return super(EventDetailView, self).dispatch(request, *args, **kwargs)
Exemple #30
0
    def get_context_data (self, **kwargs):
        context = super(Detail, self).get_context_data(**kwargs)


        context['counts1'] = VotingRecordResult.get_counts(record=context['obj'],session=1)
        context['votes1'] = VotingRecordResult.objects.filter(record=context['obj'], session=1)
	context['counts2'] = VotingRecordResult.get_counts(record=context['obj'],session=2)
        context['votes2'] = VotingRecordResult.objects.filter(record=context['obj'], session=2)
        context['counts3'] = VotingRecordResult.get_counts(record=context['obj'],session=3)
        context['votes3'] = VotingRecordResult.objects.filter(record=context['obj'], session=3)

        order_by = VotingRecord._meta.ordering
        context['amended_by'] =\
            context['obj'].amended_by.all().order_by(*order_by)
        context['amending'] =\
            context['obj'].amending.all().order_by(*order_by)

        set_language_changer(self.request, context['obj'].get_absolute_url)
        return context
Exemple #31
0
    def get(self, request, *args, **kwargs):
        if 'speaker_slug' in kwargs:
            speaker_slug = kwargs['speaker_slug']
            speaker = Speaker.objects.published().filter(slug=speaker_slug,
                                                         vcard_enabled=True)
            if speaker.count() != 1:
                raise Http404
            filename = "%s.vcf" % str(speaker_slug)
            vcard = speaker[0].get_vcard(request)
            try:
                vcard = vcard.decode('utf-8').encode('ISO-8859-1')
            except UnicodeError:
                pass
            response = HttpResponse(vcard, content_type="text/x-vCard")
            response[
                'Content-Disposition'] = 'attachment; filename="{0}"'.format(
                    filename)
            return response
        """
        This handles non-permalinked URLs according to preferences as set in
        EventsConfig.
        """
        if not hasattr(self, 'object'):
            self.object = self.get_object()
        set_language_changer(request, self.object.get_public_url)
        if self.object.redirect_url:
            return HttpResponseRedirect(self.object.redirect_url)

        url = self.object.get_absolute_url()
        if (self.config.non_permalink_handling == 200 or request.path == url):
            # Continue as normal
            #return super(EventDetail, self).get(request, *args, **kwargs)
            context = self.get_context_data(object=self.object)
            return self.render_to_response(context)

        # Check to see if the URL path matches the correct absolute_url of
        # the found object
        if self.config.non_permalink_handling == 302:
            return HttpResponseRedirect(url)
        elif self.config.non_permalink_handling == 301:
            return HttpResponsePermanentRedirect(url)
        else:
            raise Http404('This is not the canonical uri of this object.')
Exemple #32
0
    def get(self, request, *args, **kwargs):
        # triggers a redirect if the old category url format is used.
        category = self.get_category_or_404()
        category_url = category.get_absolute_url(self.current_language)

        if request.path != category_url:
            # say we have one category with two translations:
            # /en/faq/category-en/
            # /de/faq/category-de/
            # with this check we make sure that any request to
            # /en/faq/category-de/ gets redirected to /en/faq/category-en/
            return HttpResponsePermanentRedirect(category_url)

        self.category = category

        setattr(self.request, request_faq_category_identifier, self.category)
        set_language_changer(self.request, self.category.get_absolute_url)
        response = super(FaqByCategoryView, self).get(request, *args, **kwargs)
        return response
Exemple #33
0
    def get_object(self):
        try:
            obj = super(EntryDateDetailView, self).get_object()
        except Http404 as e:
            # No entry has been found for a given language, we fallback to search for an entry in any language
            # Could find multiple entries, in this way we cannot decide which one is the right one, so we let
            # exception be propagated FIXME later
            if is_multilingual():
                try:
                    queryset = self.get_unfiltered_queryset()
                    obj = super(EntryDateDetailView, self).get_object(queryset=queryset)
                except Entry.MultipleObjectsReturned as s:
                    raise e
                # We know there is only one title for this entry, so we can simply use get()
                raise Redirect(obj.entrytitle_set.get().get_absolute_url())
            else:
                raise e

        set_language_changer(self.request, obj.language_changer)
        return obj
Exemple #34
0
    def get(self, request, *args, **kwargs):
        """
        This handles non-permalinked URLs according to preferences as set in
        NewsBlogConfig.
        """
        if not hasattr(self, 'object'):
            self.object = self.get_object()
        set_language_changer(request, self.object.get_absolute_url)
        url = self.object.get_absolute_url()
        if (self.config.non_permalink_handling == 200 or request.path == url):
            # Continue as normal
            return super(ArticleDetail, self).get(request, *args, **kwargs)

        # Check to see if the URL path matches the correct absolute_url of
        # the found object
        if self.config.non_permalink_handling == 302:
            return HttpResponseRedirect(url)
        elif self.config.non_permalink_handling == 301:
            return HttpResponsePermanentRedirect(url)
        else:
            raise Http404('This is not the canonical uri of this object.')
Exemple #35
0
    def dispatch(self, request, *args, **kwargs):
        self.namespace, self.config = get_app_instance(request)
        self.request_language = get_language(request)
        self.queryset = (
            Event.objects.namespace(self.namespace)
                         .published()
                         .language(self.request_language)
                         .order_by(*ORDERING_FIELDS)
        )
        self.event = self.queryset.active_translations(
            self.request_language, slug=kwargs['slug']).first()
        if not self.event:
            raise Http404("Event not found")

        set_language_changer(request, self.event.get_absolute_url)
        setattr(self.request, request_events_event_identifier, self.event)

        if hasattr(request, 'toolbar'):
            request.toolbar.set_object(self.event)

        return super(EventDetailView, self).dispatch(request, *args, **kwargs)
Exemple #36
0
    def get(self, request, *args, **kwargs):
        """
        This handles non-permalinked URLs according to preferences as set in
        NewsBlogConfig.
        """
        if not hasattr(self, 'object'):
            self.object = self.get_object()
        set_language_changer(request, self.object.get_absolute_url)
        url = self.object.get_absolute_url()
        if (self.config.non_permalink_handling == 200 or request.path == url):
            # Continue as normal
            return super(ArticleDetail, self).get(request, *args, **kwargs)

        # Check to see if the URL path matches the correct absolute_url of
        # the found object
        if self.config.non_permalink_handling == 302:
            return HttpResponseRedirect(url)
        elif self.config.non_permalink_handling == 301:
            return HttpResponsePermanentRedirect(url)
        else:
            raise Http404('This is not the canonical uri of this object.')
Exemple #37
0
    def dispatch(self, request, *args, **kwargs):
        self.namespace, self.config = get_app_instance(request)
        self.request_language = get_language(request)
        qs = (Event.objects.namespace(self.namespace).published().language(
            self.request_language))
        site_id = getattr(get_current_site(request), 'id', None)
        valid_languages = get_valid_languages(self.namespace,
                                              self.request_language, site_id)
        self.queryset = qs.translated(*valid_languages).order_by(
            *ORDERING_FIELDS)
        self.event = self.queryset.active_translations(
            self.request_language, slug=kwargs['slug']).first()
        if not self.event:
            raise Http404("Event not found")

        set_language_changer(request, self.event.get_absolute_url)
        setattr(self.request, request_events_event_identifier, self.event)

        if hasattr(request, 'toolbar'):
            request.toolbar.set_object(self.event)

        return super(EventDetailView, self).dispatch(request, *args, **kwargs)
Exemple #38
0
    def get(self, request, *args, **kwargs):
        category = self.get_category_or_404()

        # only look at questions within this category
        queryset = self.get_queryset().filter(category=category.pk)

        question = self.get_object(queryset=queryset)
        question_url = question.get_absolute_url(self.current_language)

        if request.path != question_url:
            # say we have one category with two translations:
            # /en/faq/category-en/
            # /de/faq/category-de/
            # with this check we make sure that any request to
            # /en/faq/category-de/10/ gets redirected
            # to /en/faq/category-en/10/
            # where 10 is the question id
            return HttpResponsePermanentRedirect(question_url)

        set_language_changer(self.request, question.get_absolute_url)

        if hasattr(self.request, 'toolbar'):
            self.request.toolbar.set_object(question)

        setattr(
            self.request, request_faq_category_identifier, question.category)

        setattr(self.request, request_faq_question_identifier, question)
        response = super(FaqAnswerView, self).get(request, *args, **kwargs)

        # FIXME: We should check for unique visitors using sessions.
        # update number of visits
        question_only_queryset = self.get_queryset().filter(pk=question.pk)
        question_only_queryset.update(
            number_of_visits=models.F('number_of_visits') + 1)
        return response
    def get(self, request, *args, **kwargs):
        """
        This handles non-permalinked URLs according to preferences as set in
        Dashboards_appConfig.
        """
        #TODO Review this code as there is an error while creating the log file
        # Creates a log file for each Dashboard ####
        active_dashboard = self.get_object()

        set_up_dashboard_tree(active_dashboard)

        # Build Documentation
        try:
            [one, two] = BuildDoc(self)
        except Exception as e:
            logger.exception("Doc not created")


        ###################################################

        if not hasattr(self, 'object'):
            self.object = self.get_object()
        set_language_changer(request, self.object.get_absolute_url)
        url = self.object.get_absolute_url()
        if (self.config.non_permalink_handling == 200 or request.path == url):
            # Continue as normal
            return super(DashboardDetail, self).get(request, *args, **kwargs)

        # Check to see if the URL path matches the correct absolute_url of
        # the found object
        if self.config.non_permalink_handling == 302:
            return HttpResponseRedirect(url)
        elif self.config.non_permalink_handling == 301:
            return HttpResponsePermanentRedirect(url)
        else:
            raise Http404('This is not the canonical uri of this object.')
Exemple #40
0
    def get_context_data(self, **kwargs):
        context = super(Detail, self).get_context_data(**kwargs)

        context['counts1'] = VotingRecordResult.get_counts(
            record=context['obj'], session=1)
        context['votes1'] = VotingRecordResult.objects.filter(
            record=context['obj'], session=1)
        context['counts2'] = VotingRecordResult.get_counts(
            record=context['obj'], session=2)
        context['votes2'] = VotingRecordResult.objects.filter(
            record=context['obj'], session=2)
        context['counts3'] = VotingRecordResult.get_counts(
            record=context['obj'], session=3)
        context['votes3'] = VotingRecordResult.objects.filter(
            record=context['obj'], session=3)

        order_by = VotingRecord._meta.ordering
        context['amended_by'] =\
            context['obj'].amended_by.all().order_by(*order_by)
        context['amending'] =\
            context['obj'].amending.all().order_by(*order_by)

        set_language_changer(self.request, context['obj'].get_absolute_url)
        return context
Exemple #41
0
def blog_archive_tagged(request, **kwargs):
    kwargs['queryset_or_model'] = kwargs['queryset_or_model'].published()
    set_language_changer(request, language_changer)
    return tagged_object_list(request, **kwargs)
Exemple #42
0
 def set_language_changer(self, category):
     """Translate the slug while changing the language."""
     set_language_changer(self.request, category.get_absolute_url)
Exemple #43
0
 def get_dated_items(self):
     items = super(LanguageFallbackEntryArchiveIndexView,
                   self).get_dated_items()
     from cmsplugin_blog.urls import language_changer
     set_language_changer(self.request, language_changer)
     return items
Exemple #44
0
 def get(self, *args, **kwargs):
     self.object = self.get_object()
     response = super(CategoryPostListView, self).get(*args, **kwargs)
     set_language_changer(self.request, self.object.get_absolute_url)
     return response
Exemple #45
0
def blog_archive_day(request, **kwargs):
    kwargs['queryset'] = kwargs['queryset'].published()
    set_language_changer(request, language_changer)
    return archive_day(request, **kwargs)
Exemple #46
0
def blog_archive_tagged(request, **kwargs):
    kwargs['queryset_or_model'] = kwargs['queryset_or_model'].published()
    set_language_changer(request, language_changer)
    return tagged_object_list(request, **kwargs)
Exemple #47
0
    def get(self, request, *args, **kwargs):
        """
        This handles non-permalinked URLs according to preferences as set in
        Dashboards_appConfig.
        """

        #TODO Review this code as there is an error while creating the log file
        # Creates a log file for each Dashboard #### CODE ADDED BY DIABLO
        active_dashboard = self.get_object()

        author = active_dashboard.author
        logger.debug(author)

        try:
            file_name = 'resources/user_logs/' + str(author).replace(
                " ", "") + active_dashboard.slug + str(
                    active_dashboard.id) + ".log"
            if os.path.isfile(file_name) == False:

                logger.debug(os.path.abspath(os.curdir))
                f = open(file_name, "w")
                f.close()
                logger.debug('Log file created in %s', file_name)
            else:
                logger.debug('log file already created')
        except Exception as e:
            logger.exception("Error file not created")

        #create dashboard python modules Tree
        directory = 'resources/dashboards/' + active_dashboard.slug + '/'
        if not os.path.exists(directory):
            os.makedirs(directory)

        #create dashboard js modules Tree
        directory = 'static/js/dashboards/' + active_dashboard.slug + '/'
        if not os.path.exists(directory):
            os.makedirs(directory)

        #Create ajax_functionsfile
        file_name = 'static/js/dashboards/' + active_dashboard.slug + '/ajax_functions' + active_dashboard.slug + '.js'
        if os.path.isfile(file_name) == False:
            f = open(file_name, 'w')
            f.write(
                "//this file should hold the ajax functions for interaction in form_addon, dont delete"
            )
            f.close()
            logger.debug('Form Functions ajax created')

        #make them python directories
        file_name = 'resources/dashboards/' + active_dashboard.slug + '/__init__.py'
        if os.path.isfile(file_name) == False:
            f = open(file_name, 'w')
            f.close()
            logger.debug('Dashboard Module Created')

        file_name = 'resources/dashboards/' + active_dashboard.slug + '/FormFunctions.py'
        if os.path.isfile(file_name) == False:
            f = open(file_name, 'w')
            f.write(
                "#this file should hold the functions that can be selected in each dashboard, do not delete or rename this file"
            )
            f.close()
            logger.debug('Form Functions Module Created')

        #initialize all dashboards functions
        file_name = 'resources/dashboards/__init__.py'
        if os.path.isfile(file_name) == False:
            f = open(file_name, 'w')
            f.close()
            logger.debug('Dashboard  Created')

        # Build Documentation
        try:
            [one, two] = BuildDoc(self)
        except Exception as e:
            logger.exception("Doc not created")

        ###################################################

        if not hasattr(self, 'object'):
            self.object = self.get_object()
        set_language_changer(request, self.object.get_absolute_url)
        url = self.object.get_absolute_url()
        if (self.config.non_permalink_handling == 200 or request.path == url):
            # Continue as normal
            return super(DashboardDetail, self).get(request, *args, **kwargs)

        # Check to see if the URL path matches the correct absolute_url of
        # the found object
        if self.config.non_permalink_handling == 302:
            return HttpResponseRedirect(url)
        elif self.config.non_permalink_handling == 301:
            return HttpResponsePermanentRedirect(url)
        else:
            raise Http404('This is not the canonical uri of this object.')
Exemple #48
0
 def get_queryset(self):
     author = self.kwargs['author']
     queryset = super(BlogAuthorArchiveView, self).get_queryset().published().filter(entrytitle__author__username=author)
     if queryset:
         set_language_changer(self.request, queryset[0].language_changer)
     return queryset
Exemple #49
0
def blog_archive_day(request, **kwargs):
    kwargs['queryset'] = kwargs['queryset'].published()
    set_language_changer(request, language_changer)
    return archive_day(request, **kwargs)
Exemple #50
0
 def get_queryset(self):
     queryset = super(BlogTaggedArchiveView, self).get_queryset().published()
     if queryset:
         set_language_changer(self.request, queryset[0].language_changer)
     return queryset
Exemple #51
0
    def get_context_data(self, **kwargs):
        context = super(Detail, self).get_context_data(**kwargs)
        obj = context['obj']

        context['form'] = self._get_form(obj)
        context['questions'] = self._get_questions(obj)
        totalCount = VotingRecordResult.get_counts(representative=obj)

        context['attended'] = totalCount['total'] - totalCount['absent']
        context['absent'] = totalCount['absent']
        if totalCount['total'] == 0:
            context['percentage_attended'] = 0
            context['percentage_absent'] = 0
            context['percentage_attended_string'] = "N/A"
        else:
            context['percentage_attended'] = context['attended'] / float(totalCount['total']) * 100
            context['percentage_absent'] = 100 - context['percentage_attended']
            context['percentage_attended_string'] = "{0:.2f}".format(context['percentage_attended'])
            
        
        # Reformatting Contact phone and address information
        context['contactaddress'] = ""
        if obj.contact_address_phone:
            contactitems = obj.contact_address_phone.split("; ")
            context['contactaddress'] = [items.strip().replace("<p>","").replace("</p>","") for items in contactitems]

        #votecountall = VotingRecordResult.get_counts(representative=obj)
        #context['votecounts'] = votecountall
        context['votecounts'] = VotingRecordResult.get_counts(representative=obj,session=3)
        context['lawvotecounts'] = VotingRecordResult.get_counts(representative=obj,lawcount=True)

        context['url_feed'] = reverse('representative_feed_detail', args=[obj.pk])
        context['url_votingrecords'] = reverse(
            'representative_votingrecords', args=[obj.pk, obj.slug])
        try:
            context['decl'] = obj.incomedeclaration.all()[0]
        except IndexError:
            context['decl'] = None


        try:
            latestdeclarationid = obj.income['declarationid']
            familymembers = obj.family_income.filter(ad_id__exact=latestdeclarationid).exclude(fam_income__exact=0)
            # This loop is temporary. We need to fix the xquery file that write the SQL file for representative_familyincome.
            for member in familymembers:
                member.fam_name_en = glt.to_latin(member.fam_name)
                member.fam_name_ka = member.fam_name
                member.fam_role_en = glt.to_latin(member.fam_role)
                member.fam_role_ka = member.fam_role
            context['faminc'] = familymembers
  
        except IndexError:
            context['faminc'] = None

        try:
            currentincomeyear = obj.income['latestsubmissionyear']
            context['assetlinks'] = obj.urls.filter(label__contains="Asset").exclude(label__contains=currentincomeyear)
        except IndexError:
            context['assetlinks'] = None

        try:
            names_to_exclude = ["Facebook","Twitter","LinkedIn","Wikipedia","Asset Link"]
            context['parliamentlink'] = obj.urls.all().exclude(label__in=names_to_exclude)
        except IndexError:
            context['parliamentlink'] = None

        try:
            names_to_exclude = ["მთავარი","Homepage","Parliament.ge"]
            context['sociallinks'] = obj.urls.all().exclude(label__in=names_to_exclude).exclude(label__contains="Asset")
        except IndexError:
            context['sociallinks'] = None

        set_language_changer(self.request, obj.get_absolute_url)
        return context
Exemple #52
0
    def get_context_data(self, **kwargs):
        context = super(VotingRecords, self).get_context_data(**kwargs)
        set_language_changer(self.request, context['obj'].get_absolute_url)
        context['results'] = _get_votingrecord_results(context['obj'])

        return context
Exemple #53
0
 def set_language_changer(self, category):
     """Translate the slug while changing the language."""
     set_language_changer(self.request, category.get_absolute_url)
Exemple #54
0
 def set_language_changer(self, job_opening):
     """Translate the slug while changing the language."""
     set_language_changer(self.request, job_opening.get_absolute_url)