add currency model

remotes/origin/mitri4
Dmitriy Shesterkin 9 years ago
parent 3a119728b0
commit 4929c78e47
  1. 5
      batiskaf/jinja2.py
  2. 7
      batiskaf/jinja2_ext/currency.py
  3. 20
      batiskaf/templates/jinja2/base.jinja
  4. 4
      batiskaf/templates/jinja2/index.jinja
  5. 5
      static/js/_.js
  6. 52
      static/less/_.css
  7. 5
      static/less/_.less
  8. 2
      static/less/_.min.css
  9. 8
      static/less/_brand.less
  10. 71
      static/less/components/_navbar.less
  11. 5
      store/admin.py
  12. 20
      store/currency.py
  13. 30
      store/migrations/0056_auto_20170306_1823.py
  14. 35
      store/migrations/0057_auto_20170306_1933.py
  15. 23
      store/models.py

@ -3,9 +3,10 @@ from django.contrib.staticfiles.storage import staticfiles_storage
from django.core.urlresolvers import reverse
from batiskaf.jinja2_ext.thumbnails import thumbnail
from batiskaf.jinja2_ext.cart import cart
from batiskaf.jinja2_ext.currency import currency
from batiskaf.jinja2_ext.html_filters import *
from jinja2 import Environment
from store.models import Category, Brand
from store.models import Category, Brand, Currency
def environment(**options):
@ -15,10 +16,12 @@ def environment(**options):
'url': reverse,
'main_categories': Category.objects.filter(parent__isnull=True).order_by('pk'),
'all_brands': Brand.objects.order_by('title'),
'all_currency': Currency.objects.all(),
})
env.filters['linebreaks'] = linebreaks
env.filters['thumbnail'] = thumbnail
env.filters['cart'] = cart
env.filters['currency'] = currency
env.filters['bootstrap'] = bootstrap
env.filters['bootstrap_inline'] = bootstrap_inline
env.filters['bootstrap_horizontal'] = bootstrap_horizontal

@ -0,0 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from store.currency import Currency
def currency(request):
return Currency(request)

@ -17,7 +17,7 @@
<link href='/static/favicon.ico?v=3' type='image/x-icon' rel='shortcut icon'/>
<link href="/static/bower_components/Bootflat/css/bootstrap.min.css" rel="stylesheet">
<link href="/static/bower_components/Bootflat/bootflat/css/bootflat.min.css" rel="stylesheet">
<link href="/static/less/_.min.css?v=3" rel="stylesheet">
<link href="/static/less/_.css?v=5" rel="stylesheet">
<link href="/static/css/select2.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="/static/bower_components/sweetalert/lib/sweet-alert.css">
<link rel="stylesheet" href="/static/js/mp/dist/magnific-popup.css">
@ -142,9 +142,23 @@
</li>
</ul>
</li>
<li style="background: hsl(36, 100%, 50%)"><a href="/promo/"><span class="lead">Акции</span></a>
</li>
<li style="background: hsl(36, 100%, 50%)"><a href="/promo/"><span class="lead">Акции</span></a></li>
</ul>
<div class="navbar-header dropdown yamm-fw">
<a style="border: none;" class="dropdown-toggle navbar-item__currency" href="#" data-toggle="dropdown">
<span class="currency-icon">&#36;</span>
{# {{ (request|currency) }}#}
</a>
<ul class="dropdown-menu currency-menu" style="min-width: 50px!important;">
<div class="yamm-content">
{% for item in all_currency %}
<li class="currency-item">
<a class="currency-item__link" href="#">{{ item.HTML_letter_code|safe}}</a>
</li>
{% endfor %}
</div>
</ul>
</div>
</div>
</div>
</div>

@ -47,7 +47,11 @@
</a>
</div>
<div class="price">
Валюта &#8376; &#8381; &#36;
{{ product.min_price(request.user) }} ₸
</div>
{% if product.in_stock() %}
<div class="state-yes">

@ -1,6 +1,11 @@
$(document).on('click', '.yamm .dropdown-menu', function (e) {
e.stopPropagation();
});
$(document).on('click', '.navbar-item__currency', function (e) {
e.preventDefault();
});
$(document).ready(function () {
$("#shop-categories").on('affix.bs.affix', function () {
$('.header-middle').css('margin-bottom', $("#shop-categories").css('height'));

@ -312,6 +312,58 @@
.navbar-item__roballen {
background: #027BC1;
}
.navbar-item__currency {
float: left;
height: 50px;
font-size: 14px!important;
width: 34px;
}
.navbar-item__currency:after {
clear: both;
display: table;
content: " ";
}
.open .currency-icon {
background-image: linear-gradient(to bottom, #080808 0%, #0f0f0f 100%);
background-repeat: repeat-x;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff080808', endColorstr='#ff0f0f0f', GradientType=0);
box-shadow: inset 0 3px 9px rgba(0, 0, 0, 0.25);
}
.currency-icon {
display: block;
margin-left: 0;
width: 49px;
text-align: center;
line-height: 50px;
}
.currency-menu {
width: 50px;
left: inherit!important;
margin: 0;
position: absolute;
float: left;
background-color: #434a54;
color: #fff;
border-width: 0 1px 1px;
border-radius: 0 0 2px 2px;
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
}
.currency-menu .yamm-content {
padding: 10px;
}
.currency-item {
margin-bottom: 15px;
text-align: center;
}
.currency-item:last-child {
margin-bottom: 0;
}
.currency-item__link {
display: block;
padding: 0!important;
border: 0!important;
font-size: 14px!important;
}
body {
font-family: "Open Sans", Arial, sans-serif;
}

@ -4,8 +4,9 @@
@import "../bower_components/colors/less/colors.less";
@import "../bower_components/yamm3/yamm/yamm.less";
// include custom style
@import "_brand";
// include components custom style
@import "components/_navbar";
@brand-yellow: #fed000;
@brand-gray: #434a54;

File diff suppressed because one or more lines are too long

@ -1,8 +0,0 @@
@brand-roballen: #027BC1;
@brand-roballen-second: #A4A5A9;
.navbar-item__roballen {
background: @brand-roballen;
}

@ -0,0 +1,71 @@
@brand-roballen: #027BC1;
@brand-roballen-second: #A4A5A9;
.navbar-item__roballen {
background: @brand-roballen;
}
.open .navbar-item__currency {
//color: #fed000 !important;
}
.navbar-item__currency {
float: left;
height: 50px;
font-size: 14px!important;
width: 34px;
&:after {
clear: both;
display: table;
content: " ";
}
}
.open .currency-icon {
background-image: linear-gradient(to bottom, #080808 0%, #0f0f0f 100%);
background-repeat: repeat-x;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff080808', endColorstr='#ff0f0f0f', GradientType=0);
box-shadow: inset 0 3px 9px rgba(0, 0, 0, 0.25);
}
.currency-icon {
display: block;
margin-left: 0;
width: 49px;
text-align: center;
line-height: 50px;
}
.currency-menu {
width: 50px;
left: inherit!important;
margin: 0;
position: absolute;
float: left;
background-color: #434a54;
color: #fff;
border-width: 0 1px 1px;
border-radius: 0 0 2px 2px;
box-shadow: 0 6px 12px rgba(0,0,0,.175);
& .yamm-content {
padding: 10px;
}
}
.currency-item {
&:last-child {
margin-bottom: 0;
}
margin-bottom:15px;
text-align: center;
}
.currency-item__link {
display: block;
padding: 0!important;
border: 0!important;
font-size: 14px!important;
}

@ -133,3 +133,8 @@ class ProductFeedbackAdmin(admin.ModelAdmin):
# class DogAdmin(admin.ModelAdmin):
# list_display = ('name', 'data')
#
@admin.register(Currency)
class CurrencyAdmin(admin.ModelAdmin):
list_display = ('title', 'exchange', 'ISO_letter_code')

@ -0,0 +1,20 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from .models import Currency as CurrencyModel
MAIN_CURRENCY_ID = '1'
class Currency(object):
currency_id = ''
def __init__(self, request):
self.cart_id = request.session.get('currency_id', None)
if not self.currency_id:
self.currency_id = MAIN_CURRENCY_ID
request.session['currency_id'] = MAIN_CURRENCY_ID

@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.3 on 2017-03-06 18:23
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('store', '0055_auto_20170224_1244'),
]
operations = [
migrations.CreateModel(
name='Currency',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=25, verbose_name='Название')),
('exchange', models.FloatField(verbose_name='Курс, KZT/ед.')),
('abridgement', models.CharField(max_length=25, verbose_name='Сокращенное название')),
('ISO_letter_code', models.CharField(help_text='Например: KZT, USD, RUB', max_length=3, verbose_name='Буквенный код')),
('HTML_letter_code', models.CharField(help_text='Код в HTML для вывода в шаблонах', max_length=10, verbose_name='HTML код')),
],
options={
'verbose_name': 'валюта',
'verbose_name_plural': 'валюты',
},
)
]

@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations
def create_currency(apps, schema_editor):
Currency = apps.get_model("store", "Currency")
Currency.objects.get_or_create(title="Казахстанский тенге",
exchange=1.00,
abridgement="тенге",
ISO_letter_code="KZT",
HTML_letter_code="&#8376;")
Currency.objects.get_or_create(title="Российский рубль",
exchange=0.18519,
abridgement="руб.",
ISO_letter_code="RUB",
HTML_letter_code="&#8381;")
Currency.objects.get_or_create(title="Доллар США",
exchange=0.00315,
abridgement="доллар",
ISO_letter_code="USD",
HTML_letter_code="&#36;")
class Migration(migrations.Migration):
dependencies = [
('store', '0056_auto_20170306_1823'),
]
operations = [
migrations.RunPython(create_currency)
]

@ -229,8 +229,11 @@ class Product(models.Model):
min_v = v
return min_v
def min_price(self, profile=None):
return self.min_price_variation().get_price(profile)
def min_price(self, profile=None, currency=None):
price = self.min_price_variation().get_price(profile)
if currency:
pass
return price
def is_discount(self):
return self.variations.filter(discount__gt=0).count() > 0
@ -262,6 +265,22 @@ class Product(models.Model):
return retval
class Currency(models.Model):
title = models.CharField('Название', max_length=25)
exchange = models.FloatField('Курс, KZT/ед.')
abridgement = models.CharField('Сокращенное название', max_length=25)
ISO_letter_code = models.CharField('Буквенный код', help_text='Например: KZT, USD, RUB', max_length=3)
HTML_letter_code = models.CharField('HTML код', help_text='Код в HTML для вывода в шаблонах', max_length=10)
class Meta:
verbose_name = 'валюта'
verbose_name_plural = 'валюты'
ordering = ['pk']
def __str__(self):
return self.title
class ProductVariation(models.Model):
product = models.ForeignKey(
Product, verbose_name='Товар', related_name='variations')

Loading…
Cancel
Save