Commit f4e4e66b authored by Aron Gergely's avatar Aron Gergely

Added functionality to indicate main shelter picture.

parent 7f37b632
......@@ -9,6 +9,17 @@ import conf
from web.models import Shelter, Category, ShelterPicture
from bootstrap import db
#! /usr/bin/python
#-*- coding:utf-8 -*
import os
import glob
import shutil
import conf
from web.models import Shelter, Category, ShelterPicture
from bootstrap import db
def import_shelters_pictures(folder):
shelters = Shelter.query.all()
......@@ -17,8 +28,10 @@ def import_shelters_pictures(folder):
for picture in glob.glob(folder + shelter_rid + '/**.jpg'):
picture_name = os.path.basename(picture)
try:
category_name = picture_name.split('_')[1]
picture_subject = os.path.splitext(picture_name.split('_')[2])[0]
except:
continue
......@@ -26,9 +39,16 @@ def import_shelters_pictures(folder):
Category.parent_id!=None).first()
if category:
new_picture = ShelterPicture(file_name=picture_name,
shelter_id=shelter.id,
category_id=category.id)
if picture_subject.lower() == 'facade':
new_picture = ShelterPicture(file_name=picture_name,
shelter_id=shelter.id,
category_id=category.id,
is_main_picture=True)
else:
new_picture = ShelterPicture(file_name=picture_name,
shelter_id=shelter.id,
category_id=category.id)
db.session.add(new_picture)
db.session.commit()
......
......@@ -25,6 +25,7 @@ class ShelterPicture(db.Model):
"""
id = db.Column(db.Integer, primary_key=True)
file_name = db.Column(db.String(), default='')
is_main_picture = db.Column(db.Boolean(), default=False)
# relationship
shelter_id = db.Column(db.Integer, db.ForeignKey('shelter.id'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment