This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="cart"> | |
{% with total_items=cart|length %} | |
{% if cart|length > 0 %} | |
Ваша корзина: | |
<a href="{% url "cart:CartDetail" %}"> | |
{{ total_items }} тов. {{ cart.get_total_price }} руб. | |
</a> | |
{% else %} | |
Корзина пустая | |
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# промежуточный класс для перенправления незарегистрированного пользователя на страницу входа | |
import re | |
from django.conf import settings | |
from django.shortcuts import redirect | |
from django.contrib.auth import logout | |
from django.urls import reverse | |
EXEMPT_URLS = [re.compile(settings.LOGIN_URL.lstrip('/'))] | |
if hasattr(settings, 'LOGIN_EXEMPT_URLS'): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib.auth.forms import PasswordResetForm | |
class MailCheckPasswordResetForm(PasswordResetForm): | |
email = forms.EmailField(max_length=254) | |
error_messages = { | |
'unknown': _("That email address doesn't have an associated " | |
"user account. Are you sure you've registered?"), | |
'unusable': _("The user account associated with this email " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { | |
// Smooth Scrolling | |
$('a[href*="#"]:not([href="#"])').click(function() { | |
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { | |
var target = $(this.hash); | |
target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); | |
if (target.length) { | |
$('html, body').animate({ | |
scrollTop: target.offset().top | |
}, 1000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function m(value) { | |
//$r = $(".s-how-to-order").animated('fadeInUp', 'fadeOutDown'); | |
var inEffect = "fadeInUp" | |
var outEffect = "fadeOutDown" | |
var $r = $(value); | |
$r.css("opacity", "0").addClass("animated").waypoint(function (dir) { | |
if (dir == 'down') { | |
$r.removeClass(outEffect).addClass(inEffect).css("opacity", "1"); | |
} else { | |
$r.removeClass(inEffect).addClass(outEffect).css("opacity", "1"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1st | |
import string | |
import random | |
def pw_gen(size = 8, chars=string.ascii_letters + string.digits + string.punctuation): | |
return ''.join(random.choice(chars) for _ in range(size)) | |
print(pw_gen(int(input('How many characters in your password?')))) | |
#2nd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% for article in articles %} | |
{% include 'articles/partial/partial_article.html' %} | |
{% empty %} | |
<h1>Nothing to show</h1> | |
{% endfor %} | |
<!-- Pagination --> | |
{% if articles.has_other_pages %} | |
<div class="text-center"> | |
<ul class="pagination pagination-lg text-center"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# utils/models.py | |
# -*- coding: UTF-8 -*- | |
from __future__ import unicode_literals | |
from django.db import models | |
from django.utils.translation import ugettext_lazy as _ | |
from django.template.defaultfilters import escape | |
from django.utils.safestring import mark_safe | |
class MetaTagsMixin(models.Model): | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The following is an example of how to use two generic relationships in your app (put | |
# this code in demo_app/models.py), as shown in the following: | |
# demo_app/models.py | |
# -*- coding: UTF-8 -*- | |
from __future__ import nicode_literals | |
from django.db import models | |
from utils.models import object_relation_mixin_factory | |
from django.utils.encoding import python_2_unicode_compatible | |
FavoriteObjectMixin = object_relation_mixin_factory( is_required=True,) | |
OwnerMixin = object_relation_mixin_factory( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.conf import settings | |
from django.contrib.gis.geoip2 import GeoIP2 | |
GEO_DEFAULT_IP = getattr(settings, 'GEO_DEFAULT_IP', '72.14.207.99') | |
def get_client_ip(request): | |
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR') | |
if x_forwarded_for is not None: | |
ip = x_forwarded_for.split(',')[0] | |
else: |
OlderNewer