Skip to content

Commit

Permalink
Merge pull request #32 from RydalWater/reading-progress
Browse files Browse the repository at this point in the history
Post-v0.1.4 Fixes, Updates and Enhancements (Reading progress)
  • Loading branch information
RydalWater authored Dec 22, 2024
2 parents bcee2a9 + 2fb7ee9 commit 4bf3c68
Show file tree
Hide file tree
Showing 13 changed files with 2,061 additions and 187 deletions.
2 changes: 1 addition & 1 deletion openlibrarian_root/almanac/tests/test_relays.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def tearDown(self):
"""
self.driver.close()

class RelaysUnitTestCase(SettingsUnitTestCase):
class RelaysUnitTestCase(TestCase):
"""
Unit Tests for the relays page
"""
Expand Down
94 changes: 47 additions & 47 deletions openlibrarian_root/almanac/tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,58 @@
from time import sleep


# class SettingsFunctionalTestCase(TestCase):
# """
# Functional Tests for the about page
# """
# def setUp(self):
# """
# Set Up and instantiate driver
# """
# self.url = "/almanac/"
# self.driver = webdriver.Firefox()
# self.driver.get(f"http://127.0.0.1:8000/login-npub/")
# self.driver.find_element(by=By.ID, value="npub").send_keys("npub1dpzan5jvyp0kl0sykx29397f7cnazgwa3mtkfyt8d9gga7htm9xsdsk85n")
# self.driver.find_element(by=By.ID, value="submit").click()
# sleep(1)
class SettingsFunctionalTestCase(TestCase):
"""
Functional Tests for the settings page
"""
def setUp(self):
"""
Set Up and instantiate driver
"""
self.url = "/almanac/"
self.driver = webdriver.Firefox()
self.driver.get(f"http://127.0.0.1:8000/login-npub/")
self.driver.find_element(by=By.ID, value="npub").send_keys("npub1dpzan5jvyp0kl0sykx29397f7cnazgwa3mtkfyt8d9gga7htm9xsdsk85n")
self.driver.find_element(by=By.ID, value="submit").click()
sleep(1)

# def test_almanac_profile(self):
# """
# Test Almanac Profile Button
# """
# self.driver.get(f"http://127.0.0.1:8000{self.url}")
# self.driver.find_element(by=By.ID, value="profile").click()
# self.assertIn("/profile/", self.driver.current_url)
def test_almanac_profile(self):
"""
Test Almanac Profile Button
"""
self.driver.get(f"http://127.0.0.1:8000{self.url}")
self.driver.find_element(by=By.ID, value="profile").click()
self.assertIn("/profile/", self.driver.current_url)

# def test_almanac_relays(self):
# """
# Test Almanac Relays Button
# """
# self.driver.get(f"http://127.0.0.1:8000{self.url}")
# self.driver.find_element(by=By.ID, value="relays").click()
# self.assertIn("/relays/", self.driver.current_url)
def test_almanac_relays(self):
"""
Test Almanac Relays Button
"""
self.driver.get(f"http://127.0.0.1:8000{self.url}")
self.driver.find_element(by=By.ID, value="relays").click()
self.assertIn("/relays/", self.driver.current_url)

# def test_almanac_friends(self):
# """
# Test Almanac Friends Button
# """
# self.driver.get(f"http://127.0.0.1:8000{self.url}")
# self.driver.find_element(by=By.ID, value="friends").click()
# self.assertIn("/friends/", self.driver.current_url)
def test_almanac_friends(self):
"""
Test Almanac Friends Button
"""
self.driver.get(f"http://127.0.0.1:8000{self.url}")
self.driver.find_element(by=By.ID, value="friends").click()
self.assertIn("/friends/", self.driver.current_url)

# def test_almanac_export_import(self):
# """
# Test Almanac Export/Import Button
# """
# self.driver.get(f"http://127.0.0.1:8000{self.url}")
# self.driver.find_element(by=By.ID, value="transfers").click()
# self.assertIn("/transfers/", self.driver.current_url)
def test_almanac_export_import(self):
"""
Test Almanac Export/Import Button
"""
self.driver.get(f"http://127.0.0.1:8000{self.url}")
self.driver.find_element(by=By.ID, value="transfers").click()
self.assertIn("/transfers/", self.driver.current_url)

# def tearDown(self):
# """
# Tear Down function to close driver
# """
# self.driver.close()
def tearDown(self):
"""
Tear Down function to close driver
"""
self.driver.close()

class SettingsUnitTestCase(TestCase):
"""
Expand Down
39 changes: 35 additions & 4 deletions openlibrarian_root/circulation_desk/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from utils.Profile import fetch_profile_info, edit_relay_list
from utils.Library import fetch_libraries
from utils.Interests import fetch_interests
from utils.Progress import fetch_progress, Progress
from circulation_desk.forms import SeedForm, NpubForm, NsecForm
import asyncio

Expand Down Expand Up @@ -59,7 +60,17 @@ async def login_npub_view(request):
libraries, interests = await asyncio.gather(*tasks)
nym = profile.get('nym')

await async_set_session_info(request, npub=npub, nym=nym, relays=relays, profile=profile, interests=interests, libraries=libraries)
# Get list of ISBNs and then create progress object
isbns = []
for library in libraries:
if library["s"] in ("CR", "HR"):
for book in library["b"]:
if "Hidden" not in book["i"]:
isbns.append(book["i"])
progress = await fetch_progress(npub=npub, isbns=isbns, relays=relays)


await async_set_session_info(request, npub=npub, nym=nym, relays=relays, profile=profile, interests=interests, libraries=libraries, progress=progress)
return redirect('circulation_desk:index')
else:
context = {
Expand Down Expand Up @@ -103,7 +114,16 @@ async def login_nsec_view(request):
libraries, interests = await asyncio.gather(*tasks)
nym = profile.get('nym')

await async_set_session_info(request,npub=npub,nsec=nsec,nym=nym,relays=relays, profile=profile, libraries=libraries, interests=interests)
# Get list of ISBNs and then create progress object
isbns = []
for library in libraries:
if library["s"] in ("CR", "HR"):
for book in library["b"]:
if "Hidden" not in book["i"]:
isbns.append(book["i"])
progress = await fetch_progress(npub=npub, isbns=isbns, relays=relays)

await async_set_session_info(request,npub=npub,nsec=nsec,nym=nym,relays=relays, profile=profile, libraries=libraries, interests=interests, progress=progress)
return redirect('circulation_desk:index')
else:
context = {
Expand Down Expand Up @@ -150,7 +170,16 @@ async def login_seed_view(request):
libraries, interests = await asyncio.gather(*tasks)
nym = profile.get('nym')

await async_set_session_info(request,npub=npub,nsec=nsec,nym=nym,relays=relays, profile=profile, libraries=libraries, interests=interests)
# Get list of ISBNs and then create progress object
isbns = []
for library in libraries:
if library["s"] in ("CR", "HR"):
for book in library["b"]:
if "Hidden" not in book["i"]:
isbns.append(book["i"])
progress = await fetch_progress(npub=npub, isbns=isbns, relays=relays)

await async_set_session_info(request,npub=npub,nsec=nsec,nym=nym,relays=relays, profile=profile, libraries=libraries, interests=interests, progress=progress)
return redirect('circulation_desk:index')
else:
context = {
Expand Down Expand Up @@ -242,9 +271,11 @@ async def create_account_confirm_view(request):
libraries = await fetch_libraries(npub=temp_keys['tnpub'], nsec=nsec, relays=mod_relays)
# Get default interests
interests = await fetch_interests(temp_keys['tnpub'], mod_relays)
# Set Default Progress
progress = []

# Set Session Data
await async_set_session_info(request,libraries=libraries, interests=interests, relays=mod_relays, npub=temp_keys['tnpub'], nsec=nsec)
await async_set_session_info(request,libraries=libraries, interests=interests, relays=mod_relays, npub=temp_keys['tnpub'], nsec=nsec, progress=progress)

# Remove temp keys from session
await async_remove_session_info(request, tnpub=temp_keys['tnpub'], tnsec=temp_keys['tnsec'])
Expand Down
6 changes: 3 additions & 3 deletions openlibrarian_root/library/templates/library/library.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
<div class="row">
<div class="col-1"></div>
<div class="col-10">
<a id="npub" href="{% url 'library:library_shelves' %}" class="btn btn-sm btn-primary w-100"><i class="fa-solid fa-book"></i> Shelves</a>
<a id="shelves" href="{% url 'library:library_shelves' %}" class="btn btn-sm btn-primary w-100"><i class="fa-solid fa-book"></i> Shelves</a>
</div>
</div>
<div class="row mt-2">
<div class="col-1"></div>
<div class="col-10">
<a id="nsec" href="{% url 'library:library' %}" class="btn btn-sm btn-primary w-100 disabled"><i class="fa-solid fa-star"></i> Reviews</a>
<a id="reviews" href="{% url 'library:library' %}" class="btn btn-sm btn-primary w-100 disabled"><i class="fa-solid fa-star"></i> Reviews</a>
</div>
</div>
<div class="row mt-2">
<div class="col-1"></div>
<div class="col-10">
<a id="nsec" href="{% url 'library:library' %}" class="btn btn-sm btn-primary w-100 disabled"><i class="fa-solid fa-chart-line"></i> Statistics</a>
<a id="statistics" href="{% url 'library:library' %}" class="btn btn-sm btn-primary w-100 disabled"><i class="fa-solid fa-chart-line"></i> Statistics</a>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit 4bf3c68

Please sign in to comment.