def handle(self, *args, **options):
        for row in all_portfolio_rows():
            w = Work.objects.create(
                name_he=row.get(u'שם העבודה', ''),
                name_en=row.get('Document Title', ''),
                description_he=html2text(row.get(u'תאור', '')),
                description_en=html2text(row.get(u'Description', '')),
                discipline=match_discipline(row),
                country=match_country(row.get(u'ארץ', '')),
                designer=Designer.objects.get_or_create(
                    name_he=row.get(u'מעצב', ''),
                    defaults={'name_en': row.get('Designer', '')})[0],
                category=match_category(row.get(u'קטגוריה')),
                size_as_text=row.get(u'גודל', ''),
                publish_date_as_text=row.get(u'תאריך', ''),
                publish_year=int(row.get(u'תאריך', ''))if row.get(
                    u'תאריך', '').isdigit() else None,
                client=row.get(u'לקוח', ''),
                technique=match_technique(row.get(u'טכניקה', '')),
                is_self_collected=match_is_self_collected(
                    row.get(u'מעצב', ''),
                    row.get(u'מאוסף', '')),
                raw_image=File(open(os.path.join(
                    settings.PORFOLIO_IMAGE_DIR,
                    row['Filename'])))
            )
            w.subjects = match_subject(row.get(u'נושא'))
            w.of_collections = match_collector(row.get(u'מעצב', ''),
                                               row.get(u'מאוסף', ''))

            for keyword in [keyword.strip() for keyword in html2text(row.get(u'מילות מפתח', '')).split(',')]:
                if keyword:
                    w.tags.add(keyword)
示例#2
0
 def forwards(self, orm):
     "Write your forwards methods here."
     # Note: Remember to use orm['appname.ModelName'] rather than "from appname.models..."
     for row in all_portfolio_rows():
         orm.Work(
             sidar_id=os.path.splitext(row['Filename'])[0]
         ).save()
 def forwards(self, orm):
     "Write your forwards methods here."
     # Note: Remember to use orm['appname.ModelName'] rather than "from appname.models..."
     for row in all_portfolio_rows():
         subjects = []
         category = None
         if nullify(row[u'נושא']) != None:
             for subject in html2text(row[u'נושא']).split(','):
                 if nullify(subject.strip()) != None:
                     subjects.append((orm.Subject.objects.get_or_create(name_he=subject.strip()))[0])
             # subjects = [(orm.Subject.objects.get_or_create(name_he=subject.strip()))[0] for subject in html2text(row[u'נושא']).split(',')]
         if nullify(row[u'קטגוריה']) != None:
             clean_category = split_languages_from_string(row[u'קטגוריה'])
             category = orm.Category.objects.get_or_create(
                 name_he=clean_category['he'],
                 defaults={'name_en': clean_category['en']}
             )[0]
         try:
             work = orm.Work.objects.get(sidar_id=remove_file_extension(row['Filename']))
         except orm.Work.DoesNotExist:
             pass
         else:
             work.category = category
             work.subjects = subjects
             work.save()
示例#4
0
 def forwards(self, orm):
     "Write your forwards methods here."
     # Note: Remember to use orm['appname.ModelName'] rather than "from appname.models..."
     for row in all_portfolio_rows():
         try:
             orm.Work(sidar_id=remove_file_extension(row['Filename'])).save()
         except IntegrityError:
             pass
 def forwards(self, orm):
     "Write your forwards methods here."
     # Note: Remember to use orm['appname.ModelName'] rather than "from appname.models..."
     for row in all_portfolio_rows():
         work = orm.Work.objects.get(sidar_id=remove_file_extension(row['Filename']))
         work.description_he = html2text(row[u'תאור']).strip()
         work.description_en = html2text(row[u'Description']).strip()
         work.save()
示例#6
0
 def forwards(self, orm):
     "Write your forwards methods here."
     # Note: Remember to use orm['appname.ModelName'] rather than "from appname.models..."
     for row in all_portfolio_rows():
         country = nullify(row[u'ארץ'].strip())
         if country != None:
             matched_country = orm.Country.objects.get_or_create(name_he=country)[0]
         else:
             matched_country = None
         work = orm.Work.objects.get(sidar_id=remove_file_extension(row['Filename']))
         work.country = matched_country
         work.save()
示例#7
0
    def forwards(self, orm):
        "Write your forwards methods here."
        # Note: Remember to use orm['appname.ModelName'] rather than "from appname.models..."
        # Build file path hash for importing images
        
        # path_hash = dict()
        # for root, dirs, files in os.walk(PORTFOLIO_CSV_ROOT):
        #     for filename in files:
        #         if filename.rpartition('.')[-1] == "jpg":
        #             path_hash[filename] = os.path.join(root, filename)

        for row in all_portfolio_rows():
            work = orm.Work.objects.get(sidar_id=remove_file_extension(row['Filename']))
            work.name_he = row[u'שם העבודה'].strip()
            work.name_en = row['Document Title'].strip()
            # work.raw_image = File(open(path_hash[row['Filename']]))
            work.save()
    def handle(self, *args, **options):
        for row in all_portfolio_rows():
            for work in Work.objects.filter(
                raw_image__contains=os.path.basename(row.get('Filename'))
            ):
                if work.name_he:
                    continue
                work.name_he = row.get(u'שם העבודה', '')
                work.name_en = row.get('Document Title', '')
                work.description_he = html2text(row.get(u'תאור', ''))
                work.description_en = html2text(row.get(u'Description', ''))
            #     discipline=match_discipline(row),
                work.country = match_country(row.get(u'ארץ', ''))

                designer = work.designer
                if not designer.name_he and row.get(u'מעצב'):
                    designer.name_he = row.get(u'מעצב')
                if not designer.name_en and row.get(u'Designer'):
                    designer.name_en = row.get(u'Designer')
                designer.save()

                category = work.category
                if not category.name_he and row.get(u'קטגוריה'):
                    names = split_languages_from_string(row.get(u'קטגוריה'))
                    category.name_he = names['he']
                    category.name_en = names['en']
                    category.save()

                work.size_as_text = row.get(u'גודל', '')
                work.publish_date_as_text = row.get(u'תאריך', '')
                work.publish_year = int(row.get(u'תאריך', '')) if row.get(
                    u'תאריך', '').isdigit() else None
                work.client = row.get(u'לקוח', '')
                work.technique = match_technique(row.get(u'טכניקה', ''))
                work.is_self_collected = match_is_self_collected(
                    row.get(u'מעצב', ''),
                    row.get(u'מאוסף', ''))
                work.subjects = match_subject(row.get(u'נושא'))
                work.of_collections = match_collector(row.get(u'מעצב', ''),
                                                      row.get(u'מאוסף', ''))

                for keyword in [keyword.strip() for keyword in html2text(row.get(u'מילות מפתח', '')).split(',')]:
                    if keyword:
                        work.tags.add(keyword)
                work.save()
    def forwards(self, orm):
        "Write your forwards methods here."
        # Note: Remember to use orm['appname.ModelName'] rather than "from appname.models..."
        for row in all_portfolio_rows():
            try:
                designer = row[u'מעצב'].strip()
            except KeyError:
                print "No field called מעצב for the the current file."
                designer = None

            if designer:
                designer = orm.Designer.objects.get_or_create(
                    name_he=designer,
                    defaults={'name_en': row['Designer']}
                )[0]
                try:
                    work = orm.Work.objects.get(sidar_id=remove_file_extension(row['Filename']))
                    work.designer = designer
                    work.save()
                except orm.Work.DoesNotExist:
                    pass
    def forwards(self, orm):
        "Write your forwards methods here."
        # Note: Remember to use orm['appname.ModelName'] rather than "from appname.models..."
        for row in all_portfolio_rows():
            try:
                work = orm.Work.objects.get(sidar_id=remove_file_extension(row['Filename']))
            except orm.Work.DoesNotExist:
                pass
            else:
                try:
                    work.size_as_text = clean(row[u'גודל'])
                except KeyError:
                    pass
                try:
                    work.publish_date_as_text = clean(row[u'תאריך'])
                except KeyError:
                    pass

                try:
                    if row[u'לקוח'] != '':
                        work.client = (orm.Client.objects.get_or_create(
                            name_he=clean(row[u'לקוח']),
                            defaults={'name_en': clean(row['Client'])}
                        ))[0]
                    else:
                        work.client = None
                except KeyError:
                    pass

                try:
                    if row[u'מילות מפתח'] != '':
                        keywords = []
                        for keyword in [keyword.strip() for keyword in html2text(row[u'מילות מפתח']).split(',')]:
                            if keyword != '':
                                keywords.append((orm.Keyword.objects.get_or_create(name_he=keyword)[0]))
                        work.keywords = keywords
                except KeyError:
                    pass

                work.save()
    def forwards(self, orm):
        "Write your forwards methods here."
        # Note: Remember to use orm['appname.ModelName'] rather than "from appname.models..."
        disciplines = orm.Discipline.objects.all()

        for row in all_portfolio_rows():
            filename = row['Filename']

            if len(filename) < 2:
                continue
            if filename[1] != '-':
                continue
            matched_discipline = None

            for discipline in disciplines:
                if discipline.name_en[0] == filename[0]:
                    matched_discipline = discipline

            if matched_discipline is None:
                print ('WARNING: Could not find a matching discipline for work "%s".' % filename)

            work = orm.Work.objects.get(sidar_id=remove_file_extension(row['Filename']))
            work.discipline = matched_discipline
            work.save()