Skip to content

Commit

Permalink
Merge branch 'master' into pjbummmmmp
Browse files Browse the repository at this point in the history
  • Loading branch information
gvn committed Aug 2, 2018
2 parents f531d50 + c4af8f3 commit fa6045e
Show file tree
Hide file tree
Showing 34 changed files with 473 additions and 323 deletions.
1 change: 1 addition & 0 deletions Pipfile
Expand Up @@ -28,6 +28,7 @@ factory_boy = "*"
Faker = "*"
wagtail-factories = {ref = "1ead51cadaad3b4530ba2197ccf45d2dca87dbdf", git = "https://github.com/mvantellingen/wagtail-factories"}
mezzanine = {ref = "521a98c39bb6351c4b46067069f33caf95fe0a5e", git = "https://github.com/stephenmcd/mezzanine"}
wagtail-inventory = "*"

[dev-packages]
django-debug-toolbar = "*"
Expand Down
42 changes: 28 additions & 14 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Procfile
@@ -1,2 +1,2 @@
release: cd network-api && python ./manage.py migrate --no-input
release: cd network-api && python ./manage.py migrate --no-input && python ./manage.py block_inventory
web: cd network-api && gunicorn networkapi.wsgi:application
3 changes: 3 additions & 0 deletions env.default
Expand Up @@ -55,6 +55,9 @@ CSP_MEDIA_SRC="'self'"
CSP_CHILD_SRC='self' https://www.youtube.com/ https://s3.amazonaws.com/
CSP_FORM_ACTION='self' https://www.mozilla.org/en-US/newsletter/

# TEST ENVIRONMENT VALUES

PETITION_TEST_CAMPAIGN_ID=""

# REVIEW APPS SLACK BOT

Expand Down
Empty file.
18 changes: 18 additions & 0 deletions network-api/networkapi/buyersguide/admin.py
@@ -0,0 +1,18 @@
from wagtail.contrib.modeladmin.options import (
ModelAdmin, modeladmin_register)
from networkapi.buyersguide.models import Product


# Wagtail admin
class WagtailBuyersGuideAdmin(ModelAdmin):
model = Product
menu_label = 'Buyer\'s Guide'
menu_icon = 'pick' # change as required
menu_order = 600 # will put in 3rd place (000 being 1st, 100 2nd)
add_to_settings_menu = False # or True to add your model to the Settings sub-menu
exclude_from_explorer = False # or True to exclude pages of this type from Wagtail's explorer view
list_display = ('name', 'company', 'url',)
search_fields = ('name', 'company')


modeladmin_register(WagtailBuyersGuideAdmin)
5 changes: 5 additions & 0 deletions network-api/networkapi/buyersguide/apps.py
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class BuyersguideConfig(AppConfig):
name = 'buyersguide'
44 changes: 44 additions & 0 deletions network-api/networkapi/buyersguide/factory.py
@@ -0,0 +1,44 @@
import random

from factory import (
DjangoModelFactory,
Faker,
post_generation,
LazyAttribute,
)

from networkapi.utility.faker_providers import ImageProvider
from networkapi.buyersguide.models import Product

Faker.add_provider(ImageProvider)


class ProductFactory(DjangoModelFactory):

class Meta:
model = Product
exclude = (
'product_words'
)

product_words = Faker('words', nb=2)

name = LazyAttribute(lambda o: ' '.join(o.product_words))
company = Faker('company')
blurb = Faker('sentence')
url = Faker('url')
price = random.randint(49, 1500)
camera = Faker('boolean')
microphone = Faker('boolean')
location = Faker('boolean')
need_account = Faker('boolean')
privacy_controls = Faker('boolean')
delete_data = Faker('boolean')
share_data = Faker('boolean')
child_rules = Faker('boolean')
privacy_policy = Faker('url')
worst_case = Faker('sentence')

@post_generation
def set_image(self, create, extracted, **kwargs):
self.image.name = Faker('generic_image').generate({})
39 changes: 39 additions & 0 deletions network-api/networkapi/buyersguide/migrations/0001_initial.py
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.13 on 2018-07-27 21:07
from __future__ import unicode_literals

from django.db import migrations, models
import networkapi.buyersguide.models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Product',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(blank='True', help_text='Name of Product', max_length=100)),
('company', models.CharField(blank='True', help_text='Name of Company', max_length=100)),
('blurb', models.TextField(blank='True', help_text='Description of the product', max_length=5000)),
('url', models.URLField(blank='True', help_text='Link to this product page', max_length=2048)),
('price', models.CharField(blank='True', help_text='Price range', max_length=100)),
('image', models.FileField(blank=True, help_text='Image representing this prodct', max_length=2048, upload_to=networkapi.buyersguide.models.get_product_image_upload_path)),
('camera', models.NullBooleanField(help_text='Does this product have or access a camera?')),
('microphone', models.NullBooleanField(help_text='Does this product have or access a microphone?')),
('location', models.NullBooleanField(help_text='Does this product access your location?')),
('need_account', models.NullBooleanField(help_text='Do you need an account to use this product?')),
('privacy_controls', models.NullBooleanField(help_text='Do users have access to privacy controls?')),
('delete_data', models.NullBooleanField(help_text='Can you request data be deleted?')),
('share_data', models.NullBooleanField(help_text='Does the maker share data with other companies?')),
('child_rules', models.NullBooleanField(help_text='Are there rules for children?')),
('privacy_policy', models.URLField(blank='True', help_text='Link to privacy policy for this product', max_length=2048)),
('worst_case', models.CharField(blank='True', help_text="What's the worst thing that could happen by using this product?", max_length=5000)),
],
),
]
Empty file.
90 changes: 90 additions & 0 deletions network-api/networkapi/buyersguide/models.py
@@ -0,0 +1,90 @@
from django.db import models
from networkapi.utility.images import get_image_upload_path
# from wagtail.snippets.models import register_snippet


def get_product_image_upload_path(instance, filename):
return get_image_upload_path(
app_name='buyersguide',
prop_name='name',
instance=instance,
current_filename=filename
)


class Product(models.Model):
"""
A thing you can buy in stores and our review of it
"""

name = models.CharField(
max_length=100,
help_text='Name of Product',
blank="True",
)
company = models.CharField(
max_length=100,
help_text='Name of Company',
blank="True",
)

blurb = models.TextField(
max_length=5000,
help_text='Description of the product',
blank="True"
)
url = models.URLField(
max_length=2048,
help_text='Link to this product page',
blank="True",
)
price = models.CharField(
max_length=100,
help_text='Price range',
blank="True",
)
image = models.FileField(
max_length=2048,
help_text='Image representing this prodct',
upload_to=get_product_image_upload_path,
blank=True,
)
camera = models.NullBooleanField(
help_text='Does this product have or access a camera?',
)
microphone = models.NullBooleanField(
help_text='Does this product have or access a microphone?',
)
location = models.NullBooleanField(
help_text='Does this product access your location?',
)
need_account = models.NullBooleanField(
help_text='Do you need an account to use this product?',
)
privacy_controls = models.NullBooleanField(
help_text='Do users have access to privacy controls?',
)
delete_data = models.NullBooleanField(
help_text='Can you request data be deleted?',
)
share_data = models.NullBooleanField(
help_text='Does the maker share data with other companies?',
)
child_rules = models.NullBooleanField(
help_text='Are there rules for children?',
)
privacy_policy = models.URLField(
help_text='Link to privacy policy for this product',
max_length=2048,
blank="True",
)
worst_case = models.CharField(
max_length=5000,
help_text="What's the worst thing that could happen by using this product?",
blank="True",
)

# objects = HighlightQuerySet.as_manager()

def __str__(self):
return str(self.name)
@@ -0,0 +1,5 @@
Buyer's guide homepage!

{% for product in products %}
<div><a href="{{product.name | urlencode}}">{{product.name}}</a></div>
{% endfor %}
19 changes: 19 additions & 0 deletions network-api/networkapi/buyersguide/templates/product_page.html
@@ -0,0 +1,19 @@
<h2>{{product.name}}</h2>

<img src="{{mediaUrl}}{{product.image}}" width="500"/>
<div>
{{product.company}}
</div>
<div>{{product.blurb}}</div>
<div>{{product.url}}</div>
<div>{{product.price}}</div>
<div>Camera: {{product.camera}}</div>
<div>Microphone: {{product.microphone}}</div>
<div>Location: {{product.location}}</div>
<div>Need account: {{product.need_account}}</div>
<div>Privacy Controls: {{product.privacy_controls}}</div>
<div>Delete Data: {{product.delete_data}}</div>
<div>Share Data: {{product.share_data}}</div>
<div>Child rules: {{product.child_rules}}</div>
<div>Privacy Policy: {{product.privacy_policy}}</div>
<div>Worst case scenario: {{product.worst_case}}</div>
3 changes: 3 additions & 0 deletions network-api/networkapi/buyersguide/tests.py
@@ -0,0 +1,3 @@
# from django.test import TestCase

# Create your tests here.
8 changes: 8 additions & 0 deletions network-api/networkapi/buyersguide/urls.py
@@ -0,0 +1,8 @@
from django.conf.urls import url
from networkapi.buyersguide import views


urlpatterns = [
url(r'^$', views.buyersguide_home, name='buyersguide-home'),
url(r'^(?P<productname>[\w\ ]+)/', views.product_view, name='product-view'),
]
18 changes: 18 additions & 0 deletions network-api/networkapi/buyersguide/views.py
@@ -0,0 +1,18 @@
from django.shortcuts import render
from networkapi.buyersguide.models import Product
from django.contrib.auth.decorators import login_required
from django.conf import settings


# Login required so we can continue to develop this and merge into master without the public seeing it.
# Remove this when we're ready to launch.
@login_required
def buyersguide_home(request):
products = Product.objects.all()
return render(request, 'buyersguide_home.html', {'products': products})


@login_required
def product_view(request, productname):
product = Product.objects.get(name__iexact=productname)
return render(request, 'product_page.html', {'product': product, 'mediaUrl': settings.MEDIA_URL})
4 changes: 4 additions & 0 deletions network-api/networkapi/management/commands/flush_models.py
Expand Up @@ -12,6 +12,7 @@
InternetHealthIssue,
)
from networkapi.wagtailpages.models import CTA
from networkapi.buyersguide.models import Product


class Command(BaseCommand):
Expand Down Expand Up @@ -45,4 +46,7 @@ def handle(self, *args, **options):
self.stdout.write('Dropping all Pages')
Page.objects.exclude(title='Root').delete()

self.stdout.write('Dropping all Products')
Product.objects.all().delete()

self.stdout.write(self.style.SUCCESS('Done!'))

0 comments on commit fa6045e

Please sign in to comment.