def add_property(request, pk): # add property from our temporary scrape data into permanent Property data if request.is_ajax(): if request.method == 'POST': # assign property variables from the posted property p = get_object_or_404(Apartment, id=pk) # build a list of all amenity titles cw = AmenityCrossWalk.objects.all() amenity_titles = [] for a in cw: amenity_titles.append(a.scrape_title) try: #save apartment and its related models images = p.apartmentimage_set.all() floor_plans = p.apartmentfloorplan_set.all() amenities = p.apartmentamenity_set.all() prop_instance = Property(title=p.title, addr=p.address, school=p.school, city=p.city, state=p.state, zip_cd=p.zip_cd, user=request.user, lat=p.lat, long=p.long, description=p.description) prop_instance.save() for a in amenities: # get the permanent amenity based on crosswalk with scraped title if a.title in amenity_titles: amenity_xw = AmenityCrossWalk.objects.get(scrape_title=a.title) prop_instance.amenities.add(amenity_xw.amenity) for i in images: instance = PropertyImage(image_link=i.link, property=prop_instance, caption="") instance.save() for f in floor_plans: instance = PropertyRoom(property=prop_instance, price=f.price, bed_count=f.bed_count, bath_count=f.bath_count, sq_ft=f.sq_ft) instance.save() # log success instance = Log(city=p.school.city, apartment_name=p.title, status='S', comment="Successfully saved " + p.title) instance.save() return HttpResponse("Successfully added " + p.title) except Exception as e: return HttpResponse(e) else: return HttpResponse("Not a POST request") else: return HttpResponse("Not an AJAX call")
def setUp(self): test_user = User.objects.create(user_name='test', kakao_id=12345) test_property = Property( property_name = '선릉 근처 근사한 숙소', description = '머물기 정말 편한 숙소입니다.', address1 = '서울시 성북구', address2 = '', postal = '12345', max_people = 4, price = 50000, ) test_property.save()
def form_valid(self, form): """ Assign datatype data inside a transaction object """ with transaction.atomic(): form.instance.author = self.request.user form.instance.generic = False form.instance.community = Community.objects.get( id=self.kwargs.get('community_id')) form.instance.save() property_title = Property(datatype=form.instance, author=self.request.user, name='Title', type=0, generic=1, required=True) property_title.save() property_semantic_tag = Property(datatype=form.instance, author=self.request.user, name='Semantic Tags', type=0, generic=1, required=True) property_semantic_tag.save() return FormMixin.form_valid(self, form)
def calculate_compound_interest(request): context = dict(form=CompoundInterestForm()) if request.POST: context = dict(form=CompoundInterestForm(request.POST)) if context['form'].is_valid(): data = context['form'].cleaned_data context['monthly_payment'] = Property.interest_calculation( data['price'], data['months'], data['monthly_interest']) context['months'] = data['months'] context['total'] = data['months'] * context['monthly_payment'] return render(request, "property/calculate_compound_interest.html", context)
def get(self, request, *args, **kwargs): tag_views = None property = None top_tags = None try: tag_views = request.user.tagview_set.all().order_by("-count")[:5] except: pass owned = None try: owned = request.user.myproperty.property.all() except: pass if tag_views: top_tags = [x.tag for x in tag_views] property = Property.objects.filter(tag__in=top_tags) if owned: property = property.exclude(pk__in=owned) if property.count() < 10: property = Property.objects.all().order_by("?") if owned: property = Property.exclude(pk__in=owned) property = property[:10] else: property = property.distinct() property = sorted(property, key=lambda x: random.random()) featured_property = list(Property.objects.filter(featured=True)) shuffle(featured_property) #city = City.objects.filter(slug__in = ["abuja" , "lagos" , "ibadan" , "calabar" , "kano","port-harcourt"]).order_by("id") featured_cities = City.objects.filter(slug__in=[ "abuja", "lagos", "ibadan", "calabar", "kano", "port-harcourt" ]).annotate(num_property=Count("property")).order_by("-num_property") cities = City.objects.all().annotate( num_property=Count("property")).order_by("-num_property") context = { "property": property, "top_tags": top_tags, "featured_property": featured_property, "featured_cities": featured_cities, "cities": cities } return render(request, "main/index.html", context)
from property.models import Property from datetime import datetime from django.contrib.auth.models import User Property.objects.all().delete() admin = User.objects.get(pk=1) prop = Property() prop.created_by = admin prop.modified_by = admin prop.created_on = datetime.now() prop.modified_on = datetime.now() prop.name = '11 Hallin Park' prop.type = Property.COTT prop.code = 'N598' prop.start_day = Property.SAT prop.booking_rule = Property.WILL_CON prop.promotion = '' prop.short_description = '<p>Hallin is a beautiful little community in Skye’s north west peninsula of Waternish with unspoilt sea views; north to Ardmore Bay and south to Loch Bay, the inner isles Isay and Mingay and beyond to the western isles.</p>' prop.description = '<p>Hallin is a beautiful little community in Skye’s north west peninsula of Waternish with unspoilt sea views to the north to Ardmore Bay and south to Loch Bay, the inner isles Isay and Mingay and beyond to the western isles.</p><p>This former Hebridean croft has been upgraded to offer comfortable holiday accommodation, including a sun lounge but without losing any of its warmth and charm, and is the perfect place to enjoy the peace and quiet this area offers. The bubbling burn, the birds on the wind, the countryside with its animals and that wonderful sea breeze. It is also the perfect base to explore the island.</p><p>After a days touring, you can enjoy an evening in front of the open fire or better still, a seat in the sun lounge to enjoy the ever changing sea views. With the outstanding craggy coastline and the many glorious sunsets to be enjoyed, 11 Hallin Park is an excellent self catering holiday cottage providing the perfect base from which to explore the magical Isle of Skye.</p>' prop.save() prop = Property() prop.created_by = admin prop.modified_by = admin prop.created_on = datetime.now() prop.modified_on = datetime.now() prop.name = 'Cape Cove' prop.type = Property.LAHS prop.code = 'A902' prop.start_day = Property.FRI prop.booking_rule = Property.WILL_CON
def new(request): user_id = request.session.get('login_email', '') user = get_object_or_404(User, pk=user_id.lower()) if request.method == 'POST': import pprint pprint.pprint(dict(request.POST)) description = request.POST.get('description', '') price = request.POST.get('price', '1') property_tax = request.POST.get('property_tax', '1') property_type = request.POST.get('property_type', '') country = request.POST.get('country', 'CAN') province = request.POST.get('province', 'BC') region = request.POST.get('region', '') city = request.POST.get('city', '') neighborhood = request.POST.get('neighborhood', '') street_address = request.POST.get('street_address', '') postal_code = request.POST.get('postal_code', '') latitude = request.POST.get('latitude', '') longitude = request.POST.get('longitude', '') p = Property(owner=user, creation_stamp=timezone.now(), publish_stamp=None, edit_stamp=timezone.now(), status='U', description=description, price=price, property_tax=property_tax, property_type=property_type, country=country, province=province, region=region, city=city, neighborhood=neighborhood, street_address=street_address, postal_code=postal_code, latitude=latitude, longitude=longitude) p.normalize_fields() p.escape_fields() try: p.full_clean(exclude=['id']) except ValidationError as e: return render( request, 'property/new.html', { 'user': user, 'country_choices': Property.COUNTRIES, 'status_choices': Property.STATUS, 'province_choices': Property.PROVINCES, 'errors': e.message_dict, 'property': p }) p.id = p.generate_id() p.save() return HttpResponseRedirect(reverse('property:edit', args=(p.id, ))) else: return render( request, 'property/new.html', { 'user': user, 'country_choices': Property.COUNTRIES, 'status_choices': Property.STATUS, 'province_choices': Property.PROVINCES, })
def addcontent(request): if request.method == 'POST': form = PropertyForm(request.POST, request.FILES) if form.is_valid(): current_user = request.user data = Property() data.category= form.cleaned_data['category'] data.user_id = current_user.id data.title = form.cleaned_data['title'] data.keywords = form.cleaned_data['keywords'] data.description = form.cleaned_data['description'] data.price = form.cleaned_data['price'] data.square_metre = form.cleaned_data['square_metre'] data.room = form.cleaned_data['room'] data.floor = form.cleaned_data['floor'] data.status = 'New' data.address = form.cleaned_data['address'] data.slug = form.cleaned_data['slug'] data.image = form.cleaned_data['image'] data.detail = form.cleaned_data['detail'] data.save() messages.success(request, "İçerik başarıyla eklendi") return HttpResponseRedirect("/user/contents") else: messages.warning(request, "İçerik eklenmedi" + str(form.errors)) return HttpResponseRedirect("/user/contents") else: form = PropertyForm() category = Category.objects.all() setting = Setting.objects.get(pk=1) context = { 'category': category, 'setting': setting, 'form': form, } return render(request, 'user_addproperty.html', context)
def form_valid(self, form): """ Assign community data inside a transaction object """ with transaction.atomic(): form.instance.author = self.request.user form.instance.save() datatype = DataType( community=form.instance, author=self.request.user, name='Generic', description='Generic post type for community ' + form.instance.name, generic=1) datatype.save() property_title = Property(datatype=datatype, author=self.request.user, name='Title', type=0, generic=1, required=True) property_title.save() property_description = Property(datatype=datatype, author=self.request.user, name='Description', type=0, generic=1, required=True) property_description.save() property_semantic_tag = Property(datatype=datatype, author=self.request.user, name='Semantic Tags', type=0, generic=1, required=True) property_semantic_tag.save() return FormMixin.form_valid(self, form)
def addproperty(request): if request.method == 'POST': form = PropertyForm(request.POST, request.FILES) if form.is_valid(): current_user = request.user data = Property() # model ile baglantl kur data.user_id = current_user.id data.category = form.cleaned_data['category'] data.title = form.cleaned_data['title'] data.keywords = form.cleaned_data['keywords'] data.price = form.cleaned_data['price'] data.floor = form.cleaned_data['floor'] data.room = form.cleaned_data['room'] data.rate = form.cleaned_data['rate'] data.baby_room = form.cleaned_data['square meters'] data.square_metre = form.cleaned_data['square_metre'] data.description = form.cleaned_data['description'] data.image = form.cleaned_data['image'] data.address = form.cleaned_data['address'] data.slug = form.cleaned_data['slug'] data.detail = form.cleaned_data['detail'] data.status = 'False' data.save() # verirabanlna kagdet messages.success(request, 'Your Content Insterted Successfuly') return HttpResponseRedirect('/user/addimage/%s' % data.id) else: messages.success(request, 'Property Form Error :' + str(form.errors)) return HttpResponseRedirect('/user/addproperty') else: category = Category.objects.all() setting = Setting.objects.get(pk=1) form = PropertyForm() context = {'category': category, 'form': form, 'setting': setting} return render(request, 'user_addproperty.html', context)