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
$(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
# 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
# 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
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: |
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 celery.schedules import crontab | |
from services import crawlers | |
from celery.task.base import periodic_task | |
from celery.utils.log import get_task_logger | |
logger = get_task_logger(__name__) | |
@periodic_task(run_every=(crontab(hour="*", minute="*", day_of_week="*"))) | |
def update_githab(): | |
# logger.info("Start task") |
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 hidden_field in form.hidden_fields() %} | |
{{ hidden_field }} | |
{% endfor %} | |
{% if form.non_field_errors %} | |
{% for error in form.non_field_errors() %} | |
{{ error }} | |
{% endfor %} | |
{% 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
<!-- With bootstrap accordeon for category's children --> | |
<ul class="categories"> | |
<li> | |
<form id="all_categories_form" action="{{ url('articles:home') }}" method="get"> | |
<input type="hidden" name="is_clear" value="True"> | |
<a href="#" onclick="document.getElementById('all_categories_form').submit();">All</a> | |
</form> | |
</li> |
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
class ArticleForm(TranslatableModelForm): | |
title = TranslatedField() | |
short_description = TranslatedField( | |
label=_('Short description'), | |
required=False, | |
help_text=_("You can use html tags for short description. Max length: 1000 characters.")) | |
content = TranslatedField( | |
label=_('Content'), | |
form_class=forms.CharField, | |
widget=TinyMCE, |
OlderNewer