Skip to content

Commit

Permalink
Merge a2ccabd into c7c52f7
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirMakhanov committed Jun 30, 2020
2 parents c7c52f7 + a2ccabd commit 9ebb745
Show file tree
Hide file tree
Showing 24 changed files with 176 additions and 90 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -24,3 +24,4 @@ example/debug/emails/*
!example/debug/emails/.gitkeep
.cache/
htmlcov/
/.idea/
4 changes: 2 additions & 2 deletions affiliate/__init__.py
@@ -1,2 +1,2 @@
__author__ = 'st4lk'
__version__ = '0.4.0'
__author__ = 'st4lk > yoandym'
__version__ = '0.6.0'
3 changes: 2 additions & 1 deletion affiliate/middleware.py
Expand Up @@ -6,6 +6,7 @@
from django.utils import timezone
from django.utils.dateparse import parse_datetime
from django.http import HttpResponseRedirect
from django.utils.deprecation import MiddlewareMixin

from .models import NoAffiliate
from . import utils
Expand Down Expand Up @@ -42,7 +43,7 @@ def get_affiliate(request, new_aid, prev_aid, prev_aid_dt):
return request._cached_affiliate


class AffiliateMiddleware(object):
class AffiliateMiddleware(MiddlewareMixin):

def process_request(self, request):
new_aid, prev_aid, prev_aid_dt = None, None, None
Expand Down
2 changes: 1 addition & 1 deletion affiliate/models.py
Expand Up @@ -19,7 +19,7 @@ def create_affiliate(self, user, **extra_fields):


class AbstractAffiliate(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, verbose_name=_("user"))
user = models.OneToOneField(settings.AUTH_USER_MODEL, verbose_name=_("user"), on_delete=models.CASCADE)
reward_amount = models.DecimalField(_("reward amount"), max_digits=16,
decimal_places=5, default=app_settings.REWARD_AMOUNT)
reward_percentage = models.BooleanField(_('in percent'),
Expand Down
3 changes: 3 additions & 0 deletions example/web_project/apps/__init__.py
@@ -0,0 +1,3 @@
# import users
# import products
# import partner
8 changes: 4 additions & 4 deletions example/web_project/apps/partner/migrations/0001_initial.py
Expand Up @@ -21,7 +21,7 @@ class Migration(migrations.Migration):
('reward_percentage', models.BooleanField(default=True, verbose_name='in percent')),
('is_active', models.BooleanField(default=True, verbose_name='active')),
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='created at')),
('user', models.OneToOneField(verbose_name='User', to=settings.AUTH_USER_MODEL)),
('user', models.OneToOneField(verbose_name='User', to=settings.AUTH_USER_MODEL, on_delete=models.DO_NOTHING)),
],
options={
'abstract': False,
Expand All @@ -39,9 +39,9 @@ class Migration(migrations.Migration):
('reward_percentage', models.BooleanField(default=False)),
('reward', models.DecimalField(max_digits=5, decimal_places=2)),
('created_at', models.DateTimeField(auto_now_add=True)),
('affiliate', models.ForeignKey(to='partner.Affiliate')),
('bought_by', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
('product', models.ForeignKey(to='products.Product')),
('affiliate', models.ForeignKey(to='partner.Affiliate', on_delete=models.DO_NOTHING)),
('bought_by', models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.DO_NOTHING)),
('product', models.ForeignKey(to='products.Product', on_delete=models.DO_NOTHING)),
],
options={
},
Expand Down
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2020-06-29 06:12
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('partner', '0001_initial'),
]

operations = [
migrations.AlterModelOptions(
name='affiliate',
options={'verbose_name': 'affiliate', 'verbose_name_plural': 'affiliates'},
),
migrations.AlterField(
model_name='affiliate',
name='user',
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='user'),
),
]
6 changes: 3 additions & 3 deletions example/web_project/apps/partner/models.py
Expand Up @@ -9,10 +9,10 @@ class Affiliate(AbstractAffiliate):


class AffiliateTransaction(models.Model):
affiliate = models.ForeignKey(Affiliate)
product = models.ForeignKey('products.Product')
affiliate = models.ForeignKey(Affiliate, on_delete=models.DO_NOTHING)
product = models.ForeignKey('products.Product', on_delete=models.DO_NOTHING)
price = models.DecimalField(max_digits=5, decimal_places=2)
bought_by = models.ForeignKey(settings.AUTH_USER_MODEL)
bought_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.DO_NOTHING)
reward_amount = models.DecimalField(max_digits=5, decimal_places=2)
reward_percentage = models.BooleanField(default=False)
reward = models.DecimalField(max_digits=5, decimal_places=2)
Expand Down
11 changes: 5 additions & 6 deletions example/web_project/apps/partner/urls.py
@@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
from django.conf.urls import patterns, url
from django.conf.urls import url
from django.contrib.auth.decorators import login_required
from . import views


urlpatterns = patterns('',
url(r'^$',
login_required(views.AffiliateView.as_view()), name='affiliate'),
)
app_name = 'partner'
urlpatterns = [
url(r'^$', login_required(views.AffiliateView.as_view()), name='affiliate'),
]
8 changes: 4 additions & 4 deletions example/web_project/apps/products/urls.py
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
from django.conf.urls import patterns, url
from django.conf.urls import url
from . import views


urlpatterns = patterns('',
app_name = 'products'
urlpatterns = [
url(r'^$', views.ProductListView.as_view(), name='list'),
)
]
15 changes: 6 additions & 9 deletions example/web_project/apps/users/urls.py
@@ -1,16 +1,13 @@
# -*- coding: utf-8 -*-
from django.conf.urls import patterns, url
from django.conf.urls import url
from django.contrib.auth.views import login, logout
from django.views.generic import TemplateView
from . import views


urlpatterns = patterns('',
url(r'^signin/$', login, name='login',
kwargs={"template_name": "account/login.html"}),
app_name = 'users'
urlpatterns = [
url(r'^signin/$', login, name='login', kwargs={"template_name": "account/login.html"}),
url(r'^signup/$', views.UserCreateView.as_view(), name='signup'),
url(r'^logout_confirm/$',
TemplateView.as_view(template_name='account/logout.html'),
name="logout_confirm"),
url(r'^logout_confirm/$', TemplateView.as_view(template_name='account/logout.html'), name="logout_confirm"),
url(r'^logout/$', logout, name='logout'),
)
]
2 changes: 1 addition & 1 deletion example/web_project/apps/users/views.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from django.views.generic import CreateView
from django.core.urlresolvers import reverse
from django.urls import reverse
from django.contrib.auth import authenticate, login
from django.http import HttpResponseRedirect
from django.contrib.auth import get_user_model
Expand Down
46 changes: 28 additions & 18 deletions example/web_project/config/settings.py
Expand Up @@ -10,6 +10,7 @@

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
import logging
from os.path import join
from django import VERSION as DJANGO_VERSION
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
Expand Down Expand Up @@ -46,6 +47,7 @@
'django.contrib.admin',
'crispy_forms',
'affiliate',
# 'apps',
'apps.users',
'apps.partner',
'apps.products',
Expand All @@ -54,15 +56,15 @@
if DJANGO_VERSION < (1, 7):
INSTALLED_APPS += ('south', )

MIDDLEWARE_CLASSES = (
MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'affiliate.middleware.AffiliateMiddleware',
)
]

ROOT_URLCONF = 'config.urls'

Expand All @@ -87,22 +89,30 @@
}
}

# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.core.context_processors.tz',
'django.contrib.messages.context_processors.messages',
'django.core.context_processors.request',
)

# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
TEMPLATE_DIRS = (
join(BASE_DIR, 'templates'),
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'APP_DIRS': True,
'DIRS': [
join(BASE_DIR, 'templates'),
],
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.request',
]
}
},
]



# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-root
# https://docs.djangoproject.com/en/dev/howto/static-files/
Expand Down Expand Up @@ -223,7 +233,7 @@
'formatter': 'main_formatter',
},
'null': {
"class": 'django.utils.log.NullHandler',
"class": 'logging.NullHandler',
}
},
'loggers': {
Expand Down
15 changes: 8 additions & 7 deletions example/web_project/config/urls.py
Expand Up @@ -2,15 +2,16 @@
from __future__ import unicode_literals

from django.conf import settings
from django.conf.urls import patterns, include, url
from django.conf.urls import include, url
from django.conf.urls.static import static

from django.contrib import admin

admin.autodiscover()

urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^users/', include("apps.users.urls", namespace="users")),
url(r'^partner/', include("apps.partner.urls", namespace="partner")),
url(r'^$', include("apps.products.urls", namespace="products")),
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^users/', include('apps.users.urls')),
url(r'^partner/', include('apps.partner.urls')),
url(r'^$', include('apps.products.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
1 change: 0 additions & 1 deletion example/web_project/templates/account/login.html
@@ -1,6 +1,5 @@
{% extends "base.html" %}
{% load i18n %}
{% load url from future %}
{% load crispy_forms_tags %}
{% load affiliate_tags %}

Expand Down
1 change: 0 additions & 1 deletion example/web_project/templates/account/signup.html
@@ -1,6 +1,5 @@
{% extends "base.html" %}

{% load url from future %}
{% load i18n %}
{% load crispy_forms_tags %}
{% load affiliate_tags %}
Expand Down
1 change: 0 additions & 1 deletion example/web_project/templates/partner/affiliate_base.html
@@ -1,6 +1,5 @@
{% extends "base.html" %}

{% load url from future %}
{% load i18n %}
{% load crispy_forms_tags %}
{% load affiliate_tags %}
Expand Down
2 changes: 2 additions & 0 deletions pytest.ini
@@ -1,2 +1,4 @@
[pytest]
DJANGO_SETTINGS_MODULE = config.settings_test
filterwarnings =
error
6 changes: 5 additions & 1 deletion requirements.txt
@@ -1 +1,5 @@
django>=1.6,<1.9
django>=1.10,<1.11
django-crispy-forms==1.8.1
Pillow==6.2.2
model-mommy==1.6.0

38 changes: 38 additions & 0 deletions requirements_django_110.txt
@@ -0,0 +1,38 @@
appdirs==1.4.4
atomicwrites==1.4.0
attrs==19.3.0
backports.functools-lru-cache==1.6.1
configparser==4.0.2
contextlib2==0.6.0.post1
coverage==5.1
distlib==0.3.1
Django==1.10
-e git+git@github.com:yoandym/django-affiliate.git@c31cf91a707949163feaf0f2a6b844bb4c75e333#egg=django_affiliate
django-crispy-forms==1.8.1
filelock==3.0.12
freezegun==0.3.15
funcsigs==1.0.2
importlib-metadata==1.7.0
importlib-resources==2.0.1
mock==3.0.5
model-mommy==1.6.0
more-itertools==5.0.0
packaging==20.4
pathlib2==2.3.5
Pillow==6.2.2
pluggy==0.13.1
py==1.9.0
pyparsing==2.4.7
pytest==4.6.11
pytest-django==3.9.0
python-dateutil==2.8.1
pytz==2020.1
scandir==1.10.0
singledispatch==3.4.0.3
six==1.15.0
toml==0.10.1
tox==3.16.0
typing==3.7.4.1
virtualenv==20.0.25
wcwidth==0.2.5
zipp==1.2.0

0 comments on commit 9ebb745

Please sign in to comment.