コード例 #1
0
class VisitEvent(RealEstateAppBaseModel):

    property_fk = models.ForeignKey('propertys.Property')

    visitor_fk = models.ForeignKey('visitcalendar.Visitor')

    date_visit = models.DateTimeField(
        _('Date of visit'),
        unique=True,
        default=datetime.now(),
        help_text=_('Entry with a init of date publicashion'))

    slug = models.SlugField(
        _('slug'),
        unique=True,
        help_text=_('Automatically built from the caption. A slug is a short '
                    'label generally used in URLs.'),
    )

    objects = RealEstateManager()

    class Meta:
        app_label = 'visitcalendar'
        db_table = 'real_estate_app_apps_visitcalendar_visitevent'
        get_latest_by = 'date_visit'
        ordering = ('date_visit', )
        verbose_name = _('Visit')
        verbose_name_plural = _('Visits')

    def __unicode__(self):
        try:
            return u'%s' % self.date_visit.strftime(
                settings.DATETIME_INPUT_FORMATS[0])
        except IndexError:
            return u'%s' % self.date_visit.strftime('%Y-%m-%d %H:%M:%S')
        else:
            raise

    def _visitor(self):
        return self.visitor_first_name + ' ' + self.visitor_last_name

    visitor = property(_visitor)

    def _get_absolute_url(self):
        return ('visitcalendar-detail', None, {
            'slug': str(self.slug),
        })

    get_absolute_url = permalink(_get_absolute_url)
コード例 #2
0
ファイル: fields.py プロジェクト: tatyana12/djang
class StatusProperty(RealEstateAppBaseModel):
    statusproperty = models.CharField(
        _('Status Property'),
        max_length=100,
        help_text=_('Enter with new status. Ex.: Rent, Sale,...'))

    objects = RealEstateManager()

    def __unicode__(self):
        return self.statusproperty

    class Meta:
        app_label = 'propertys'
        db_table = 'real_estate_app_apps_propertys_status_property'
        get_latest_by = 'statusproperty'
        ordering = ('statusproperty', )
        verbose_name = _('Status Property')
        verbose_name_plural = _('Status Propertys')
コード例 #3
0
ファイル: fields.py プロジェクト: tatyana12/djang
class Classification(RealEstateAppBaseModel):
    classification = models.CharField(
        _('Classification'),
        max_length=100,
        help_text=_('Enter with new classification. Ex.: House, Build,...'))

    objects = RealEstateManager()

    def __unicode__(self):
        return u'%s' % self.classification

    class Meta:
        app_label = 'propertys'
        db_table = 'real_estate_app_apps_propertys_classification'
        get_latest_by = 'classification'
        ordering = ('classification', )
        verbose_name = _('Classification')
        verbose_name_plural = _('Classifications')
コード例 #4
0
ファイル: fields.py プロジェクト: tatyana12/djang
class PositionOfSun(RealEstateAppBaseModel):

    position = models.CharField(
        _('Position'),
        max_length=255,
        help_text=_('Enter with a new position of sun of a property.'))

    objects = RealEstateManager()

    def __unicode__(self):
        return self.position

    class Meta:
        app_label = 'propertys'
        db_table = 'real_estate_app_apps_propertys_position_of_sun'
        get_latest_by = 'position'
        ordering = ('position', )
        verbose_name = _('Position of sun')
        verbose_name_plural = _('Positions of sun')
コード例 #5
0
ファイル: models.py プロジェクト: tatyana12/djang
class RealEstateAppBaseModel(models.Model):
    def __init__(self, *args, **kwargs):
        super(RealEstateAppBaseModel, self).__init__(*args, **kwargs)
        self.template = "admin/%s/%s/%s_rendered.html" % (
            self._meta.app_label, self._meta.object_name.lower(),
            self._meta.object_name.lower())

    logical_exclude = models.NullBooleanField(_('Logical exclude'),
                                              default=False,
                                              null=True,
                                              editable=False)

    enable_publish = models.BooleanField(_('Enable publish'), default=True)

    create_date = models.DateTimeField(
        _('Creation date'),
        default=datetime.now(),
        help_text=_('Entry with a init of date publicashion'))

    objects = RealEstateManager()

    class Meta:
        abstract = True

    def _render_object(self):
        """
			Render a object to portlet
		"""
        from django import template
        object_name = self._meta.object_name.lower()
        app_label = self._meta.app_label

        context = template.Context({
            'obj': self,
        })

        return template.loader.get_template(self.template or [
            "admin/%s/%s_rendered.html" % (app_label, object_name),
            "admin/%s_rendered.html" % object_name
        ]).render(context)

    render = property(_render_object)
コード例 #6
0
class TermVisit(RealEstateAppCompleteModel):

	text = models.TextField(
							_('Text of term'),
							blank=False,
							null=False,
							help_text=_('Term visit variables you can use: \n %s' % RenderVariablesString(
																						app='real_estate_app.apps.visitcalendar',
																						obj=Visitor
																					).str_variables_locale()
							)
	)

	objects = RealEstateManager()

	class Meta:
		app_label = 'visitcalendar'
		db_table  = 'real_estate_app_apps_visitcalendar_termvisit'
		get_latest_by='create_date'
		ordering=('create_date',)
		verbose_name=_('Term Visit')
		verbose_name_plural=_('Terms of hits')
コード例 #7
0
ファイル: fields.py プロジェクト: tatyana12/djang
class AditionalThings(RealEstateAppBaseModel):

    name = models.CharField(
        _('Name'),
        max_length=255,
        help_text=
        _('Enter with new aditional things to property. Ex.: Pool, Barbecue,...'
          ))

    #   TODO: report a bug to django about this error when i use the
    #	      CheckboxSelectMultiple with custom Manager has problem.
    #         Not work with logical_exclude and mark all checked
    objects = RealEstateManager()

    def __unicode__(self):
        return self.name

    class Meta:
        app_label = 'propertys'
        db_table = 'real_estate_app_apps_propertys_aditionalthings'
        get_latest_by = 'name'
        ordering = ('name', )
        verbose_name = _('Aditional things')
        verbose_name_plural = _('Aditionals things')
コード例 #8
0
ファイル: visitor.py プロジェクト: tatyana12/djang
class Visitor(RealEstateAppBaseModel):
	
	first_name = models.CharField(
		_('First name'),
		max_length=255
	)

	last_name = models.CharField(
		_('Last name'),
		max_length=255
	)

	if LANGUAGE_CODE in ('pt_BR','pt-br'):
		from django.contrib.localflavor.br.br_states import STATE_CHOICES

		cpf = models.CharField(
			u'CPF',
			max_length=14,
			unique=True,
		)

		rg = models.CharField(
			u'RG',
			max_length=20
		)

		ssp = models.CharField(
			u'SSP',
			max_length=2,
			choices=STATE_CHOICES,
			blank=True
		)

	address = models.CharField(
		_('Address'),
		max_length=255
	)

	zip = models.CharField(
		_('ZIP'),
		max_length=15
	)

	celphone = models.CharField(
		_('Celphone'),
		max_length=15
	)
	phone = models.CharField(
		_('Phone'),
		max_length=15
	)

	email = models.CharField(
		_('E-mail'),
		max_length=255
	)

	work_address = models.CharField(
		_('Work address'),
		max_length=255
	)

	work_zip = models.CharField(
		_('Work ZIP'),
		max_length=15
	)

	work_phone = models.CharField(
		_('Work phone'),
		max_length=15
	)

	objects=RealEstateManager()

	class Meta:
		app_label = 'visitcalendar'
		db_table  = 'real_estate_app_apps_visitcalendar_visitor'
		get_latest_by='create_date'
		ordering=('create_date',)
		verbose_name=_('Visitor')
		verbose_name_plural=_('Visitors')

	def __unicode__(self):
			return u'%s' % self.name

	def _name(self):
		return self.first_name+' '+self.last_name
	name=property(_name)

	def _get_absolute_url(self):
		return ('visitcalendar-detail',None, {
				'slug' : str(self.slug),
				})
	get_absolute_url=permalink(_get_absolute_url)
コード例 #9
0
ファイル: realtors.py プロジェクト: tatyana12/djang
class Realtor(RealEstateAppBaseModel):

	unknow_img = REAL_ESTATE_REALTOR_UNKNOW_IMG

	user = models.ForeignKey(User, unique=True)

	sex = models.CharField(
							_('Sex'),
							max_length=1,
							choices=SEX,
							blank=True
	)

	phone = models.CharField(
							_('Phone'),
							max_length=20,
							blank=True
	)

	celphone = models.CharField(
							_('Celphone'),
							max_length=20,
							blank=True
	)
	
	photo = models.ImageField(
							_('photo'),
							upload_to=get_realtor_directory,
							max_length=255,
							blank=True
	)

	if LANGUAGE_CODE in ('pt_BR','pt-br'):
		from django.contrib.localflavor.br.br_states import STATE_CHOICES
		from real_estate_app.localflavor.br import TIPO_PESSOA

		cpf = models.CharField(
								u'CPF',
								max_length=14,
								blank=True,
								unique=True
		)
	
		rg = models.CharField(
						   	u'RG',
						   	max_length=10,
						   	blank=True
		)
	
		ssp = models.CharField(
								u'SSP',
								max_length=2,
								choices=STATE_CHOICES,
								blank=True
		)

		cnpj = models.CharField(
							u'CNPJ',
							max_length=18,
							blank=True
		)

		razao_social=models.CharField(
							u'Razao Social',
							max_length=250,
							blank=True
		)

		tipo_pessoa = models.CharField(
							u'Pessoa Física ou Jurídica',
							max_length=3,
							choices=TIPO_PESSOA,
							default='PF'
		)

		creci = models.CharField(
							u'CRECI',
							max_length=10,
		)
	
	objects= RealEstateManager()

	class Meta:
		app_label = 'realtors'
		db_table  = 'real_estate_app_apps_realtors_realtor'
		get_latest_by='username'
		ordering=('user',)
		verbose_name=_('Realtor')
		verbose_name_plural=_('Realtors')
		
		if LANGUAGE_CODE in ('pt_BR','pt-br'):
			unique_together=[('rg','ssp'),('creci','ssp')]


	def __unicode__(self):
				
		return u'%s' % self.name

	def get_first_name(self):
		try:
			return self.__name
		except AttributeError:
			try:
				self.__name = self.user.first_name
			except IndexError:
				self.__name = self.user.email
			return self.__name
	first_name=property(get_first_name)

	def get_last_name(self):
		try:
			return self.__name
		except AttributeError:
			try:
				self.__name = self.user.last_name
			except IndexError:
				self.__name = self.user.email
			return self.__name
	last_name=property(get_last_name)

	def get_user_name(self):
		if LANGUAGE_CODE == 'pt-br' and self.tipo_pessoa == 'PJ':
			self.__name=self.razao_social
			return self.__name
		try:
			return self.__name
		except AttributeError:
			try:
				self.__name = self.user.first_name+' '+self.user.last_name
			except IndexError:
				self.__name = self.user.email
			return self.__name
	name=property(get_user_name)

	def get_phones(self):
		try:
			return self.__phones
		except AttributeError:
			try:
				self.__phones = self.phones_set.all()
			except IndexError:
				self.__phones = None

			return self.__phones
	
	phones=property(get_phones)

	def get_email(self):
		try:
			return self.__email
		except AttributeError:
			try: 
				self.__email = self.user.email
			except IndexError:
				self.__email = None

			return self.__email
	email=property(get_email)

	def get_address(self):
		try:
			return self.__address
		except AttributeError:
			try:
				self.__address = self.address_set.all()
			except IndexError:
				self.__address = None

			return self.__address
	
	address=property(get_address)


	def __getattr__(self, name):
		"""
		Deploys dynamic methods for on-demand thumbnails creation with any
		size.

		Syntax::

		get_photo_[WIDTH]x[HEIGHT]_[METHOD]

		Where *WIDTH* and *HEIGHT* are the pixels of the new thumbnail and
		*METHOD* can be ``url`` or ``filename``.

		Example usage::

	    >>> photo = Photo(photo="/tmp/example.jpg", ...)
	    >>> photo.save()
	    >>> photo.get_photo_320x240_url()
	    >>> u"http://media.example.net/photos/2008/02/26/example_320x240.jpg"
	    >>> photo.get_photo_320x240_filename()
	    >>> u"/srv/media/photos/2008/02/26/example_320x240.jpg"
		"""
		match = re.match(GET_THUMB_PATTERN, name)
		matchh = re.match(GET_THUMBNAIL,name)
		if match is None and matchh is None:
			raise AttributeError, name

		try:
			methodd, widthh, heightt = matchh.groups()

			def get_thumbnail_crop():
				from sorl.thumbnail import get_thumbnail
				size=widthh+'x'+heightt
				attrs={
					'crop':'center',
					'quality':99,
				}

				try:
					my_file=self.photo.file.name
				except ValueError:
					# TODO: discover why get error when try to pass 
					#       self.unknow_img to get_thumbnail
					return self.unknow_img
				
				return get_thumbnail(my_file,size, **attrs).url

			if methodd == "sorlthumbnail_crop":
				return get_thumbnail_crop

		except AttributeError:
			pass
		### All others methods different of get_thumbnail_crop or get_thumbnail will
		### be deprecated.
		try:
			width, height, method = match.groups()
			size = int(width), int(height)
			def get_photo_thumbnail_filename():
				file, ext = path.splitext(self.photo.file.name)
				return file + '_%sx%s' % size + ext

			def get_photo_thumbnail_url():
				url, ext = path.splitext(self.photo.url)
				return url + '_%sx%s' % size + ext	


			def get_photo_thumbnail_resize_filename():
				file, ext = path.splitext(self.photo.file.name)
				return file + '_%sx%s_' % size + method + ext

			def get_photo_thumbnail_resize_url():
				url, ext = path.splitext(self.photo.url)
				return url + '_%sx%s_' % size + method + ext	

			if method == "thumb_url" or method=="thumb_filename":	
				thumbnail = get_photo_thumbnail_filename()
			else:
				thumbnail = get_photo_thumbnail_resize_filename()

			if not path.exists(thumbnail):
				img = Image.open(self.photo.file.name)

				if method =="thumb_url" or method == "thumb_filename":
					img.thumbnail(size, Image.ANTIALIAS)
					img.save(thumbnail)
				else:
					(img_width,img_height)=img.size
					
					wpercent=(size[0]/float(img_width))
					HSIZE=int((float(img_height)*float(wpercent)))

					y_crop=int((float((HSIZE/2.0))-float((size[1]/2.0))))
					height_crop=(HSIZE-y_crop)				
					
					box=(0,y_crop,size[0],height_crop)

					new_img = img.resize((size[0],HSIZE),Image.ANTIALIAS)

					crop=new_img.crop(box)
					crop.load()
					crop.save(thumbnail)

			if method == "thumb_url":
				return get_photo_thumbnail_url
			elif method == "resize_url":
				return get_photo_thumbnail_resize_url
			else:
				return get_photo_thumbnail_filename
		except AttributeError:
			pass