示例#1
0
文件: pages.py 项目: kgodey/philo
	content = TemplateField()
	
	def __unicode__(self):
		"""Returns the value of the :attr:`name` field."""
		return self.name
	
	class Meta:
		app_label = 'philo'


class ContentReference(models.Model):
	"""Represents a model instance related to a page."""
	#: The page which this :class:`ContentReference` is related to.
	page = models.ForeignKey(Page, related_name='contentreferences')
	#: This represents the name of the container as defined by a :ttag:`container` tag.
	name = models.CharField(max_length=255, db_index=True)
	content_type = models.ForeignKey(ContentType, verbose_name='Content type')
	content_id = models.PositiveIntegerField(verbose_name='Content ID', blank=True, null=True)
	#: A :class:`GenericForeignKey` to a model instance. The content type of this instance is defined by the :ttag:`container` tag which defines this :class:`ContentReference`.
	content = generic.GenericForeignKey('content_type', 'content_id')
	
	def __unicode__(self):
		"""Returns the value of the :attr:`name` field."""
		return self.name
	
	class Meta:
		app_label = 'philo'


register_value_model(Template)
register_value_model(Page)
示例#2
0
	
	"""
    #: A :class:`CollectionMemberManager` instance
    objects = CollectionMemberManager()
    #: :class:`ForeignKey` to a :class:`Collection` instance.
    collection = models.ForeignKey(Collection, related_name='members')
    #: The numerical index of the item within the collection (optional).
    index = models.PositiveIntegerField(
        verbose_name='Index',
        help_text=
        'This will determine the ordering of the item within the collection. (Optional)',
        null=True,
        blank=True)
    member_content_type = models.ForeignKey(
        ContentType,
        limit_choices_to=value_content_type_limiter,
        verbose_name='Member type')
    member_object_id = models.PositiveIntegerField(verbose_name='Member ID')
    #: :class:`GenericForeignKey` to an arbitrary model instance.
    member = generic.GenericForeignKey('member_content_type',
                                       'member_object_id')

    def __unicode__(self):
        return u'%s - %s' % (self.collection, self.member)

    class Meta:
        app_label = 'philo'


register_value_model(Collection)
示例#3
0
    name = models.CharField(max_length=255)
    #: Defines the mimetype of the uploaded file. This will not be validated. If no mimetype is provided, it will be automatically generated based on the filename.
    mimetype = models.CharField(max_length=255, blank=True)
    #: Contains the uploaded file. Files are uploaded to ``philo/files/%Y/%m/%d``.
    file = models.FileField(upload_to='philo/files/%Y/%m/%d')

    def clean(self):
        if not self.mimetype:
            self.mimetype = mimetypes.guess_type(self.file.name,
                                                 strict=False)[0]
            if self.mimetype is None:
                raise ValidationError("Unknown file type.")

    def actually_render_to_response(self, request, extra_context=None):
        wrapper = FileWrapper(self.file)
        response = HttpResponse(wrapper, content_type=self.mimetype)
        response['Content-Length'] = self.file.size
        response['Content-Disposition'] = "inline; filename=%s" % basename(
            self.file.name)
        return response

    class Meta:
        app_label = 'philo'

    def __unicode__(self):
        """Returns the value of :attr:`File.name`."""
        return self.name


register_value_model(Node)
示例#4
0
文件: nodes.py 项目: derega/philo
	"""Stores an arbitrary file."""
	#: The name of the uploaded file. This is meant for finding the file again later, not for display.
	name = models.CharField(max_length=255)
	#: Defines the mimetype of the uploaded file. This will not be validated. If no mimetype is provided, it will be automatically generated based on the filename.
	mimetype = models.CharField(max_length=255, blank=True)
	#: Contains the uploaded file. Files are uploaded to ``philo/files/%Y/%m/%d``.
	file = models.FileField(upload_to='philo/files/%Y/%m/%d')
	
	def clean(self):
		if not self.mimetype:
			self.mimetype = mimetypes.guess_type(self.file.name, strict=False)[0]
			if self.mimetype is None:
				raise ValidationError("Unknown file type.")
	
	def actually_render_to_response(self, request, extra_context=None):
		wrapper = FileWrapper(self.file)
		response = HttpResponse(wrapper, content_type=self.mimetype)
		response['Content-Length'] = self.file.size
		response['Content-Disposition'] = "inline; filename=%s" % basename(self.file.name)
		return response
	
	class Meta:
		app_label = 'philo'
	
	def __unicode__(self):
		"""Returns the value of :attr:`File.name`."""
		return self.name


register_value_model(Node)
示例#5
0
文件: pages.py 项目: somair/philo
    def __unicode__(self):
        """Returns the value of the :attr:`name` field."""
        return self.name

    class Meta:
        app_label = 'philo'


class ContentReference(models.Model):
    """Represents a model instance related to a page."""
    #: The page which this :class:`ContentReference` is related to.
    page = models.ForeignKey(Page, related_name='contentreferences')
    #: This represents the name of the container as defined by a :ttag:`container` tag.
    name = models.CharField(max_length=255, db_index=True)
    content_type = models.ForeignKey(ContentType, verbose_name='Content type')
    content_id = models.PositiveIntegerField(verbose_name='Content ID',
                                             blank=True,
                                             null=True)
    #: A :class:`GenericForeignKey` to a model instance. The content type of this instance is defined by the :ttag:`container` tag which defines this :class:`ContentReference`.
    content = generic.GenericForeignKey('content_type', 'content_id')

    def __unicode__(self):
        """Returns the value of the :attr:`name` field."""
        return self.name

    class Meta:
        app_label = 'philo'


register_value_model(Template)
register_value_model(Page)