Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
eshellman authored Nov 3, 2018
2 parents e455d9a + 0a59165 commit 3d40651
Show file tree
Hide file tree
Showing 405 changed files with 85,250 additions and 1,957 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ settings/keys/*
*.dot
reports
ENV
venv
.DS_Store
build
deploy/last-update
logs/*
cache/*
celerybeat.pid
celerybeat-schedule
.gitignore~
static/scss/*.css.map
static/scss/**/*.css.map
*.retry
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ services:
env:
global:
- DJANGO_SETTINGS_MODULE=regluit.settings.travis
- PYTHONPATH=/home/travis/build/Gluejar/
- PYTHONPATH=/home/travis/build/EbookFoundation/

before_install:
- sudo mkdir /var/log/django
- sudo chmod 777 /var/log/django
- mkdir ~/build/Gluejar/regluit/settings/keys/
- cp ~/build/Gluejar/regluit/settings/dummy/__init__.py ~/build/Gluejar/regluit/settings/keys/__init__.py
- openssl aes-256-cbc -K $encrypted_56eb2b7cc527_key -iv $encrypted_56eb2b7cc527_iv -in ~/build/Gluejar/regluit/test/travis-host.py.enc -out ~/build/Gluejar/regluit/settings/keys/host.py -d
- mkdir ~/build/EbookFoundation/regluit/settings/keys/
- cp ~/build/EbookFoundation/regluit/settings/dummy/__init__.py ~/build/EbookFoundation/regluit/settings/keys/__init__.py
- openssl aes-256-cbc -K $encrypted_56eb2b7cc527_key -iv $encrypted_56eb2b7cc527_iv -in ~/build/EbookFoundation/regluit/test/travis-host.py.enc -out ~/build/EbookFoundation/regluit/settings/keys/host.py -d

install:
- pip install -r requirements_versioned.pip
Expand Down
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,32 @@ The partitioning between these modules is not as clean as would be ideal. `payme

regluit was originally developed on Django 1.3 (python 2.7) and currently runs on Django 1.8.

Develop
Development (Vagrant + Virtualbox)
-------

The recommended method for local development is to create a virtual machine with [Vagrant](https://www.vagrantup.com/) and [Virtualbox](https://www.virtualbox.org/wiki/Downloads).
With this method, the only requirements on the host machine are `virtualbox` and `vagrant`.
Vagrant will use the `ansible-local` provisioner, therefore installing python and ansible on the host machine is not necessary.

__Instructions for Ubuntu 16:__
1. Install virtualbox: `sudo apt-get install virtualbox`
2. Install vagrant: `sudo apt-get install vagrant`
3. Clone the `EbookFoundation/regluit` repository.
4. Navigate to the base directory of the cloned repo (where `Vagrantfile` is located).
5. Run `vagrant up` to create the VM, install dependencies, and start necessary services.
* Note: This step may take up to 15 minutes to complete.
6. Once the VM has been created, run `vagrant ssh` to log in to the virtual machine you just created. If provisioning was successful, you should see a success message upon login.
* If virtualenv doesn't activate upon login, you can do it manually by running `cd /opt/regluit && source venv/bin/activate`
7. Within the VM, run `./manage.py runserver 0.0.0.0:8000` to start the Django development server.
8. On your host machine, open your web browser of choice and navigate to `http://127.0.0.1:8000`

__Instructions for other platforms (Windows/OSX):__
* Steps are essentially the same, except for the installation of Vagrant and Virtualbox. Refer to each package's documentation for specific installation instructions.

_NOTE:_ If running Windows on your host machine, ensure you are running `vagrant up` from an elevated command prompt, e.g. right click on Command Prompt -> Run As Administrator.


Development (Host Machine)
-------

Here are some instructions for setting up regluit for development on
Expand Down
56 changes: 56 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.
config.vm.box = "ubuntu/xenial64"

# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
config.vm.box_check_update = false

# Setup specific for local machine
config.vm.define "regluit-local", primary: true do |local|
# Create a private network
local.vm.network "private_network", type: "dhcp"
local.vm.hostname = "regluit-local"

# VirtuaLBox provider settings for running locally with Oracle VirtualBox
# --uartmode1 disconnected is necessary to disable serial interface, which
# is known to cause issues with Ubuntu 16 VM's
local.vm.provider "virtualbox" do |vb|
vb.name = "regluit-local"
vb.memory = 1024
vb.cpus = 2
vb.customize [ "modifyvm", :id, "--uartmode1", "disconnected" ]
end

end

config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.synced_folder ".", "/opt/regluit"

config.vm.network "forwarded_port", guest: 8000, host: 8000

# Provision node with Ansible running on the Vagrant host
# This requires you have Ansible installed locally
# Vagrant autogenerates an ansible inventory file to use
config.vm.provision "ansible_local" do |ansible|
ansible.playbook = "/opt/regluit/provisioning/setup-regluit.yml"
ansible.provisioning_path = "/opt/regluit"
ansible.verbose = true
ansible.install = true
end

config.vm.post_up_message = "Successfully created regluit-local VM. Run 'vagrant ssh' to log in and start the development server."

end
4 changes: 3 additions & 1 deletion core/mobi.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def convert_to_mobi(input_url, input_format="application/epub+zip"):
return a string with the output of mobigen computation
"""

if mobigen_url and mobigen_user_id and mobigen_password:
print 'settings ok'
# using verify=False since at the moment, using a self-signed SSL cert.

payload = requests.get(input_url).content
Expand All @@ -26,5 +27,6 @@ def convert_to_mobi(input_url, input_format="application/epub+zip"):
if r.status_code == 200:
return r.content
else:
print "{0}: {1}".format(r.status_code, r.content)
raise Exception("{0}: {1}".format(r.status_code, r.content))

3 changes: 2 additions & 1 deletion core/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
TRANSACTION_STATUS_FAILED,
TRANSACTION_STATUS_INCOMPLETE
)
from regluit.utils import crypto

from regluit.utils import encryption as crypto
from regluit.utils.localdatetime import date_today

from regluit.core.parameters import (
Expand Down
37 changes: 18 additions & 19 deletions core/models/bibmodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ def get_or_add(type='goog', value=None, edition=None, work=None):

def __unicode__(self):
return u'{0}:{1}'.format(self.type, self.value)

def label(self):
return ID_CHOICES_MAP.get(self.type, self.type)

def url(self):
return id_url(self.type, self.value)

Expand All @@ -129,7 +129,7 @@ class Work(models.Model):
is_free = models.BooleanField(default=False)
landings = GenericRelation(Landing, related_query_name='works')
related = models.ManyToManyField('self', symmetrical=False, blank=True, through='WorkRelation', related_name='reverse_related')
age_level = models.CharField(max_length=5, choices=AGE_LEVEL_CHOICES, default='', blank=True)
age_level = models.CharField(max_length=5, choices=AGE_LEVEL_CHOICES, default='', blank=True)

class Meta:
ordering = ['title']
Expand Down Expand Up @@ -165,7 +165,7 @@ def delete(self, cascade=True, *args, **kwargs):
for work_relation in self.works_related_from.all():
work_relation.delete()
super(Work, self).delete(*args, **kwargs) # Call the "real" save() method.

def id_for(self, type):
return id_for(self, type)

Expand Down Expand Up @@ -233,7 +233,7 @@ def openlibrary_id(self):
@property
def openlibrary_url(self):
return id_url('olwk', self.openlibrary_id)

def cover_filetype(self):
if self.uses_google_cover():
return 'jpeg'
Expand Down Expand Up @@ -431,14 +431,14 @@ def mobifiles(self):

def pdffiles(self):
return EbookFile.objects.filter(edition__work=self, format='pdf').exclude(file='').order_by('-created')

def versions(self):
version_labels = []
for ebook in self.ebooks_all():
if ebook.version_label and not ebook.version_label in version_labels:
version_labels.append(ebook.version_label)
return version_labels

def formats(self):
fmts = []
for fmt in ['pdf', 'epub', 'mobi', 'html']:
Expand All @@ -450,7 +450,7 @@ def formats(self):
def remove_old_ebooks(self):
# this method is triggered after an file upload or new ebook saved
old = Ebook.objects.filter(edition__work=self, active=True).order_by('-version_iter', '-created')

# keep highest version ebook for each format and version label
done_format_versions = []
for eb in old:
Expand All @@ -459,7 +459,7 @@ def remove_old_ebooks(self):
eb.deactivate()
else:
done_format_versions.append(format_version)

# check for failed uploads.
null_files = EbookFile.objects.filter(edition__work=self, file='')
for ebf in null_files:
Expand Down Expand Up @@ -796,12 +796,12 @@ class Subject(models.Model):

class Meta:
ordering = ['name']

@classmethod
def set_by_name(cls, subject, work=None, authority=None):
''' use this method whenever you would be creating a new subject!'''
subject = subject.strip()

# make sure it's not a ; delineated list
subjects = subject.split(';')
for additional_subject in subjects[1:]:
Expand All @@ -826,12 +826,12 @@ def set_by_name(cls, subject, work=None, authority=None):
if not subject_obj.authority and authority:
subject_obj.authority = authority
subject_obj.save()

subject_obj.works.add(work)
return subject_obj
return subject_obj
else:
return None

def __unicode__(self):
return self.name

Expand Down Expand Up @@ -1123,7 +1123,6 @@ def make_mobi(self):
asking=self.asking,
source=self.file.url
)

new_mobi_ebf.file.save(path_for_file(new_mobi_ebf, None), mobi_cf)
new_mobi_ebf.save()
if self.ebook:
Expand Down Expand Up @@ -1223,7 +1222,7 @@ def version(self):
return '.{}'.format(self.version_iter)
else:
return '().{}'.format(self.version_label, self.version_iter)

def set_version(self, version):
#set both version_label and version_iter with one string with format "version.iter"
version_pattern = r'(.*)\.(\d+)$'
Expand All @@ -1233,11 +1232,11 @@ def set_version(self, version):
else:
self.version_label = version
self.save()

def set_next_iter(self):
# set the version iter to the next unused iter for that version
for ebook in Ebook.objects.filter(
edition=self.edition,
edition=self.edition,
version_label=self.version_label,
format=self.format,
provider=self.provider
Expand All @@ -1246,7 +1245,7 @@ def set_next_iter(self):
break
self.version_iter = iter + 1
self.save()

@property
def rights_badge(self):
if self.rights is None:
Expand Down
4 changes: 2 additions & 2 deletions core/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,8 +998,8 @@ def test_download_page(self):

anon_client = Client()
response = anon_client.get("/work/%s/download/" % w.id, follow=True)
self.assertContains(response, "/download_ebook/%s/"% eb1.id, count=11)
self.assertContains(response, "/download_ebook/%s/"% eb2.id, count=5)
self.assertContains(response, "/download_ebook/%s/"% eb1.id, count=11)
self.assertContains(response, "/download_ebook/%s/"% eb2.id, count=4)
self.assertTrue(eb1.edition.work.is_free)
eb1.delete()
self.assertTrue(eb2.edition.work.is_free)
Expand Down
12 changes: 9 additions & 3 deletions frontend/forms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ class Meta:


class CampaignPurchaseForm(forms.Form):
anonymous = forms.BooleanField(required=False, label=_("Make this purchase anonymous, please"))
anonymous = forms.BooleanField(required=False,
label_suffix='',
label=_("Make this purchase anonymous"))
offer_id = forms.IntegerField(required=False)
offer = None
library_id = forms.IntegerField(required=False)
Expand Down Expand Up @@ -346,7 +348,8 @@ def trans_extra(self):
class CampaignThanksForm(forms.Form):
anonymous = forms.BooleanField(
required=False,
label=_("Make this contribution anonymous, please")
label_suffix='',
label=_("Make this contribution anonymous")
)
preapproval_amount = forms.DecimalField(
required = True,
Expand Down Expand Up @@ -380,7 +383,10 @@ class CampaignPledgeForm(forms.Form):
def amount(self):
return self.cleaned_data["preapproval_amount"] if self.cleaned_data else None

anonymous = forms.BooleanField(required=False, label=_("Make this support anonymous, please"))
anonymous = forms.BooleanField(
required=False,
label_suffix='',
label=_("Make this support anonymous"))
ack_name = forms.CharField(
required=False,
max_length=64,
Expand Down
Loading

0 comments on commit 3d40651

Please sign in to comment.