Ejemplo n.º 1
0
	def _normalize_file(self, request):
		"""
		Normalize the file path managed by this node, making it an absolute URL
		referencing the shared media URL if it's shared or pointing to the
		current project's media URL if not. Furthermore, if the tag was able to
		access the `request` object from the context, make it secure if the
		request itself is secure.
		"""
		if self.shared:
			self.file_path = make_shared_media_url(self.file_path)
		else:
			if not self.file_path.startswith("http"):
				self.file_path = os.path.join(settings.MEDIA_URL, self.file_path)
		if request is not None and request.is_secure():
			self.file_path = make_secure_media_url(self.file_path)
Ejemplo n.º 2
0
    def _normalize_file(self, request):
        """
		Normalize the file path managed by this node, making it an absolute URL
		referencing the shared media URL if it's shared or pointing to the
		current project's media URL if not. Furthermore, if the tag was able to
		access the `request` object from the context, make it secure if the
		request itself is secure.
		"""
        if self.shared:
            self.file_path = make_shared_media_url(self.file_path)
        else:
            if not self.file_path.startswith("http"):
                self.file_path = os.path.join(settings.MEDIA_URL,
                                              self.file_path)
        if request is not None and request.is_secure():
            self.file_path = make_secure_media_url(self.file_path)
Ejemplo n.º 3
0
	def render(self, name, value, attrs=None):
		"""Show the field's time value in HH:MM format."""

		final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)

		#  Attempt to transform an existing time value into a value capable of
		#  being an attribute of the input tag that this widget is rendered as.
		try:
			value = value.strftime(self.time_format)
		except AttributeError:
			try:
				value = datetime.datetime.strptime(value, "%H:%M").time().strftime(self.time_format)
			except (ValueError, AttributeError, TypeError):
				value = ''
		final_attrs['value'] = force_unicode(value)
		return mark_safe(
			u'<input%(input)s /> <img src="%(icon_src)s" class="%(icon_class)s" alt="%(icon_alt)s" />' % {
				'input': flatatt(final_attrs),
				'icon_src': make_shared_media_url(self._CLOCK_ICON),
				'icon_class': u" ".join(self._ICON_CLASSES),
				'icon_alt': _("clock icon")
			})
Ejemplo n.º 4
0
    def render(self, name, value, attrs=None):
        """Show the field's time value in HH:MM format."""

        final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)

        #  Attempt to transform an existing time value into a value capable of
        #  being an attribute of the input tag that this widget is rendered as.
        try:
            value = value.strftime(self.time_format)
        except AttributeError:
            try:
                value = datetime.datetime.strptime(
                    value, "%H:%M").time().strftime(self.time_format)
            except (ValueError, AttributeError, TypeError):
                value = ''
        final_attrs['value'] = force_unicode(value)
        return mark_safe(
            u'<input%(input)s /> <img src="%(icon_src)s" class="%(icon_class)s" alt="%(icon_alt)s" />'
            % {
                'input': flatatt(final_attrs),
                'icon_src': make_shared_media_url(self._CLOCK_ICON),
                'icon_class': u" ".join(self._ICON_CLASSES),
                'icon_alt': _("clock icon")
            })