Ejemplo n.º 1
0
    def card_image_url(self):
        """
        Get the relative url for the card Image
        """
        if not self.card_image:
            return ''

        return get_image_url(self.site, self.card_image)
Ejemplo n.º 2
0
    def hero_image_url(self):
        """
        Get the relative url for the hero Image
        """
        if not self.hero_image:
            return ''

        return get_image_url(self.site, self.hero_image)
Ejemplo n.º 3
0
    def get(self, request):
        """ Responds to GET calls with theming, user, and site information """
        if request.user.is_authenticated:
            current_user = User.objects.get(pk=self.request.user.pk)
        else:
            current_user = None
        frontend_url = request.META.get('HTTP_REFERER')
        frontend_url = urlparse(frontend_url)._replace(path='').geturl()
        try:
            site_config = SiteConfiguration.objects.get(frontend_url=frontend_url)
            site = site_config.site
        except SiteConfiguration.DoesNotExist:
            site = request.site

        server_url = "{}://{}".format(
            request.scheme,
            site.hostname,
        )
        port = request.get_port()
        if port not in STANDARD_HTTP_PORTS:
            server_url += ':{}'.format(port)
        logo = get_image_url(site, site.sitebranding.site_logo) if site.sitebranding.site_logo else None
        theme_name = site.sitebranding.theme_name
        lms_url_root = site.siteconfiguration.lms_public_url_root_override or site.siteconfiguration.lms_url_root
        footer_links = site.sitebranding.footer_links
        authorized_journals = JournalAccess.get_user_accessible_journal_ids(request.user)
        segment_key = site.siteconfiguration.segment_key
        last_visited = self.get_last_visited(self.request.user) if self.request.user.is_authenticated else []

        return Response({
            'user': UserSerializer(current_user).data,
            'is_authenticated': bool(current_user),
            'visited_pages': UserPageVisitSerializer(last_visited, many=True).data,
            'server_url': server_url,
            'logo': logo,
            'theme_name': theme_name,
            'lms_url_root': lms_url_root,
            'footer_links': footer_links,
            'authorized_journals': authorized_journals,
            'segment_key': segment_key,
        })
Ejemplo n.º 4
0
    def get_api_representation(self, value, context=None):
        block_title = self.get_title(value)
        block_caption = self.get_caption_block(value)
        image = self.get_image(value)

        if image:
            return {
                'title':
                block_title if block_title else image.title,
                'width':
                image.width,
                'height':
                image.height,
                'image_id':
                image.id,
                'url':
                get_image_url(context['request'].site, image),
                'caption':
                self.get_caption_text(value)
                if block_caption else image.caption,
                'span_id':
                get_span_id(IMAGE_BLOCK_TYPE, image.id)
            }

        log.warning(
            'Missing Image: image has been deleted but still referenced in page'
        )
        return {
            'title': block_title if block_title else "Missing Image",
            'width': 0,
            'height': 0,
            'image_id': 0,
            'url': '',
            'caption': self.get_caption_text(value) if block_caption else '',
            'span_id': 'missing-image',
        }
Ejemplo n.º 5
0
 def hero_image_url(self):
     if self.hero_image:
         return get_image_url(self.site, self.hero_image)
     else:
         return ''