def get_context(self): """ Returns a Context object with elements for the template context of the template returned by ``get_template``. """ context = getattr(self, "_context", None) if context is not None: return context else: self._context = Context( { "story": self.story, "unpublished_stories": self.story.author.stories.filter(status="draft") .exclude(pk=self.story.pk) .order_by("-created"), "recent_stories": Story.objects.public().exclude(pk=self.story.pk).order_by("-published")[:3], # Pre-cook a bunch of URL paths to make template # markup leaner "builder_url": full_url(self.story.builder_url()), "viewer_url": full_url(self.story.viewer_url()), "explorer_url": full_url(reverse("explore_stories")), "detail_url": (full_url(self.story.get_absolute_url()) if not self.story.is_connected() else ""), "account_notifications_url": full_url(reverse("account_notifications")), } ) return self._context
def story_embed(story): return { 'default_embed_widget_height': DEFAULT_EMBED_WIDGET_HEIGHT, 'story': story, 'storybase_site_name': settings.STORYBASE_SITE_NAME, 'widget_js_url': full_url(settings.STATIC_URL + 'js/widgets.min.js'), }
def test_full_url_path_no_proto(self): """ Test that a full url is returned when a blank scheme is specified """ path = "/stories/asdas-3/" self.assertEqual("//floodlightproject.org/stories/asdas-3/", full_url(path, None))
def test_full_url_path_https(self): """ Test that a full url is returned when a path is given and the scheme is specified. """ path = "/stories/asdas-3/" self.assertEqual("https://floodlightproject.org/stories/asdas-3/", full_url(path, 'https'))
def test_full_url_passthrough(self): """ Test that a full url is just passed through if the argument is already a full URL """ path = "http://floodlightproject.org/stories/asdas-3/" self.assertEqual("http://floodlightproject.org/stories/asdas-3/", full_url(path))
def embed_code(obj): return { 'default_embed_widget_height': DEFAULT_EMBED_WIDGET_HEIGHT, 'object': obj, 'embed_class': ('storybase-story-embed' if obj.__class__.__name__ == 'Story' else 'storybase-list-embed'), 'object_name': _object_name(obj), 'storybase_site_name': settings.STORYBASE_SITE_NAME, 'widget_js_url': full_url(settings.STATIC_URL + 'js/widgets.min.js', scheme=''), }
def get_thumbnail_url(self, width=0, height=0, **kwargs): # First, try to get the user's Facebook profile image url = self.facebook_image_url(width) if url: return url # Go to Gravatar to retrieve the user's profile image # If we provide a default image URL, Gravatar will fall # back to this. default_url = full_url(self.get_default_img_url(width, height)) from storybase_user.utils import gravatar_url return gravatar_url(self.user.email, default_url, width)
def render(self, context): from storybase.utils import full_url try: url = full_url(self.path.resolve(context)) except VariableDoesNotExist: url = '' if self.asvar: context[self.asvar] = url return '' else: return url
def send_create_notification(self, obj=None): if obj is None: obj = self.object admin_url_name = "admin:%s_%s_change" % (obj._meta.app_label, obj._meta.object_name.lower()) admin_url = full_url(reverse(admin_url_name, args=(obj.id,))) message = render_to_string('storybase_user/admin_approval_required_email.txt', { 'object': obj, 'admin_url': admin_url }) subject = "New %s %s needs your approval" % ( obj._meta.object_name, obj.name) send_admin_mail(subject, message, settings.DEFAULT_FROM_EMAIL) return True
def get_default_img_url(cls, width, height, include_host=False): choices = cls.get_default_img_url_choices() lgst_width = 0 lgst_src = None for img_width, url in choices.iteritems(): if img_width <= width and img_width > lgst_width: lgst_src = url lgst_width = img_width if include_host: lgst_src = full_url(lgst_src) return lgst_src
def get_context(self): """ Returns a Context object with elements for the template context of the template returned by ``get_template``. """ context = getattr(self, '_context', None) if context is not None: return context else: self._context = Context({ 'story': self.story, 'unpublished_stories': self.story.author.stories.filter(status='draft').exclude(pk=self.story.pk).order_by('-created'), 'recent_stories': Story.objects.public().exclude(pk=self.story.pk).order_by('-published')[:3], # Pre-cook a bunch of URL paths to make template # markup leaner 'builder_url': full_url(self.story.builder_url()), 'viewer_url': full_url(self.story.viewer_url()), 'explorer_url': full_url(reverse('explore_stories')), 'detail_url': (full_url(self.story.get_absolute_url()) if not self.story.is_connected() else ''), 'account_notifications_url': full_url(reverse('account_notifications')), }) return self._context
def send_create_notification(self, obj=None): if obj is None: obj = self.object admin_url_name = "admin:%s_%s_change" % (obj._meta.app_label, obj._meta.object_name.lower()) admin_url = full_url(reverse(admin_url_name, args=(obj.id, ))) message = render_to_string( 'storybase_user/admin_approval_required_email.txt', { 'object': obj, 'admin_url': admin_url }) subject = "New %s %s needs your approval" % (obj._meta.object_name, obj.name) send_admin_mail(subject, message, settings.DEFAULT_FROM_EMAIL) return True
def get_thumbnail_url(self, width=0, height=0, **kwargs): """Return the URL of the Asset's thumbnail""" include_host = kwargs.get('include_host', False) if not self.image: return None thumbnail_options = { # Disable crop for now in favor of CSS cropping, but this # is how you would do it. This particular argument crops # from the center on the x-axis and the top edge of the # image on the y-axis. # See http://easy-thumbnails.readthedocs.org/en/latest/ref/processors/#easy_thumbnails.processors.scale_and_crop #'crop': ',0', 'size': (width, height), } thumbnail = self.get_thumbnail(thumbnail_options) if include_host: return full_url(thumbnail.url) else: return thumbnail.url
def test_full_url_path(self): """Test that a full url is returned when a path is given""" path = "/stories/asdas-3/" self.assertEqual("http://floodlightproject.org/stories/asdas-3/", full_url(path))