Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promo master #37

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
23 changes: 23 additions & 0 deletions oscar_promotions/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.contrib import admin
from oscar.core.loading import get_model


AutomaticProductList = get_model('oscar_promotions', 'AutomaticProductList')
HandPickedProductList = get_model('oscar_promotions', 'HandPickedProductList')
Image = get_model('oscar_promotions', 'Image')
Expand All @@ -11,6 +12,7 @@
RawHTML = get_model('oscar_promotions', 'RawHTML')
SingleProduct = get_model('oscar_promotions', 'SingleProduct')
TabbedBlock = get_model('oscar_promotions', 'TabbedBlock')
TimeBasedPromotion = get_model('oscar_promotions', 'TimeBasedPromotion')


class OrderProductInline(admin.TabularInline):
Expand All @@ -31,6 +33,26 @@ class KeywordPromotionAdmin(admin.ModelAdmin):
readonly_fields = ['clicks']


class TimeBasedPromotionOptions(admin.ModelAdmin):
list_display = ('title', 'available_since_date', 'available_since_time', 'available_until_date',
'available_until_time', 'enabled')
list_filter = ('enabled',)

actions = ['enable', 'disable']

def disable(self, request, queryset):
rows_updated = queryset.update(enabled=False)
self.message_user(request, "%s desactivadas exitosamente." % rows_updated)

disable.short_description = "Desactivar las promociones seleccionadas"

def enable(self, request, queryset):
rows_updated = queryset.update(enabled=True)
self.message_user(request, "%s activadas exitosamente." % rows_updated)

enable.short_description = "Habilitar las promociones seleccionadas"


admin.site.register(Image)
admin.site.register(MultiImage)
admin.site.register(RawHTML)
Expand All @@ -40,3 +62,4 @@ class KeywordPromotionAdmin(admin.ModelAdmin):
admin.site.register(PagePromotion, PagePromotionAdmin)
admin.site.register(KeywordPromotion, KeywordPromotionAdmin)
admin.site.register(SingleProduct)
admin.site.register(TimeBasedPromotion, TimeBasedPromotionOptions)
2 changes: 0 additions & 2 deletions oscar_promotions/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class PromotionsConfig(OscarConfig):

def ready(self):
super().ready()
self.home_view = get_class('oscar_promotions.views', 'HomeView', module_prefix='oscar_promotions')
self.record_click_view = get_class(
'oscar_promotions.views', 'RecordClickView', module_prefix='oscar_promotions'
)
Expand All @@ -33,6 +32,5 @@ def get_urls(self):
self.record_click_view.as_view(model=KeywordPromotion),
name='keyword-click',
),
url(r'^$', self.home_view.as_view(), name='home'),
]
return self.post_process_urls(urls)
4 changes: 2 additions & 2 deletions oscar_promotions/dashboard/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class PromotionsDashboardConfig(OscarDashboardConfig):
name = 'oscar_promotions.dashboard'
namespace = 'oscar_promotions_dashboard'
verbose_name = _("Promotions dashboard")
default_permissions = ['is_staff']
default_permissions = ['is_staff', 'partner.dashboard_access']

# Dynamically set the CRUD views for all promotion classes
view_names = (
Expand Down Expand Up @@ -55,7 +55,7 @@ def get_urls(self):
url(r'^$', self.list_view.as_view(), name='promotion-list'),
url(r'^pages/$', self.page_list.as_view(), name='promotion-list-by-page'),
url(
r'^page/-(?P<path>/([\w-]+(/[\w-]+)*/)?)$',
r'^page/-(?P<path>/(([\w-]|\s)+(/([\w-]|\s)+)*/)?)$',
self.page_detail.as_view(),
name='promotion-list-by-url',
),
Expand Down
17 changes: 14 additions & 3 deletions oscar_promotions/dashboard/forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from django import forms
from django.contrib.sites.models import Site
from django.utils.translation import gettext_lazy as _
from django.forms import SelectMultiple
from oscar.core.loading import get_class, get_model
from oscar.forms.fields import ExtendedURLField

Expand All @@ -26,7 +28,7 @@ class PromotionTypeSelectForm(forms.Form):
class RawHTMLForm(forms.ModelForm):
class Meta:
model = RawHTML
fields = ['name', 'body']
fields = ['name', 'body', 'site']

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand All @@ -36,14 +38,14 @@ def __init__(self, *args, **kwargs):
class SingleProductForm(forms.ModelForm):
class Meta:
model = SingleProduct
fields = ['name', 'product', 'description']
fields = ['name', 'product', 'description', 'site']
widgets = {'product': ProductSelect}


class HandPickedProductListForm(forms.ModelForm):
class Meta:
model = HandPickedProductList
fields = ['name', 'description', 'link_url', 'link_text']
fields = ['name', 'description', 'link_url', 'link_text', 'site']


class OrderedProductForm(forms.ModelForm):
Expand Down Expand Up @@ -79,3 +81,12 @@ def clean_page_url(self):
page_url += '/'

return page_url


class PromotionsSearchForm(forms.Form):

sites_choices = (('', '---------'),) + tuple([(k, v) for k, v in Site.objects.all().values_list("id", "name")])
sites = forms.MultipleChoiceField(
choices=sites_choices, label=_("Site"), required=False,
widget=SelectMultiple(attrs={'data-multiple': 'true'})
)
35 changes: 30 additions & 5 deletions oscar_promotions/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from oscar_promotions import app_settings
from oscar_promotions.conf import PROMOTION_CLASSES
from oscar_promotions.dashboard.forms import PromotionsSearchForm

AutomaticProductList = get_model('oscar_promotions', 'AutomaticProductList')
HandPickedProductList = get_model('oscar_promotions', 'HandPickedProductList')
Expand All @@ -35,6 +36,8 @@


class ListView(generic.TemplateView):
form = None
form_class = PromotionsSearchForm
template_name = 'oscar_promotions/dashboard/promotion_list.html'

def get_context_data(self):
Expand All @@ -44,16 +47,38 @@ def get_context_data(self):
num_promotions = 0
for klass in PROMOTION_CLASSES:
objects = klass.objects.all()
objects = self.apply_search(objects)
num_promotions += objects.count()
data.append(objects)
promotions = itertools.chain(*data)
ctx = {
'num_promotions': num_promotions,
'promotions': promotions,
'select_form': SelectForm(),
'form': self.form
}
return ctx

def apply_search(self, queryset):
"""
Search through the filtered queryset.

We must make sure that we don't return search results that the user is not allowed
to see (see filter_queryset).
"""
self.form = self.form_class(self.request.GET)

if not self.form.is_valid():
return queryset

data = self.form.cleaned_data

site_list = data.get("sites", [])
if len(site_list) > 0:
queryset = queryset.filter(site_id__in=site_list)

return queryset


class CreateRedirectView(generic.RedirectView):
permanent = True
Expand Down Expand Up @@ -171,18 +196,18 @@ class CreateSingleProductView(CreateView):

class CreateImageView(CreateView):
model = Image
fields = ['name', 'link_url', 'image']
fields = ['name', 'link_url', 'image', 'site']


class CreateMultiImageView(CreateView):
model = MultiImage
fields = ['name']
fields = ['name', 'site']


class CreateAutomaticProductListView(CreateView):
model = AutomaticProductList
fields = ['name', 'description', 'link_url', 'link_text', 'method',
'num_products']
'num_products', 'site']


class CreateHandPickedProductListView(CreateView):
Expand Down Expand Up @@ -290,12 +315,12 @@ class UpdateSingleProductView(UpdateView):

class UpdateImageView(UpdateView):
model = Image
fields = ['name', 'link_url', 'image']
fields = ['name', 'link_url', 'image', 'site']


class UpdateMultiImageView(UpdateView):
model = MultiImage
fields = ['name', 'images']
fields = ['name', 'images', 'site']


class UpdateAutomaticProductListView(UpdateView):
Expand Down
24 changes: 24 additions & 0 deletions oscar_promotions/migrations/0002_auto_20150604_1450.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

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

operations = [
migrations.AlterField(
model_name='handpickedproductlist',
name='products',
field=models.ManyToManyField(to='catalogue.Product', verbose_name='Products', through='oscar_promotions.OrderedProduct', blank=True),
),
migrations.AlterField(
model_name='multiimage',
name='images',
field=models.ManyToManyField(help_text='Choose the Image content blocks that this block will use. (You may need to create some first).', to='oscar_promotions.Image', blank=True),
),
]
29 changes: 29 additions & 0 deletions oscar_promotions/migrations/0003_timebasedpromotion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.12 on 2018-02-07 15:45
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('oscar_promotions', '0002_auto_20150604_1450'),
]

operations = [
migrations.CreateModel(
name='TimeBasedPromotion',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=50)),
('description', models.CharField(max_length=100)),
('available_since_date', models.DateField(blank=True, null=True)),
('available_since_time', models.TimeField()),
('available_until_date', models.DateField(blank=True, null=True)),
('available_until_time', models.TimeField()),
('promotional_code', models.CharField(max_length=50, blank=True, null=True)),
('link', models.CharField(blank=True, max_length=200, null=True)),
],
),
]
20 changes: 20 additions & 0 deletions oscar_promotions/migrations/0004_timebasedpromotion_enabled.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.12 on 2018-03-07 19:51
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('oscar_promotions', '0003_timebasedpromotion'),
]

operations = [
migrations.AddField(
model_name='timebasedpromotion',
name='enabled',
field=models.BooleanField(default=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.12 on 2018-06-27 03:36
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('oscar_promotions', '0004_timebasedpromotion_enabled'),
]

operations = [
migrations.AddField(
model_name='timebasedpromotion',
name='call_to_action',
field=models.CharField(blank=True, max_length=200, null=True),
),
]
20 changes: 20 additions & 0 deletions oscar_promotions/migrations/0006_auto_20180706_1322.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.12 on 2018-07-06 17:22
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('oscar_promotions', '0005_timebasedpromotion_call_to_action'),
]

operations = [
migrations.AlterField(
model_name='timebasedpromotion',
name='promotional_code',
field=models.CharField(blank=True, max_length=50, null=True),
),
]
27 changes: 27 additions & 0 deletions oscar_promotions/migrations/0007_imageextrainfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.14 on 2018-12-14 15:14
from __future__ import unicode_literals

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


class Migration(migrations.Migration):

dependencies = [
('oscar_promotions', '0006_auto_20180706_1322'),
]

operations = [
migrations.CreateModel(
name='ImageExtraInfo',
fields=[
('description', models.TextField(verbose_name='Description for mobile view')),
('image', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='extra_info', serialize=False, to='oscar_promotions.Image')),
],
options={
'verbose_name': 'ImageExtraInfo',
'verbose_name_plural': 'ImageExtraInfo',
},
),
]
27 changes: 27 additions & 0 deletions oscar_promotions/migrations/0008_auto_20190802_1149.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.17 on 2019-08-02 15:49
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('oscar_promotions', '0007_imageextrainfo'),
]

operations = [
migrations.RemoveField(
model_name='imageextrainfo',
name='image',
),
migrations.AddField(
model_name='timebasedpromotion',
name='icon_name',
field=models.CharField(blank=True, max_length=30, null=True),
),
migrations.DeleteModel(
name='ImageExtraInfo',
),
]
Loading