Commit f4e4e66b authored by Aron Gergely's avatar Aron Gergely
Browse files

Added functionality to indicate main shelter picture.

parent 7f37b632
...@@ -9,6 +9,17 @@ import conf ...@@ -9,6 +9,17 @@ import conf
from web.models import Shelter, Category, ShelterPicture from web.models import Shelter, Category, ShelterPicture
from bootstrap import db 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): def import_shelters_pictures(folder):
shelters = Shelter.query.all() shelters = Shelter.query.all()
...@@ -17,8 +28,10 @@ def import_shelters_pictures(folder): ...@@ -17,8 +28,10 @@ def import_shelters_pictures(folder):
for picture in glob.glob(folder + shelter_rid + '/**.jpg'): for picture in glob.glob(folder + shelter_rid + '/**.jpg'):
picture_name = os.path.basename(picture) picture_name = os.path.basename(picture)
try: try:
category_name = picture_name.split('_')[1] category_name = picture_name.split('_')[1]
picture_subject = os.path.splitext(picture_name.split('_')[2])[0]
except: except:
continue continue
...@@ -26,9 +39,16 @@ def import_shelters_pictures(folder): ...@@ -26,9 +39,16 @@ def import_shelters_pictures(folder):
Category.parent_id!=None).first() Category.parent_id!=None).first()
if category: if category:
new_picture = ShelterPicture(file_name=picture_name, if picture_subject.lower() == 'facade':
shelter_id=shelter.id, new_picture = ShelterPicture(file_name=picture_name,
category_id=category.id) 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.add(new_picture)
db.session.commit() db.session.commit()
......
...@@ -25,6 +25,7 @@ class ShelterPicture(db.Model): ...@@ -25,6 +25,7 @@ class ShelterPicture(db.Model):
""" """
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
file_name = db.Column(db.String(), default='') file_name = db.Column(db.String(), default='')
is_main_picture = db.Column(db.Boolean(), default=False)
# relationship # relationship
shelter_id = db.Column(db.Integer, db.ForeignKey('shelter.id'), 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