Skip to content

Commit

Permalink
Setting purchase is optional
Browse files Browse the repository at this point in the history
The author can decide whether to charge at all and can turn off the
"buy" button.
  • Loading branch information
turukawa committed Feb 26, 2015
1 parent c73a29c commit 47ca94d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
20 changes: 20 additions & 0 deletions whyqd/novel/migrations/0003_novel_show_charge.py
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('novel', '0002_token_stripe_id'),
]

operations = [
migrations.AddField(
model_name='novel',
name='show_charge',
field=models.BooleanField(default=True),
preserve_default=True,
),
]
19 changes: 19 additions & 0 deletions whyqd/novel/migrations/0004_auto_20150226_1256.py
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('novel', '0003_novel_show_charge'),
]

operations = [
migrations.RenameField(
model_name='novel',
old_name='show_charge',
new_name='show_buy',
),
]
1 change: 1 addition & 0 deletions whyqd/novel/models/novels.py
Expand Up @@ -80,6 +80,7 @@ class Novel(models.Model):
ebook_mobi = models.FileField(upload_to=get_ebookname, blank=True)
ebook_pdf = models.FileField(upload_to=get_ebookname, blank=True)
ebook_azw = models.FileField(upload_to=get_ebookname, blank=True)
show_buy = models.BooleanField(default=True)
defaultcurrency = models.CharField(max_length=7, choices=CURRENCY_CHOICE, default="gbp")
defaultprice = models.DecimalField(max_digits=10, decimal_places=2, default=Decimal('0.00'))
discountvolume = models.IntegerField(blank=True, null=True)
Expand Down
3 changes: 3 additions & 0 deletions whyqd/novel/views.py
Expand Up @@ -50,6 +50,9 @@ def view_chapters(request, surl, template_name="novel/view_chapters.html"):
show_buy = False
elif can_read != "borrowed" and request.user.current_price > page_price:
page_price = request.user.current_price
if not novel_object.show_buy:
show_buy = False
can_read = True
return render(request, template_name, locals())

def buy_novel(request, surl=None, template_name="novel/buy_novel.html"):
Expand Down
8 changes: 6 additions & 2 deletions whyqd/wiqi/views.py
Expand Up @@ -30,7 +30,9 @@ def index(request, template_name="wiqi/index.html", nav_type="view"):
fx = get_forex()
fxd = settings.DEFAULT_CURRENCY
page_price = novel_object.sentinal.price
show_buy = True
show_buy = False
if novel_object.show_buy:
show_buy = True
if request.user.is_authenticated():
can_read = request.user.can_read(novel_object)
if can_read == "owns":
Expand Down Expand Up @@ -88,7 +90,9 @@ def view_wiqi(request, wiqi_surl, wiqi_type=None, template_name="wiqi/view.html"
fx = get_forex()
fxd = settings.DEFAULT_CURRENCY
page_price = wiqi_object.price
show_buy = True
show_buy = False
if novel_object.show_buy:
show_buy = True
if request.user.is_authenticated():
can_read = request.user.can_read(novel_object)
if can_read == "owns":
Expand Down

0 comments on commit 47ca94d

Please sign in to comment.