Merge branch 'develop' of git.general-servers.com:expomap/expomap into services

remotes/origin/1203
Ivan Kovalkovskyi 10 years ago
commit 1a3502be33
  1. 2
      article/models.py
  2. 51
      city/management/commands/update_hotels_currency.py
  3. 68
      city/management/commands/update_hotels_price.py
  4. 4
      city/models.py
  5. 2
      templates/client/article/article.html
  6. 2
      templates/client/includes/article/blog_list.html
  7. 16
      templates/client/includes/booking_block.html
  8. 2
      templates/client/includes/conference/conference_object.html
  9. 2
      templates/client/includes/exposition/exposition_object.html

@ -123,7 +123,7 @@ class Article(TranslatableModel):
files = generic.GenericRelation('file.FileModel', content_type_field='content_type', object_id_field='object_id') files = generic.GenericRelation('file.FileModel', content_type_field='content_type', object_id_field='object_id')
class Meta: class Meta:
ordering = ['-created'] ordering = ['-publish_date']
def __unicode__(self): def __unicode__(self):
return self.lazy_translation_getter('main_title', self.pk) return self.lazy_translation_getter('main_title', self.pk)

@ -0,0 +1,51 @@
import urllib2, base64
import json
from django.core.management.base import BaseCommand, CommandError
from city.models import Hotel
HOTEL_URL = 'https://distribution-xml.booking.com/json/bookings.getHotels?'
username = 'expomap'
password = '33xp00m33p'
def handle_hotels(hotel_ids):
good_hotels = []
hotel_ids_str = ','.join(hotel_ids)
new_url = HOTEL_URL + 'hotel_ids=%s'%hotel_ids_str
request = urllib2.Request(new_url)
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)
try:
response = urllib2.urlopen(request)
code = response.getcode()
except urllib2.HTTPError, e:
code = e.code
except urllib2.URLError, e:
code = e.code
json_hotels = response.read()
hotels = json.loads(json_hotels)
for item in hotels:
id = item['hotel_id']
currency = item['currencycode']
Hotel.objects.filter(id=id).update(currency=currency)
good_hotels.append(id)
bad_hotels = list(set(hotel_ids) - set(good_hotels))
Hotel.objects.filter(id__in=bad_hotels).delete()
print('success update currency in %d hotels'%len(good_hotels))
def main():
hotels_todo = Hotel.objects.filter(currency__isnull=True)[:100].count()
while hotels_todo > 0:
hotel_ids = [str(item.id) for item in list(Hotel.objects.filter(currency__isnull=True)[:100])]
handle_hotels(hotel_ids)
hotels_todo =Hotel.objects.filter(currency__isnull=True)[:100].count()
class Command(BaseCommand):
def handle(self, *args, **options):
main()

@ -0,0 +1,68 @@
import urllib2, base64
import json
from django.core.management.base import BaseCommand, CommandError
from city.models import Hotel
URL = 'https://distribution-xml.booking.com/json/bookings.getRooms?'
username = 'expomap'
password = '33xp00m33p'
test_id = '298239'
def get_prices(rooms):
min_price = None
max_price = None
for room in rooms:
try:
cur_min = float(room.get('min_price'))
except TypeError:
cur_min = None
try:
cur_max = float(room.get('max_price'))
except TypeError:
cur_max = None
if cur_min > min_price:
min_price = cur_min
if cur_max > max_price:
max_price = cur_max
return min_price, max_price
def handle_hotels(hotel_id):
hotel_ids_str = hotel_id
new_url = URL + 'hotel_ids=%s'%hotel_ids_str
request = urllib2.Request(new_url)
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)
try:
response = urllib2.urlopen(request)
code = response.getcode()
except urllib2.HTTPError, e:
code = e.code
except urllib2.URLError, e:
code = e.code
json_rooms = response.read()
rooms = json.loads(json_rooms)
min_price, max_price = get_prices(rooms)
Hotel.objects.filter(id=hotel_id).update(min_price=min_price, max_price=max_price)
print('success')
def main():
hotel_id = test_id
for hotel in Hotel.objects.all():
try:
handle_hotels(str(hotel.id))
except:
continue
#hotels_todo = Hotel.objects.filter(currency__isnull=True)[:100].count()
#while hotels_todo > 0:
#hotel_ids = [str(item.id) for item in list(Hotel.objects.filter(currency__isnull=True)[:100])]
#handle_hotels(hotel_ids)
#hotels_todo = Hotel.objects.filter(currency__isnull=True)[:100].count()
class Command(BaseCommand):
def handle(self, *args, **options):
main()

@ -136,6 +136,10 @@ class Hotel(TranslatableModel):
latitude = models.FloatField(blank=True, null=True) latitude = models.FloatField(blank=True, null=True)
longitude = models.FloatField(blank=True, null=True) longitude = models.FloatField(blank=True, null=True)
photo = ImageField(upload_to='hotels') photo = ImageField(upload_to='hotels')
currency = models.CharField(max_length=10)
min_price = models.FloatField(blank=True, null=True)
max_price = models.FloatField(blank=True, null=True)
checked = models.NullBooleanField(blank=True, null=True)
translations = TranslatedFields( translations = TranslatedFields(
name = models.CharField(max_length=255, blank=True), name = models.CharField(max_length=255, blank=True),

@ -19,7 +19,7 @@
{% include 'client/includes/article/article_logo.html' with obj=object %} {% include 'client/includes/article/article_logo.html' with obj=object %}
<h1>{{ object.main_title }}</h1> <h1>{{ object.main_title }}</h1>
<strong><span>{{ object.created|date:"d E Y" }}</span>{% if object.theme.all.exists %}{% include 'includes/article_theme.html' with obj=object %}{% endif %}</strong> <strong><span>{{ object.publish_date|date:"d E Y" }}</span>{% if object.theme.all.exists %}{% include 'includes/article_theme.html' with obj=object %}{% endif %}</strong>
{% if request.user.is_admin %} {% if request.user.is_admin %}
<a target="_blank" class="button green " href="/admin/article/blog/{{ object.slug }}/">{% trans 'изменить' %}</a> <a target="_blank" class="button green " href="/admin/article/blog/{{ object.slug }}/">{% trans 'изменить' %}</a>
{% endif %} {% endif %}

@ -7,7 +7,7 @@
{% include 'includes/article/article_preview.html' with obj=blog %} {% include 'includes/article/article_preview.html' with obj=blog %}
<h3><a href="{{ blog.get_permanent_url }}" title="">{{ blog.main_title }}</a></h3> <h3><a href="{{ blog.get_permanent_url }}" title="">{{ blog.main_title }}</a></h3>
{{ blog.preview|safe }} {{ blog.preview|safe }}
<strong><span>{{ blog.created|date:"d E Y" }}</span>{% if blog.tag.all.exists %}{% include 'includes/article_tags.html' with obj=blog %}{% endif %}</strong> <strong><span>{{ blog.publish_date|date:"d E Y" }}</span>{% if blog.tag.all.exists %}{% include 'includes/article_tags.html' with obj=blog %}{% endif %}</strong>
</div> </div>
</div> </div>
{% if forloop.counter == 5 or objects|length < 5 %} {% if forloop.counter == 5 or objects|length < 5 %}

@ -25,8 +25,10 @@
</span> </span>
<span class="hb-link">{{ hotel.name }}</span> <span class="hb-link">{{ hotel.name }}</span>
</a> </a>
<!--<div class="hb-price">6 500 руб./ночь</div>--> {% if hotel.min_price %}
<a class="button blue2 lc icon-bell" href="{{ hotel.url }}?aid={{ book_aid }}" target="_blank">Забронировать</a> <div class="hb-price">{{ hotel.min_price|floatformat:0 }} {{ hotel.currency }}/{% trans 'ночь' %}</div>
{% endif %}
<a class="button blue2 lc icon-bell" href="{{ hotel.url }}?aid={{ book_aid }}" target="_blank">{% trans 'Забронировать' %}</a>
</div> </div>
</li> </li>
{% endfor %} {% endfor %}
@ -40,11 +42,13 @@
<img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}"> <img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}">
{% endthumbnail %} {% endthumbnail %}
</span> </span>
{{ hotel.name }} <span class="hb-link">{{ hotel.name }}</span>
</a> </a>
<div class="hb-price">&nbsp;</div>
<!--<div class="hb-price">6 500 руб./ночь</div>--> {% if hotel.min_price %}
<a class="button blue2 lc icon-bell" href="{{ hotel.url }}?aid={{ book_aid }}" target="_blank">Забронировать</a> <div class="hb-price">{{ hotel.min_price|floatformat:0 }} {{ hotel.currency }}/{% trans 'ночь' %}</div>
{% endif %}
<a class="button blue2 lc icon-bell" href="{{ hotel.url }}?aid={{ book_aid }}" target="_blank">{% trans 'Забронировать' %}</a>
</div> </div>
</li> </li>
{% endfor %} {% endfor %}

@ -91,7 +91,7 @@
<a class="button green " href="/admin/conference/{{ object.url }}/">{% trans 'изменить' %}</a> <a class="button green " href="/admin/conference/{{ object.url }}/">{% trans 'изменить' %}</a>
{% endif %} {% endif %}
</div> </div>
<div class="ib-add"><a class="button blue2 icon-find" href="http://www.booking.com/searchresults.html?aid={{ book_aid }}&city={{ object.city.id }}">{% trans 'Найти отель' %}</a></div> <div class="ib-add"><a target="_blank" class="button blue2 icon-find" href="http://www.booking.com/searchresults.html?aid={{ book_aid }}&city={{ object.city.id }}">{% trans 'Найти отель' %}</a></div>
</div> </div>
<hr /> <hr />
<div class="i-divs clearfix"> <div class="i-divs clearfix">

@ -95,7 +95,7 @@
<a target="_blank" class="button green " href="/admin/exposition/{{ object.url }}/">{% trans 'изменить' %}</a> <a target="_blank" class="button green " href="/admin/exposition/{{ object.url }}/">{% trans 'изменить' %}</a>
{% endif %} {% endif %}
</div> </div>
<div class="ib-add"><a class="button blue2 icon-find" href="http://www.booking.com/searchresults.html?aid={{ book_aid }}&city={{ object.city.id }}">{% trans 'Найти отель' %}</a></div> <div class="ib-add"><a target="_blank" class="button blue2 icon-find" href="http://www.booking.com/searchresults.html?aid={{ book_aid }}&city={{ object.city.id }}">{% trans 'Найти отель' %}</a></div>
</div> </div>
<hr /> <hr />
<div class="i-divs clearfix"> <div class="i-divs clearfix">

Loading…
Cancel
Save