Преглед изворни кода

adding function for adding images

main
Simon Bowie пре 2 година
родитељ
комит
a0df5cb5f2
5 измењених фајлова са 35 додато и 21 уклоњено
  1. +4
    -3
      web/app/random.py
  2. +5
    -4
      web/app/solr.py
  3. +23
    -11
      web/app/templates/images.html
  4. +1
    -1
      web/app/templates/index.html
  5. +2
    -2
      web/app/templates/titles.html

+ 4
- 3
web/app/random.py Прегледај датотеку



# route for getting ten random images # route for getting ten random images
@random.route('/random/images/') @random.route('/random/images/')
def ten_random_images():
results = solr.get_ten_random_images()
return render_template('images.html', results=results)
def random_images():
images = solr.get_random_images(4)
additional_images = solr.get_random_images(6)
return render_template('images.html', images=images, additional_images=additional_images)

+ 5
- 4
web/app/solr.py Прегледај датотеку

i += 1 i += 1
return output return output


def get_ten_random_images():
def get_random_images(number):
core = 'all' core = 'all'
output = [] output = []
i = 0 i = 0
while i <= 9:
while i <= number-1:
search_results = random_search(core) search_results = random_search(core)
results = search_results[0] results = search_results[0]
for result in results: for result in results:
if ops.get_images(result['doc_ref']): if ops.get_images(result['doc_ref']):
image = ops.get_images(result['doc_ref']) image = ops.get_images(result['doc_ref'])
result.update(image)
output.append(result)
dict = {'id': result['id']}
dict.update(image)
output.append(dict)
i += 1 i += 1
return output return output



+ 23
- 11
web/app/templates/images.html Прегледај датотеку

<span class="info" style="display: none;"> <span class="info" style="display: none;">
<span class="operations">↝ new display of random images from dataset;</span> <span class="operations">↝ new display of random images from dataset;</span>
</span> </span>
<button onclick="" title="add one">+</button>
<button onclick="addRandomImage()" title="add one">+</button>
<span class="info" style="display: none;"> <span class="info" style="display: none;">
<span class="operations">↝ add a random image from dataset;</span> <span class="operations">↝ add a random image from dataset;</span>
</span> </span>
<button onclick="removeRandomImage()" title="remove one">-</button>
<button onclick="removeRandomImage()" title="remove one">-</button>
<span class="info" style="display: none;"> <span class="info" style="display: none;">
<span class="operations">↝ remove a random image from page;</span> <span class="operations">↝ remove a random image from page;</span>
</span> </span>
<a href="{{ url_for('main.index') }}" class="arrow-back h1 text-left contrast" style="color: var(--color-lightyellow) !important;" title="back to index"> ⇽ </a> <a href="{{ url_for('main.index') }}" class="arrow-back h1 text-left contrast" style="color: var(--color-lightyellow) !important;" title="back to index"> ⇽ </a>
</div> </div>



<div class="row">
<div class="col m-5">
<p class="h1 text-center contrast">a Scattering of Images</p>
</div>
<div class="row">
<div class="col m-5">
<p class="h1 text-center contrast">a Scattering of Images</p>
</div> </div>
</div>


<div class="container-fluid compare">
<div id="image_container" class="container-fluid compare">


{% for result in results %}
{% for image in images %}


<img class="img-fluid" src="data:image/jpg;base64,{{ result['image'] }}" alt="Drawing accompanying patent for {{ result['title'] }}" />
<img class="img-fluid" src="data:image/jpg;base64,{{ image['image'] }}" alt="Drawing accompanying patent for {{ image['id'] }}" />


{% endfor %} {% endfor %}


</div>
</div>

<script type="text/javascript">
var images = {{ additional_images|tojson }};

x = 0;

function addRandomImage(){
var record_array = images[x];
document.querySelector('#image_container').innerHTML += "<img class='img-fluid' src='data:image/jpg;base64," + record_array['image'] + "' alt='Drawing accompanying patent for " + record_array['id'] + "' />";
x++;
window.scrollTo(0, document.body.scrollHeight);
}
</script>


{% endblock %} {% endblock %}

+ 1
- 1
web/app/templates/index.html Прегледај датотеку



<div class="col text-center p-2"> <div class="col text-center p-2">
<!-- random images --> <!-- random images -->
<a href="{{ url_for('random.ten_random_images') }}">a scattering of images</a>
<a href="{{ url_for('random.random_images') }}">a scattering of images</a>
</div> </div>
</div> </div>



+ 2
- 2
web/app/templates/titles.html Прегледај датотеку

<span class="info" style="display: none;"> <span class="info" style="display: none;">
<span class="operations">↝ new display of random titles from dataset;</span> <span class="operations">↝ new display of random titles from dataset;</span>
</span> </span>
<button onclick="addRandomTitle()" title="add one">+</button>
<button onclick="addRandomTitle()" title="add one">+</button>
<span class="info" style="display: none;"> <span class="info" style="display: none;">
<span class="operations">↝ add a random title from dataset;</span> <span class="operations">↝ add a random title from dataset;</span>
</span> </span>
<button onclick="removeRandomTitle()" title="remove one">-</button>
<button onclick="removeRandomTitle()" title="remove one">-</button>
<span class="info" style="display: none;"> <span class="info" style="display: none;">
<span class="operations">↝ remove a random title from page;</span> <span class="operations">↝ remove a random title from page;</span>
</span> </span>

Loading…
Откажи
Сачувај