backend: add saving catalog
This commit is contained in:
@ -1,9 +1,14 @@
|
||||
import datetime
|
||||
import json
|
||||
import logging
|
||||
import os.path
|
||||
import re
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.postgres.fields import JSONField
|
||||
from django.db import models
|
||||
import datetime
|
||||
import os.path
|
||||
import re
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Season(models.Model):
|
||||
@ -106,3 +111,41 @@ class Catalog(models.Model):
|
||||
'build_progress': self.build_progress,
|
||||
'pdf': self.pdf_url(),
|
||||
}
|
||||
|
||||
def update_metadata(self):
|
||||
"""Update meta properties from what's in 'data'"""
|
||||
if not self.data or len(self.data) < 1:
|
||||
log.warning('no data in update_metadata()')
|
||||
return
|
||||
|
||||
data = self.data
|
||||
|
||||
self.name = data.get('name', '(No name)')
|
||||
|
||||
self.season = Season.objects.get(id=data.get('season'))
|
||||
self.region = Region.objects.get(id=data.get('region'))
|
||||
|
||||
self.public = data.get('public', False)
|
||||
self.master = data.get('master', False)
|
||||
self.show_prices = data.get('show_prices', False)
|
||||
|
||||
# NOTE 'is_utility' in the json data is not exposed to the
|
||||
# django model or placed in a separate postgres column.
|
||||
|
||||
# reset until pdf is made
|
||||
self.build_progress = 0
|
||||
|
||||
# calculate some properties
|
||||
sections = 0
|
||||
pages = 0
|
||||
materials = 0
|
||||
for section in data.get('sections'):
|
||||
sections += 1
|
||||
for page in section.get('pages'):
|
||||
pages += 1
|
||||
for block in page:
|
||||
materials += len(block.get('ids', []))
|
||||
|
||||
self.sections = sections
|
||||
self.pages = pages
|
||||
self.materials = materials
|
||||
|
||||
@ -21,7 +21,7 @@ from lazysignup.views import convert
|
||||
|
||||
from dashboard.views import dashboard
|
||||
from cataloglist.views import cataloglist, my_catalogs, public_catalogs
|
||||
from catalogedit.views import catalogedit, get_catalog
|
||||
from catalogedit.views import catalogedit, get_catalog, save_catalog
|
||||
|
||||
from .forms import UserCreationForm
|
||||
from .views import login_guest, lazy_convert_done
|
||||
@ -38,7 +38,8 @@ urlpatterns = [
|
||||
|
||||
path('catalog/new', catalogedit, name='catalogedit'),
|
||||
path('catalog/edit/<int:id>', catalogedit, name='catalogedit'),
|
||||
path('api/v1/catalogs/id/<int:id>', get_catalog, name='catalog'),
|
||||
path('api/v1/catalogs/id/<int:id>', get_catalog, name='get_catalog'),
|
||||
path('api/v1/catalogs/save', save_catalog, name='save_catalog'),
|
||||
|
||||
path('admin/', admin.site.urls),
|
||||
path("account/", include("account.urls")),
|
||||
|
||||
Reference in New Issue
Block a user