Beispiel #1
0
def addPopOutIfExists(row):
  if (row["pop_out_image"] != '' or row["pop_out_txt"] != '' or row["pop_alt_txt"] != '' or row["pop_out_link"] != '' or row["pop_out_video"] is not None):
    args = { 'text': row["pop_out_txt"], 'alt_text': row["pop_alt_txt"], 'link': row["pop_out_link"], 'video': row["pop_out_video"] }
    kwargs = includeTranslatedFields(row, 'pop_out_txt', 'text', args)
    popout = SnuggetPopOut.objects.create(**kwargs)
    if row["pop_out_image"] != '':
      imageFile = os.path.join(dataDir, 'images/pop_out', row["pop_out_image"])
      with open(imageFile, 'rb') as f:
        data = File(f)
        popout.image.save(row["pop_out_image"], data, True)

    return popout
  else:
    return None
Beispiel #2
0
def addVideoSnugget(row, shapefile, section, filterColumn, filterVal):
  group = shapefile.getGroup()

  args = {
    'section': section,
    'group': group,
    filterColumn: filterVal,
    'text': row["text"],
    'video': row["video"],
    'percentage': row["intensity"],
    'order': row['txt_location']
  }
  kwargs = includeTranslatedFields(row, 'text', 'text', args)

  snugget = EmbedSnugget.objects.create(**kwargs)
  snugget.save()
Beispiel #3
0
def addTextSnugget(row, shapefile, section, filterColumn, filterVal):
  group = shapefile.getGroup()

  if filterVal is not None:
    args = {
      'section': section,
      'group': group,
      filterColumn: filterVal,
      'content': row["text"],
      'percentage': row["intensity"],
      'order': row['txt_location']
    }

    kwargs = includeTranslatedFields(row, 'text', 'content', args)
    snugget = TextSnugget.objects.create(**kwargs)
    snugget.pop_out = addPopOutIfExists(row)
    snugget.save()
Beispiel #4
0
def addSlideshowSnugget(row, shapefile, section, filterColumn, filterVal):
  group = shapefile.getGroup()

  args = {
    'section': section,
    'group': group,
    filterColumn: filterVal,
    'text': row["text"],
    'percentage': row["intensity"],
    'order': row['txt_location']
  }

  kwargs = includeTranslatedFields(row, 'text', 'text', args)

  snugget = SlideshowSnugget.objects.create(**kwargs)
  snugget.pop_out = addPopOutIfExists(row)
  addSlideshow(os.path.join(dataDir, 'images/', row["image_slideshow_folder"]), snugget)
  snugget.save()
Beispiel #5
0
def processRow(row, overwriteAll):
    section = row['section']
    removeOld(section)
    kwargs = {
        'title': section,
        'cost': row['cost'],
        'happy_text': row['happy'],
        'useful_text': row['useful'],
        'property_text': row['property'],
        'content_text': row['text'],
        'link_text': row['external_text'],
        'link': row['external_link'],
        'slug': row['slug']
    }

    kwargs = includeTranslatedFields(row, 'section', 'title', kwargs)
    kwargs = includeTranslatedFields(row, 'text', 'content_text', kwargs)
    kwargs = includeTranslatedFields(row, 'happy', 'happy_text', kwargs)
    kwargs = includeTranslatedFields(row, 'useful', 'useful_text', kwargs)
    kwargs = includeTranslatedFields(row, 'property', 'property_text', kwargs)
    kwargs = includeTranslatedFields(row, 'external_text', 'link_text', kwargs)

    pa = PreparednessAction.objects.create(**kwargs)
    pa.save()

    if row["image"] != '':
        imageFile = os.path.join(imagesDir, row["image"])
        with open(imageFile, 'rb') as f:
            data = File(f)
            pa.image.save(row["image"], data, True)

    if row["external_icon"] != '':
        imageFile = os.path.join(imagesDir, row["external_icon"])
        with open(imageFile, 'rb') as f:
            data = File(f)
            pa.link_icon.save(row["external_icon"], data, True)

    print('Created preparedness section:', pa.title)