update settings models and migrations
parent
214c37a8f0
commit
b78e46df4e
|
@ -0,0 +1,144 @@
|
|||
from django.db import models
|
||||
from django.utils import timezone as tz
|
||||
|
||||
# logger = logging.getLogger(__name__)
|
||||
|
||||
# gh_org = 'GITenberg'
|
||||
|
||||
# def smart_truncate(content, length=100, suffix='...'):
|
||||
# if len(content) <= length:
|
||||
# return content
|
||||
# else:
|
||||
# return ' '.join(content[:length+1].split(' ')[0:-1]) + suffix
|
||||
'''
|
||||
class Author(models.Model):
|
||||
name = models.CharField(max_length=255, default="", null=True, blank=True)
|
||||
aliases = models.CharField(max_length=255, default="", null=True, blank=True)
|
||||
birth_year = models.IntegerField(null=True)
|
||||
death_year = models.IntegerField(null=True)
|
||||
wikipedia_url = models.URLField(max_length=500)
|
||||
class Meta:
|
||||
db_table = "authors"
|
||||
|
||||
'''
|
||||
|
||||
'''
|
||||
class Bookshelf(models.Model):
|
||||
id = models.AutoField(db_column='pk', primary_key=True)
|
||||
bookshelf = models.CharField(max_length=255, null=False)
|
||||
downloads = models.IntegerField(default=0)
|
||||
release_date = models.DateField(null=True)
|
||||
class Meta:
|
||||
db_table = "bookshelves"
|
||||
def __str__(self):
|
||||
return str(self.bookshelf)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Book(models.Model):
|
||||
id = models.AutoField(db_column='pk', primary_key=True)
|
||||
copyrighted = models.IntegerField(null=True, default=0)
|
||||
updatemode = models.IntegerField(null=True, default=0)
|
||||
release_date = models.DateField(null=True)
|
||||
filemask = models.CharField(max_length=240)
|
||||
gutindex = models.TextField()
|
||||
downloads = models.IntegerField(null=True, default=0)
|
||||
title = models.TextField(max_length=255, default="", null=True, blank=True)
|
||||
nonfiling = models.IntegerField(default=0)
|
||||
class Meta:
|
||||
db_table = "books"
|
||||
def __str__(self):
|
||||
return str(self.title)
|
||||
def save(self, *args, **kwargs):
|
||||
return
|
||||
def delete(self, *args, **kwargs):
|
||||
return
|
||||
|
||||
|
||||
class BookshelfToBook(models.Model):
|
||||
fk_books = models.ForeignKey(Book, db_column='fk_books', to_field='id', on_delete=models.CASCADE,)
|
||||
fk_bookshelves = models.ForeignKey(Bookshelf, db_column='fk_bookshelves', to_field='id', on_delete=models.CASCADE)
|
||||
class Meta:
|
||||
db_table = "mn_books_bookshelves"
|
||||
unique_together = (("fk_books", "fk_bookshelves"),)
|
||||
def __str__(self):
|
||||
return str(self.fk_books.title) + ' in bookshelf ' + str(self.fk_bookshelves.bookshelf)
|
||||
|
||||
'''
|
||||
|
||||
'''
|
||||
|
||||
# using a custom save method in order to update the "updated" timestamp when specific fields are updated
|
||||
def save(self, *args, **kwargs):
|
||||
if self.pk: # if object already exists in db
|
||||
old_model = Book.objects.get(pk=self.pk)
|
||||
|
||||
# This is the list of fields that, when modified, should update the "updated" timestamp
|
||||
fields = ["title", "language", "description", "author", "gutenberg_type", "gutenberg_bookshelf", "subjects", "full_text"]
|
||||
|
||||
for field in fields:
|
||||
# If one of the fields was modified, update the timestamp
|
||||
if getattr(old_model, field, None) != getattr(self, field, None):
|
||||
self.updated = tz.now()
|
||||
super(Book, self).save(*args, **kwargs) # call the inherited save method
|
||||
|
||||
def __unicode__(self):
|
||||
return self.repo_name
|
||||
|
||||
@property
|
||||
def title_short(self):
|
||||
return smart_truncate(self.title, 65)
|
||||
|
||||
@property
|
||||
def subjects_str(self):
|
||||
return self.subjects.replace(";", ", ")
|
||||
|
||||
@property
|
||||
def author_first_last(self):
|
||||
if self.author is None:
|
||||
return None
|
||||
else:
|
||||
return " ".join(self.author.name.split(", ")[::-1])
|
||||
|
||||
@property
|
||||
def description_short(self):
|
||||
return smart_truncate(self.description, 300)
|
||||
|
||||
@property
|
||||
def repo_url(self):
|
||||
return 'https://github.com/{}/{}'.format(gh_org,self.repo_name)
|
||||
|
||||
@property
|
||||
def issues_url(self):
|
||||
return 'https://github.com/{}/{}/issues'.format(gh_org,self.repo_name)
|
||||
|
||||
@property
|
||||
def downloads_url(self):
|
||||
return 'https://github.com/{}/{}/releases'.format(gh_org,self.repo_name)
|
||||
|
||||
@property
|
||||
def pg_url(self):
|
||||
return 'https://www.gutenberg.org/ebooks/{}'.format(self.book_id)
|
||||
|
||||
@property
|
||||
def cover_url(self):
|
||||
existing_covers = list(Cover.objects.filter(book=self))
|
||||
for cover in existing_covers:
|
||||
if cover.default_cover and cover.file and hasattr(cover.file, "url"):
|
||||
return cover.file.url
|
||||
#No cover is set as default, so return the first cover that has a url
|
||||
if len(existing_covers) > 0:
|
||||
for cover in existing_covers:
|
||||
if cover.file and hasattr(cover.file, "url"):
|
||||
return cover.file.url
|
||||
return None
|
||||
|
||||
_pandata=None
|
||||
def metadata(self):
|
||||
if not self._pandata:
|
||||
self._pandata=Pandata()
|
||||
self._pandata.load(self.yaml)
|
||||
return self._pandata.metadata
|
||||
'''
|
|
@ -1,6 +1,7 @@
|
|||
# Generated by Django 3.1.3 on 2020-11-30 19:10
|
||||
# Generated by Django 3.1.3 on 2021-04-23 18:31
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
@ -11,10 +12,27 @@ class Migration(migrations.Migration):
|
|||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Book',
|
||||
fields=[
|
||||
('id', models.AutoField(db_column='pk', primary_key=True, serialize=False)),
|
||||
('copyrighted', models.IntegerField(default=0, null=True)),
|
||||
('updatemode', models.IntegerField(default=0, null=True)),
|
||||
('release_date', models.DateField(null=True)),
|
||||
('filemask', models.CharField(max_length=240)),
|
||||
('gutindex', models.TextField()),
|
||||
('downloads', models.IntegerField(default=0, null=True)),
|
||||
('title', models.TextField(blank=True, default='', max_length=255, null=True)),
|
||||
('nonfiling', models.IntegerField(default=0)),
|
||||
],
|
||||
options={
|
||||
'db_table': 'books',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Bookshelf',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('id', models.AutoField(db_column='pk', primary_key=True, serialize=False)),
|
||||
('bookshelf', models.CharField(max_length=255)),
|
||||
('downloads', models.IntegerField(default=0)),
|
||||
('release_date', models.DateField(null=True)),
|
||||
|
@ -23,4 +41,16 @@ class Migration(migrations.Migration):
|
|||
'db_table': 'bookshelves',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='BookshelfToBook',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('fk_books', models.ForeignKey(db_column='fk_books', on_delete=django.db.models.deletion.CASCADE, to='mgmt.book')),
|
||||
('fk_bookshelves', models.ForeignKey(db_column='fk_bookshelves', on_delete=django.db.models.deletion.CASCADE, to='mgmt.bookshelf')),
|
||||
],
|
||||
options={
|
||||
'db_table': 'mn_books_bookshelves',
|
||||
'unique_together': {('fk_books', 'fk_bookshelves')},
|
||||
},
|
||||
),
|
||||
]
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
# Generated by Django 3.1.3 on 2020-11-30 20:17
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('mgmt', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='bookshelf',
|
||||
name='id',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='bookshelf',
|
||||
name='bookshelf',
|
||||
field=models.CharField(max_length=255, primary_key=True, serialize=False),
|
||||
),
|
||||
]
|
|
@ -1,48 +0,0 @@
|
|||
# Generated by Django 3.1.3 on 2020-12-01 21:34
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('mgmt', '0002_auto_20201130_2017'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Author',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(blank=True, default='', max_length=255, null=True)),
|
||||
('aliases', models.CharField(blank=True, default='', max_length=255, null=True)),
|
||||
('birth_year', models.IntegerField(null=True)),
|
||||
('death_year', models.IntegerField(null=True)),
|
||||
('wikipedia_url', models.URLField(max_length=500)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Book',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('book_id', models.IntegerField()),
|
||||
('repo_name', models.CharField(blank=True, max_length=255, null=True)),
|
||||
('title', models.CharField(db_index=True, default='', max_length=1000)),
|
||||
('language', models.CharField(db_index=True, default='en', max_length=5)),
|
||||
('description', models.TextField(blank=True, default='', null=True)),
|
||||
('gutenberg_type', models.CharField(blank=True, default='', max_length=255, null=True)),
|
||||
('gutenberg_bookshelf', models.CharField(default='', max_length=1000)),
|
||||
('subjects', models.CharField(default='', max_length=1000)),
|
||||
('full_text', models.TextField(blank=True, default='', null=True)),
|
||||
('num_downloads', models.IntegerField(default=0)),
|
||||
('added', models.DateTimeField(auto_now_add=True, null=True)),
|
||||
('updated', models.DateTimeField(auto_now_add=True, null=True)),
|
||||
('yaml', models.TextField(default='', null=True)),
|
||||
('author', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='mgmt.author')),
|
||||
],
|
||||
options={
|
||||
'db_table': 'books',
|
||||
},
|
||||
),
|
||||
]
|
|
@ -1,106 +0,0 @@
|
|||
# Generated by Django 3.1.3 on 2020-12-01 21:47
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('mgmt', '0003_author_book'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='book',
|
||||
name='added',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='book',
|
||||
name='author',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='book',
|
||||
name='book_id',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='book',
|
||||
name='description',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='book',
|
||||
name='full_text',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='book',
|
||||
name='gutenberg_bookshelf',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='book',
|
||||
name='gutenberg_type',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='book',
|
||||
name='language',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='book',
|
||||
name='num_downloads',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='book',
|
||||
name='repo_name',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='book',
|
||||
name='subjects',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='book',
|
||||
name='updated',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='book',
|
||||
name='yaml',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='book',
|
||||
name='copyrighted',
|
||||
field=models.IntegerField(default=0, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='book',
|
||||
name='downloads',
|
||||
field=models.IntegerField(default=0, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='book',
|
||||
name='filemask',
|
||||
field=models.CharField(default='', max_length=240),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='book',
|
||||
name='gutindex',
|
||||
field=models.TextField(blank=True, default='', null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='book',
|
||||
name='nonfiling',
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='book',
|
||||
name='release_date',
|
||||
field=models.DateField(null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='book',
|
||||
name='updatemode',
|
||||
field=models.CharField(blank=True, max_length=255, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='book',
|
||||
name='title',
|
||||
field=models.TextField(blank=True, default='', max_length=255, null=True),
|
||||
),
|
||||
]
|
|
@ -1,28 +0,0 @@
|
|||
# Generated by Django 3.1.3 on 2020-12-01 21:49
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('mgmt', '0004_auto_20201201_2147'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='book',
|
||||
name='id',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='book',
|
||||
name='gutindex',
|
||||
field=models.TextField(default='1', primary_key=True, serialize=False),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='book',
|
||||
name='updatemode',
|
||||
field=models.IntegerField(default=0, null=True),
|
||||
),
|
||||
]
|
|
@ -1,17 +0,0 @@
|
|||
# Generated by Django 3.1.3 on 2020-12-01 21:52
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('mgmt', '0005_auto_20201201_2149'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelTable(
|
||||
name='author',
|
||||
table='authors',
|
||||
),
|
||||
]
|
|
@ -1,16 +0,0 @@
|
|||
# Generated by Django 3.1.3 on 2020-12-01 22:03
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('mgmt', '0006_auto_20201201_2152'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.DeleteModel(
|
||||
name='Author',
|
||||
),
|
||||
]
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -21,7 +21,6 @@ class Author(models.Model):
|
|||
db_table = "authors"
|
||||
|
||||
'''
|
||||
|
||||
class Bookshelf(models.Model):
|
||||
id = models.AutoField(db_column='pk', primary_key=True)
|
||||
bookshelf = models.CharField(max_length=255, null=False)
|
||||
|
@ -66,7 +65,7 @@ class BookshelfToBook(models.Model):
|
|||
def __str__(self):
|
||||
return str(self.fk_books.title) + ' in bookshelf ' + str(self.fk_bookshelves.bookshelf)
|
||||
|
||||
'''
|
||||
'''
|
||||
|
||||
# using a custom save method in order to update the "updated" timestamp when specific fields are updated
|
||||
def save(self, *args, **kwargs):
|
||||
|
@ -139,4 +138,4 @@ class BookshelfToBook(models.Model):
|
|||
self._pandata=Pandata()
|
||||
self._pandata.load(self.yaml)
|
||||
return self._pandata.metadata
|
||||
'''
|
||||
'''
|
||||
|
|
|
@ -26,7 +26,7 @@ SECRET_KEY = '&@xb%y*a-v56sap7_5&+kdtsdck68h-9&r6*u#3!a2ey@+i76$'
|
|||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = ["localhost"]
|
||||
ALLOWED_HOSTS = ["localhost", '3.82.162.234']
|
||||
|
||||
|
||||
# Application definition
|
||||
|
@ -79,9 +79,9 @@ DATABASES = {
|
|||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql',
|
||||
'NAME': 'gutenberg',
|
||||
'USER': 'adamundus',
|
||||
'PASSWORD': 'database',
|
||||
'HOST': '127.0.0.1',
|
||||
'USER': 'postgres',
|
||||
'PASSWORD': 'booksrcool',
|
||||
'HOST': 'gutenberg-db.cd80uhnba3in.us-east-1.rds.amazonaws.com',
|
||||
'PORT': '5432',
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue