catalog editor: load catalog, region, season data
This commit is contained in:
@ -7,7 +7,22 @@ from django.utils.translation import gettext as _
|
|||||||
from lazysignup.decorators import allow_lazy_user
|
from lazysignup.decorators import allow_lazy_user
|
||||||
from account.decorators import login_required
|
from account.decorators import login_required
|
||||||
|
|
||||||
|
from procat2.models import Catalog, Season, Region
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def catalogedit(request):
|
def catalogedit(request, id=0):
|
||||||
return render(request, 'catalogedit/catalogedit.html')
|
regions = Region.objects.order_by('ordering')
|
||||||
|
seasons = Season.objects.order_by('ordering')
|
||||||
|
context = {
|
||||||
|
'catalogID': id,
|
||||||
|
'regions': [r.serialize() for r in regions],
|
||||||
|
'seasons': [s.serialize() for s in seasons],
|
||||||
|
}
|
||||||
|
return render(request, 'catalogedit/catalogedit.html', context)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def get_catalog(request, id):
|
||||||
|
cat = get_object_or_404(Catalog, id=id)
|
||||||
|
return JsonResponse(cat.data, safe=False)
|
||||||
|
|||||||
@ -49,14 +49,18 @@ export default {
|
|||||||
CatalogContents
|
CatalogContents
|
||||||
},
|
},
|
||||||
data: () => ({
|
data: () => ({
|
||||||
/* seasons: [ 'SS19', 'FW19', 'SS20' ],
|
step: 1,
|
||||||
* regions: [ 'US', 'Canada', 'Mexico' ],
|
}),
|
||||||
* season: null,
|
mounted: function() {
|
||||||
* region: null,
|
// catalogID is set by django
|
||||||
* name: null, */
|
// in a script block in our parent page.
|
||||||
/* ispublic: true, */
|
var catalogID = JSON.parse(document.getElementById('catalogID').textContent)
|
||||||
step: 1
|
if (catalogID > 0) {
|
||||||
})
|
this.$store.dispatch('loadCatalog', catalogID)
|
||||||
|
} else {
|
||||||
|
this.$store.dispatch('newCatalog')
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@ -4,10 +4,20 @@
|
|||||||
|
|
||||||
<v-layout row>
|
<v-layout row>
|
||||||
<v-flex d-flex shrink>
|
<v-flex d-flex shrink>
|
||||||
<v-select :items="seasons" v-model="season" label="Season"></v-select>
|
<v-select
|
||||||
|
v-model="season"
|
||||||
|
:items="seasons"
|
||||||
|
item-value="id"
|
||||||
|
item-text="name"
|
||||||
|
label="Season"></v-select>
|
||||||
</v-flex>
|
</v-flex>
|
||||||
<v-flex d-flex shrink>
|
<v-flex d-flex shrink>
|
||||||
<v-select :items="regions" v-model="region" label="Region"></v-select>
|
<v-select
|
||||||
|
v-model="region"
|
||||||
|
:items="regions"
|
||||||
|
item-value="id"
|
||||||
|
item-text="name"
|
||||||
|
label="Region"></v-select>
|
||||||
</v-flex>
|
</v-flex>
|
||||||
<v-flex d-flex grow>
|
<v-flex d-flex grow>
|
||||||
<v-text-field v-model="name" label="Catalog name" required></v-text-field>
|
<v-text-field v-model="name" label="Catalog name" required></v-text-field>
|
||||||
@ -36,15 +46,36 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
var seasons = JSON.parse(document.getElementById('seasons').textContent)
|
||||||
|
var regions = JSON.parse(document.getElementById('regions').textContent)
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: () => ({
|
data: () => ({
|
||||||
seasons: [ 'SS19', 'FW19', 'SS20' ],
|
seasons: seasons,
|
||||||
regions: [ 'US', 'Canada', 'Mexico' ],
|
regions: regions,
|
||||||
season: null,
|
|
||||||
region: null,
|
|
||||||
name: null,
|
name: null,
|
||||||
ispublic: true
|
ispublic: true
|
||||||
})
|
}),
|
||||||
|
computed: {
|
||||||
|
season: {
|
||||||
|
get() {
|
||||||
|
return this.$store.getters.catalogSeason
|
||||||
|
},
|
||||||
|
set(season) {
|
||||||
|
this.$store.dispatch('setCatalogSeason', season)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
region: {
|
||||||
|
get() {
|
||||||
|
return this.$store.getters.catalogRegion
|
||||||
|
},
|
||||||
|
set(region) {
|
||||||
|
this.$store.dispatch('setCatalogRegion', region)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@ -1,33 +1,12 @@
|
|||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import Vuex from 'vuex'
|
import Vuex from 'vuex'
|
||||||
|
import axios from 'axios'
|
||||||
|
|
||||||
Vue.use(Vuex)
|
Vue.use(Vuex)
|
||||||
|
|
||||||
export const store = new Vuex.Store({
|
export const store = new Vuex.Store({
|
||||||
state: {
|
state: {
|
||||||
catalog: {
|
catalog: null,
|
||||||
name: 'my catalog',
|
|
||||||
owner: 12,
|
|
||||||
created: '2019-04-04T22:00:14Z',
|
|
||||||
sections: [
|
|
||||||
{ id: 1,
|
|
||||||
name: 'Trailhead (Men)',
|
|
||||||
pages: [
|
|
||||||
[{ name: 'model name override', size: 2, ids: ['1001001', '1001002'] },
|
|
||||||
{ size: 1, ids: ['1001011', '1001012'] }], // one page, two blocks
|
|
||||||
[{ size: 1,
|
|
||||||
ids: ['1001021', '1001022', '1001023', '1001024', '1001025',
|
|
||||||
'1001026', '1001027', '1001028', '1001029'] }],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{ id: 2,
|
|
||||||
name: 'Waterfront (Men)',
|
|
||||||
pages: [
|
|
||||||
[{ size: 1, ids: ['1001021'] }],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
materials: {
|
materials: {
|
||||||
'1001001': { id: '1001001', // call them sap maybe?
|
'1001001': { id: '1001001', // call them sap maybe?
|
||||||
model: 'AW123',
|
model: 'AW123',
|
||||||
@ -99,6 +78,7 @@ export const store = new Vuex.Store({
|
|||||||
selectedFamilyID: null,
|
selectedFamilyID: null,
|
||||||
selectedModelID: null,
|
selectedModelID: null,
|
||||||
selectedMaterial: null,
|
selectedMaterial: null,
|
||||||
|
loadingCatalog: true,
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
//
|
//
|
||||||
@ -113,6 +93,23 @@ export const store = new Vuex.Store({
|
|||||||
CAT_SECTION: (state) => (id) => {
|
CAT_SECTION: (state) => (id) => {
|
||||||
return state.catalog.sections.find(s => s.id === id)
|
return state.catalog.sections.find(s => s.id === id)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
catalogSeason(state) {
|
||||||
|
if (state.catalog != null) {
|
||||||
|
return state.catalog.season
|
||||||
|
} else {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
catalogRegion(state) {
|
||||||
|
if (state.catalog != null) {
|
||||||
|
return state.catalog.region
|
||||||
|
} else {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
//
|
//
|
||||||
// selection info
|
// selection info
|
||||||
//
|
//
|
||||||
@ -137,6 +134,10 @@ export const store = new Vuex.Store({
|
|||||||
MATERIAL: (state) => (id) => {
|
MATERIAL: (state) => (id) => {
|
||||||
return state.materials[id]
|
return state.materials[id]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getLoadingCatalog(state) {
|
||||||
|
return state.loadingCatalog
|
||||||
|
},
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
SET_CAT_SECTIONS: (state, payload) => {
|
SET_CAT_SECTIONS: (state, payload) => {
|
||||||
@ -165,6 +166,14 @@ export const store = new Vuex.Store({
|
|||||||
SET_SELECTED_MATERIAL_ID: (state, payload) => {
|
SET_SELECTED_MATERIAL_ID: (state, payload) => {
|
||||||
state.selectedMaterial = payload
|
state.selectedMaterial = payload
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setCatalog(state, cat) {
|
||||||
|
state.catalog = cat
|
||||||
|
},
|
||||||
|
|
||||||
|
setLoadingCatalog(state, value) {
|
||||||
|
state.loadingCatalog = value
|
||||||
|
},
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
SET_CAT_SECTIONS: (context, payload) => {
|
SET_CAT_SECTIONS: (context, payload) => {
|
||||||
@ -189,5 +198,25 @@ export const store = new Vuex.Store({
|
|||||||
// let { data } = await Axios.post('http://yourwebsite.com/api/todo')
|
// let { data } = await Axios.post('http://yourwebsite.com/api/todo')
|
||||||
// context.commit('ADD_TODO',payload)
|
// context.commit('ADD_TODO',payload)
|
||||||
// },
|
// },
|
||||||
|
|
||||||
|
async loadCatalog({ commit }, id) {
|
||||||
|
try {
|
||||||
|
commit('setLoadingCatalog', true)
|
||||||
|
const response = await axios.get('/api/v1/catalogs/id/' + id)
|
||||||
|
if ('catalog' in response.data) {
|
||||||
|
console.log('recieved catalog:', response.data.catalog)
|
||||||
|
commit('setCatalog', response.data.catalog)
|
||||||
|
} else {
|
||||||
|
console.log('no catalog')
|
||||||
|
commit('setCatalog', null)
|
||||||
|
}
|
||||||
|
commit('setLoadingCatalog', false)
|
||||||
|
} catch (error) {
|
||||||
|
// TODO set loading error property
|
||||||
|
console.error('error loading catalog: ', error)
|
||||||
|
commit('setCatalog', null)
|
||||||
|
commit('setLoadingCatalog', false)
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@ -11,12 +11,26 @@ class Season(models.Model):
|
|||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
ordering = models.PositiveIntegerField(unique=True, default=1000)
|
ordering = models.PositiveIntegerField(unique=True, default=1000)
|
||||||
|
|
||||||
|
def serialize(self):
|
||||||
|
return {
|
||||||
|
'id': self.id,
|
||||||
|
'name': self.name,
|
||||||
|
'ordering': self.ordering,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class Region(models.Model):
|
class Region(models.Model):
|
||||||
id = models.CharField(max_length=30, primary_key=True)
|
id = models.CharField(max_length=30, primary_key=True)
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
ordering = models.PositiveIntegerField(unique=True, default=1000)
|
ordering = models.PositiveIntegerField(unique=True, default=1000)
|
||||||
|
|
||||||
|
def serialize(self):
|
||||||
|
return {
|
||||||
|
'id': self.id,
|
||||||
|
'name': self.name,
|
||||||
|
'ordering': self.ordering,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def pretty_datetime(date):
|
def pretty_datetime(date):
|
||||||
# Oct 16 2018 10:58 am
|
# Oct 16 2018 10:58 am
|
||||||
|
|||||||
@ -21,7 +21,7 @@ from lazysignup.views import convert
|
|||||||
|
|
||||||
from dashboard.views import dashboard
|
from dashboard.views import dashboard
|
||||||
from cataloglist.views import cataloglist, my_catalogs, public_catalogs
|
from cataloglist.views import cataloglist, my_catalogs, public_catalogs
|
||||||
from catalogedit.views import catalogedit
|
from catalogedit.views import catalogedit, get_catalog
|
||||||
|
|
||||||
from .forms import UserCreationForm
|
from .forms import UserCreationForm
|
||||||
from .views import login_guest, lazy_convert_done
|
from .views import login_guest, lazy_convert_done
|
||||||
@ -36,7 +36,9 @@ urlpatterns = [
|
|||||||
path('api/v1/catalogs/mine', my_catalogs, name='my_catalogs'),
|
path('api/v1/catalogs/mine', my_catalogs, name='my_catalogs'),
|
||||||
path('api/v1/catalogs/public', public_catalogs, name='public_catalogs'),
|
path('api/v1/catalogs/public', public_catalogs, name='public_catalogs'),
|
||||||
|
|
||||||
path('edit', catalogedit, name='catalogedit'),
|
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('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
path("account/", include("account.urls")),
|
path("account/", include("account.urls")),
|
||||||
|
|||||||
@ -10,6 +10,9 @@
|
|||||||
<link href="{% static 'img/favicon.ico' %}" rel="shortcut icon" />
|
<link href="{% static 'img/favicon.ico' %}" rel="shortcut icon" />
|
||||||
<title>Django Vue Integration</title>
|
<title>Django Vue Integration</title>
|
||||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900">
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900">
|
||||||
|
{{ catalogID | json_script:"catalogID" }}
|
||||||
|
{{ regions | json_script:"regions" }}
|
||||||
|
{{ seasons | json_script:"seasons" }}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<noscript>
|
<noscript>
|
||||||
|
|||||||
Reference in New Issue
Block a user