catalog list: get 'my catalogs' somewhat working
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
from django.db import models
|
||||
from django.conf import settings
|
||||
from django.contrib.postgres.fields import JSONField
|
||||
import datetime
|
||||
|
||||
|
||||
class Season(models.Model):
|
||||
@ -15,6 +16,15 @@ class Region(models.Model):
|
||||
ordering = models.PositiveIntegerField(unique=True, default=1000)
|
||||
|
||||
|
||||
def pretty_datetime(date):
|
||||
# Oct 16 2018 10:58 am
|
||||
return "{:%b %-d %Y, %-I:%M %p}".format(date)
|
||||
|
||||
|
||||
def unix_datetime(date):
|
||||
return date.timestamp()
|
||||
|
||||
|
||||
class Catalog(models.Model):
|
||||
owner = models.ForeignKey(settings.AUTH_USER_MODEL,
|
||||
on_delete=models.CASCADE)
|
||||
@ -31,3 +41,20 @@ class Catalog(models.Model):
|
||||
|
||||
# JSONField docs:
|
||||
# https://docs.djangoproject.com/en/2.2/ref/contrib/postgres/fields/#jsonfield
|
||||
|
||||
def summary(self):
|
||||
return {
|
||||
'id': self.id,
|
||||
'seasonCode': self.season.id,
|
||||
'regionCode': self.region.id,
|
||||
'name': self.name,
|
||||
'ownerName': self.owner.get_full_name(),
|
||||
'public': self.public,
|
||||
'updated': unix_datetime(self.updated),
|
||||
'updatedPretty': pretty_datetime(self.updated),
|
||||
'created': unix_datetime(self.created),
|
||||
'createdPretty': pretty_datetime(self.created),
|
||||
'pages': self.pages,
|
||||
'sections': self.sections,
|
||||
'materials': self.materials,
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ from django.conf import settings
|
||||
from lazysignup.views import convert
|
||||
|
||||
from dashboard.views import dashboard
|
||||
from cataloglist.views import cataloglist
|
||||
from cataloglist.views import cataloglist, my_catalogs, public_catalogs
|
||||
from catalogedit.views import catalogedit
|
||||
|
||||
from .forms import UserCreationForm
|
||||
@ -31,8 +31,12 @@ urlpatterns = [
|
||||
path('guest', login_guest, name='login_guest'),
|
||||
path('', dashboard, name='home'),
|
||||
path('dashboard', dashboard, name='dashboard'),
|
||||
|
||||
path('catalogs', cataloglist, name='cataloglist'),
|
||||
path('api/v1/catalogs/mine', my_catalogs, name='my_catalogs'),
|
||||
|
||||
path('edit', catalogedit, name='catalogedit'),
|
||||
|
||||
path('admin/', admin.site.urls),
|
||||
path("account/", include("account.urls")),
|
||||
path('convert/', convert, { 'form_class': UserCreationForm }, name='lazysignup_convert'),
|
||||
|
||||
Reference in New Issue
Block a user