Skip to content

Commit

Permalink
Change all varables to snake case in backend
Browse files Browse the repository at this point in the history
  • Loading branch information
GustavAndreasson committed Feb 11, 2024
1 parent 3f7c0ec commit 41e7bc4
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 30 deletions.
4 changes: 2 additions & 2 deletions records/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ class GroupsInline(admin.TabularInline):

@admin.register(Artist)
class ArtistAdmin(admin.ModelAdmin):
fields = ["id", "name", "description", "image", "updated", "collectionUpdated"]
fields = ["id", "name", "description", "image", "updated", "collection_updated"]
inlines = [MembersInline, GroupsInline]
list_display = ("id", "name", "description", "image", "updated", "collectionUpdated")
list_display = ("id", "name", "description", "image", "updated", "collection_updated")
search_fields = ["name"]
actions = [
reset_updated,
Expand Down
6 changes: 3 additions & 3 deletions records/discogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,11 @@ def getArtistReleases(artist_id: int, check_main=True) -> list[ArtistRelease]:
T = TypeVar("T", ArtistRelease, CollectionRelease)


def __getPaginatedCollection(uri: str, collectionType: type[T], check_main=False) -> list[T]:
def __getPaginatedCollection(uri: str, collection_type: type[T], check_main=False) -> list[T]:
page = 0
page_size = 25
pages = 100
collection: list[collectionType] = []
collection: list[collection_type] = []
progress.updateProgress("discogs", 0)
try:
while True:
Expand All @@ -288,7 +288,7 @@ def __getPaginatedCollection(uri: str, collectionType: type[T], check_main=False
pagination = Pagination.model_validate(response.get("pagination"))
if pagination.items == 0:
break
releases = [collectionType.model_validate(r) for r in response.get("releases") or []]
releases = [collection_type.model_validate(r) for r in response.get("releases") or []]
collection.extend(releases)
pages = pagination.pages
if page >= pages:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.8 on 2024-02-09 13:28

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('records', '0018_recordartists_anv'),
]

operations = [
migrations.RenameField(
model_name='artist',
old_name='collectionUpdated',
new_name='collection_updated',
),
]
6 changes: 3 additions & 3 deletions records/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Artist(models.Model):
description = models.TextField(blank=True, null=True)
image = models.CharField(max_length=255, blank=True, null=True)
updated = models.DateField(blank=True, null=True)
collectionUpdated = models.DateField(blank=True, null=True)
collection_updated = models.DateField(blank=True, null=True)
members = models.ManyToManyField("self", through="ArtistMembers", symmetrical=False)

def __str__(self):
Expand All @@ -33,7 +33,7 @@ def to_dict(self, full=True):
group_relations = ArtistMembers.objects.filter(member=self)
groups = [{"artist": gr.group.to_dict(False), "active": gr.active} for gr in group_relations]
updated = str(self.updated) if self.updated else None
collectionUpdated = str(self.collectionUpdated) if self.collectionUpdated else None
collection_updated = str(self.collection_updated) if self.collection_updated else None
return {
"id": self.id,
"name": self.name,
Expand All @@ -42,7 +42,7 @@ def to_dict(self, full=True):
"members": members,
"groups": groups,
"updated": updated,
"collectionUpdated": collectionUpdated,
"collectionUpdated": collection_updated,
}

def save(self, *args, **kwargs):
Expand Down
12 changes: 6 additions & 6 deletions records/services/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,19 @@ def collectArtistReleases(artist: Artist) -> bool:
except discogs.DiscogsError as de:
logger.info("Did not find releases for " + artist.name + " on discogs\n" + str(de))
return False
artist.collectionUpdated = date.today()
artist.collection_updated = date.today()
artist.save()
return True


def getArtists(artistList: list[str]) -> dict[str, Artist]:
def getArtists(artist_list: list[str]) -> dict[str, Artist]:
artists: dict[str, Artist] = {}
for artistIdentifier in artistList:
for artist_identifier in artist_list:
try:
if artistIdentifier.isdigit():
artists[artistIdentifier] = Artist.objects.get(id=int(artistIdentifier))
if artist_identifier.isdigit():
artists[artist_identifier] = Artist.objects.get(id=int(artist_identifier))
else:
artists[artistIdentifier] = Artist.objects.get(sname=artistIdentifier[:20].lower())
artists[artist_identifier] = Artist.objects.get(sname=artist_identifier[:20].lower())
except (Artist.DoesNotExist, Artist.MultipleObjectsReturned):
pass
return artists
12 changes: 6 additions & 6 deletions records/services/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,21 +241,21 @@ def downloadCover(record: Record) -> bool:
return False


def getReleases(releaseList: list[str]) -> dict[str, Record]:
def getReleases(release_list: list[str]) -> dict[str, Record]:
releases = {}
for releaseId in releaseList:
for release_id in release_list:
try:
releases[releaseId] = Record.objects.get(id=int(releaseId))
releases[release_id] = Record.objects.get(id=int(release_id))
except (Record.DoesNotExist, Record.MultipleObjectsReturned):
pass
return releases


def getMasters(masterList: list[str]) -> dict[str, Record]:
def getMasters(master_list: list[str]) -> dict[str, Record]:
masters = {}
for masterId in masterList:
for master_id in master_list:
try:
masters[masterId] = Record.objects.filter(master=int(masterId))[0]
masters[master_id] = Record.objects.filter(master=int(master_id))[0]
except IndexError:
pass
return masters
2 changes: 1 addition & 1 deletion records/views/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def updateArtist(request, artist_id):

def getArtistReleases(request, artist_id):
artist = get_object_or_404(Artist, id=artist_id)
if artist.collectionUpdated is None:
if artist.collection_updated is None:
progress.init(request, ["discogs", "create"])
artistService.collectArtistReleases(artist)
progress.clearProcesses(["discogs", "create"])
Expand Down
18 changes: 9 additions & 9 deletions records/views/multidata.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@


def getMultipleData(request):
artistListStr = unquote(request.GET.get("artists", ""))
artistList = artistListStr.split(",") if len(artistListStr) > 0 else []
artists = artistService.getArtists(artistList)
artist_list_str = unquote(request.GET.get("artists", ""))
artist_list = artist_list_str.split(",") if len(artist_list_str) > 0 else []
artists = artistService.getArtists(artist_list)
# labels = unquote(request.GET.get("labels", ""))
releaseListStr = unquote(request.GET.get("releases", ""))
releaseList = releaseListStr.split(",") if len(releaseListStr) > 0 else []
releases = recordService.getReleases(releaseList)
masterListStr = unquote(request.GET.get("masters", ""))
masterList = masterListStr.split(",") if len(masterListStr) > 0 else []
masters = recordService.getMasters(masterList)
release_list_str = unquote(request.GET.get("releases", ""))
release_list = release_list_str.split(",") if len(release_list_str) > 0 else []
releases = recordService.getReleases(release_list)
master_list_str = unquote(request.GET.get("masters", ""))
master_list = master_list_str.split(",") if len(master_list_str) > 0 else []
masters = recordService.getMasters(master_list)
return HttpResponse(
json.dumps(
{
Expand Down

0 comments on commit 41e7bc4

Please sign in to comment.