ebook files activate and deactivate
when manager unselects 'add_ask', the system didn't revert to the files without added ask. This fixes that. To test, toggle the add_ask checkbox and save campaign.pull/1/head
parent
0ddbdbc944
commit
ef6c4a659e
|
@ -948,7 +948,7 @@ class Campaign(models.Model):
|
|||
done_formats.append('epub')
|
||||
except Exception as e:
|
||||
logger.error("error making epub ask %s" % (e))
|
||||
self.work.make_ebooks_from_ebfs()
|
||||
self.work.make_ebooks_from_ebfs(add_ask=True)
|
||||
|
||||
|
||||
|
||||
|
@ -1239,25 +1239,37 @@ class Work(models.Model):
|
|||
def pdffiles(self):
|
||||
return EbookFile.objects.filter(edition__work=self, format='pdf').exclude(file='').order_by('-created')
|
||||
|
||||
def make_ebooks_from_ebfs(self):
|
||||
def make_ebooks_from_ebfs(self, add_ask=True):
|
||||
if self.last_campaign().type != THANKS: # just to make sure that ebf's can be unglued by mistake
|
||||
return
|
||||
ebfs=EbookFile.objects.filter(edition__work=self).exclude(file='').order_by('-created')
|
||||
done_formats= []
|
||||
for ebf in ebfs:
|
||||
previous_ebooks=Ebook.objects.filter(url= ebf.file.url,)
|
||||
try:
|
||||
previous_ebook = previous_ebooks[0]
|
||||
for eb in previous_ebooks[1:]: #housekeeping
|
||||
eb.deactivate()
|
||||
except IndexError:
|
||||
previous_ebook = None
|
||||
|
||||
if ebf.format not in done_formats:
|
||||
ebook=Ebook.objects.get_or_create(
|
||||
edition=ebf.edition,
|
||||
format=ebf.format,
|
||||
rights=self.last_campaign().license,
|
||||
provider="Unglue.it",
|
||||
url= ebf.file.url,
|
||||
)
|
||||
done_formats.append(ebf.format)
|
||||
else:
|
||||
obsolete=Ebook.objects.filter(url= ebf.file.url,)
|
||||
for eb in obsolete:
|
||||
eb.deactivate()
|
||||
if ebf.asking==add_ask or ebf.format=='mobi':
|
||||
if previous_ebook:
|
||||
previous_ebook.activate()
|
||||
else:
|
||||
ebook=Ebook.objects.get_or_create(
|
||||
edition=ebf.edition,
|
||||
format=ebf.format,
|
||||
rights=self.last_campaign().license,
|
||||
provider="Unglue.it",
|
||||
url= ebf.file.url,
|
||||
)
|
||||
done_formats.append(ebf.format)
|
||||
elif previous_ebook:
|
||||
previous_ebook.deactivate()
|
||||
elif previous_ebook:
|
||||
previous_ebook.deactivate()
|
||||
return
|
||||
|
||||
def remove_old_ebooks(self):
|
||||
|
@ -1667,6 +1679,13 @@ class EbookFile(models.Model):
|
|||
return test_epub(self.file)
|
||||
return None
|
||||
|
||||
@property
|
||||
def active(self):
|
||||
try:
|
||||
return Ebook.objects.filter(url=self.file.url)[0].active
|
||||
except:
|
||||
return False
|
||||
|
||||
class Ebook(models.Model):
|
||||
FORMAT_CHOICES = settings.FORMATS
|
||||
RIGHTS_CHOICES = cc.CHOICES
|
||||
|
@ -1727,6 +1746,10 @@ class Ebook(models.Model):
|
|||
def deactivate(self):
|
||||
self.active=False
|
||||
self.save()
|
||||
|
||||
def activate(self):
|
||||
self.active=True
|
||||
self.save()
|
||||
|
||||
class Wishlist(models.Model):
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
|
|
|
@ -133,7 +133,7 @@ def process_ebfs(campaign):
|
|||
if campaign.use_add_ask:
|
||||
campaign.add_ask_to_ebfs()
|
||||
else:
|
||||
campaign.work.make_ebooks_from_ebfs()
|
||||
campaign.work.make_ebooks_from_ebfs(add_ask=False)
|
||||
campaign.work.remove_old_ebooks()
|
||||
|
||||
@task
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
<ul>
|
||||
{% for ebook_file in edition.ebook_files.all %}
|
||||
{% if ebook_file.file %}
|
||||
<li><a href="{{ebook_file.file.url}}">{{ebook_file.file}}</a> created {{ebook_file.created}} {% if ebook_file.asking %}(This file has had the campaign 'ask' added.){% endif %}</li>
|
||||
<li>{% if ebook_file.active %}<span class="yikes">ACTIVE</span> {% endif %}<a href="{{ebook_file.file.url}}">{{ebook_file.file}}</a> created {{ebook_file.created}} {% if ebook_file.asking %}(This file has had the campaign 'ask' added.){% endif %}</li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
|
|
@ -157,7 +157,9 @@ Please fix the following before launching your campaign:
|
|||
<h3>Uploaded Files</h3>
|
||||
{% endif %}
|
||||
{% if campaign.work.epubfiles.0 %}
|
||||
<p>Active EPUB file: <a href="{{campaign.work.epubfiles.0.file.url}}">{{campaign.work.epubfiles.0.file}}</a> <br />created {{campaign.work.epubfiles.0.created}} for edition <a href="#edition_{{campaign.work.epubfiles.0.edition.id}}">{{campaign.work.epubfiles.0.edition.id}}</a> {% if campaign.work.epubfiles.0.asking %}(This file has had the campaign 'ask' added.){% endif %}</p>
|
||||
{% for ebf in campaign.work.epubfiles %}
|
||||
<p>{% if ebf.active %}<span class="yikes">ACTIVE</span> {% endif %}EPUB file: <a href="{{ebf.file.url}}">{{ebf.file}}</a> <br />created {{ebf.created}} for edition <a href="#edition_{{ebf.edition.id}}">{{ebf.edition.id}}</a> {% if ebf.asking %}(This file has had the campaign 'ask' added.){% endif %}</p>
|
||||
{% endfor %}
|
||||
{% if campaign.work.test_acqs.0 %}
|
||||
<ul>
|
||||
<li><a href="{{campaign.work.test_acqs.0.watermarked.download_link_epub}}">Processed epub for testing</a></li>
|
||||
|
@ -166,10 +168,14 @@ Please fix the following before launching your campaign:
|
|||
{% endif %}
|
||||
{% endif %}
|
||||
{% if campaign.work.mobifiles.0 %}
|
||||
<p>Active MOBI file: <a href="{{campaign.work.mobifiles.0.file.url}}">{{campaign.work.mobifiles.0.file}}</a> <br />created {{campaign.work.mobifiles.0.created}} for edition <a href="#edition_{{campaign.work.mobifiles.0.edition.id}}">{{campaign.work.mobifiles.0.edition.id}}</a> {% if campaign.work.mobifiles.0.asking %}(This file has had the campaign 'ask' added.){% endif %}</p>
|
||||
{% for ebf in campaign.work.mobifiles %}
|
||||
<p>{% if ebf.active %}<span class="yikes">ACTIVE</span> {% endif %}MOBI file: <a href="{{ebf.file.url}}">{{ebf.file}}</a> <br />created {{ebf.created}} for edition <a href="#edition_{{ebf.edition.id}}">{{ebf.edition.id}}</a> {% if ebf.asking %}(This file has had the campaign 'ask' added.){% endif %}</p>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if campaign.work.pdffiles.0 %}
|
||||
<p>Active PDF file: <a href="{{campaign.work.pdffiles.0.file.url}}">{{campaign.work.pdffiles.0.file}}</a> <br />created {{campaign.work.pdffiles.0.created}} for edition <a href="#edition_{{campaign.work.pdffiles.0.edition.id}}">{{campaign.work.pdffiles.0.edition.id}}</a> {% if campaign.work.pdffiles.0.asking %}(This file has had the campaign 'ask' added.){% endif %}</p>
|
||||
{% for ebf in campaign.work.pdffiles %}
|
||||
<p>{% if ebf.active %}<span class="yikes">ACTIVE</span> {% endif %}PDF file: <a href="{{ebf.file.url}}">{{ebf.file}}</a> <br />created {{ebf.created}} for edition <a href="#edition_{{ebf.edition.id}}">{{ebf.edition.id}}</a> {% if ebf.asking %}(This file has had the campaign 'ask' added.){% endif %}</p>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% ifnotequal campaign_status 'ACTIVE' %}
|
||||
{% ifnotequal campaign.type 3 %}
|
||||
|
|
Loading…
Reference in New Issue