Skip to content

Commit

Permalink
Added autopep8 config and ran on codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
dsimmons87 committed Feb 6, 2023
1 parent 9acb347 commit ff70387
Show file tree
Hide file tree
Showing 64 changed files with 600 additions and 467 deletions.
26 changes: 26 additions & 0 deletions openra/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from openra.models import Comments
from openra.models import UnsubscribeComments


class LatestRevisionListFilter(admin.SimpleListFilter):
title = 'Latest Revision'

Expand All @@ -37,55 +38,80 @@ def queryset(self, request, queryset):
if self.value() == 'no':
return queryset.exclude(next_rev=0)


class MapsAdmin(admin.ModelAdmin):
date_hierarchy = 'posted'

def is_latest_revision(obj):
return obj.next_rev == 0
is_latest_revision.short_description = 'Latest Revision'
is_latest_revision.boolean = True

list_display = ('map_hash', 'title', 'user', 'posted', 'game_mod', 'amount_reports', 'mapformat', 'parser', 'advanced_map', 'lua', 'downloading', is_latest_revision)
list_filter = ('game_mod', 'mapformat', 'advanced_map', 'lua', 'parser', LatestRevisionListFilter)


admin.site.register(Maps, MapsAdmin)

admin.site.register(MapCategories)


class MapUpgradeLogsAdmin(admin.ModelAdmin):
ordering = ('-date_run',)
list_display = ('map_id', 'date_run', 'from_version', 'to_version')
list_filter = ('from_version', 'to_version')


admin.site.register(MapUpgradeLogs, MapUpgradeLogsAdmin)


class UnsubscribeCommentsAdmin(admin.ModelAdmin):
date_hierarchy = 'unsubscribed'
list_display = ('item_id', 'user', 'unsubscribed')


admin.site.register(UnsubscribeComments, UnsubscribeCommentsAdmin)


class CommentsAdmin(admin.ModelAdmin):
date_hierarchy = 'posted'
list_display = ('item_id', 'user', 'posted', 'content', 'item_type', 'is_removed')


admin.site.register(Comments, CommentsAdmin)


class LintsAdmin(admin.ModelAdmin):
date_hierarchy = 'posted'
list_display = ('map_id', 'version_tag', 'posted', 'pass_status')
list_filter = ('pass_status',)


admin.site.register(Lints, LintsAdmin)


class ReportsAdmin(admin.ModelAdmin):
date_hierarchy = 'posted'
list_display = ('ex_id', 'user', 'posted', 'reason', 'infringement')
list_filter = ('infringement',)


admin.site.register(Reports, ReportsAdmin)


class RatingAdmin(admin.ModelAdmin):
date_hierarchy = 'posted'
list_display = ('ex_id', 'user', 'posted', 'rating')


admin.site.register(Rating, RatingAdmin)


class ScreenshotsAdmin(admin.ModelAdmin):
date_hierarchy = 'posted'
list_display = ('ex_id', 'user', 'posted', 'map_preview')


admin.site.register(Screenshots, ScreenshotsAdmin)

# Add the registration date to the user list
Expand Down
2 changes: 1 addition & 1 deletion openra/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,5 @@ def download_map(request, map_hash):
response['Content-Disposition'] = 'attachment; filename = %s' % serve_filename
response['Content-Length'] = os.path.getsize(oramap_path)

Maps.objects.filter(id=map_object.id).update(downloaded=map_object.downloaded+1)
Maps.objects.filter(id=map_object.id).update(downloaded=map_object.downloaded + 1)
return response
1 change: 1 addition & 0 deletions openra/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.apps import AppConfig


class OpenraConfig(AppConfig):
name = "openra"

Expand Down
31 changes: 18 additions & 13 deletions openra/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from django.contrib.auth import authenticate, login
from django.contrib.auth.models import User

def set_session_to_remember_auth(request, remember:bool):

def set_session_to_remember_auth(request, remember: bool):
if remember:
request.session.set_expiry(None)
else:
Expand All @@ -16,43 +17,47 @@ def try_login(request):
_ensure_active_user(user)
login(request, user)


class Credentials:
username:str
password:str
username: str
password: str

def __init__(self, username:str, password:str):
def __init__(self, username: str, password: str):
self.username = username
self.password = password

def are_both_provided(self):
return self.username != '' and self.password != ''


def _extract_credentials(request):
credentials = Credentials(
credentials = Credentials(
request.POST.get('ora_username', '').strip(),
request.POST.get('ora_password', '').strip()
)
if not credentials.are_both_provided():
raise ExceptionLoginFailed('incorrect')
return credentials

def _authenticate_credentials(credentials:Credentials):

def _authenticate_credentials(credentials: Credentials):
user = authenticate(
username = credentials.username,
password = credentials.password
username=credentials.username,
password=credentials.password
)
if user == None:
if user is None:
raise ExceptionLoginFailed('incorrect')
return user

def _ensure_active_user(user:User):

def _ensure_active_user(user: User):
if not user.is_active:
raise ExceptionLoginFailed('inactive')


class ExceptionLoginFailed(Exception):

reason:str
reason: str

def __init__(self, reason:str):
def __init__(self, reason: str):
self.reason = reason

4 changes: 2 additions & 2 deletions openra/classes/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import List


class ExceptionBase(Exception):

message: str
Expand All @@ -8,7 +9,7 @@ class ExceptionBase(Exception):

def __init__(self):
self.message = ''
self.detail = []
self.detail = []
self.friendly = 'An error occurred, please try again later'

def get_full_details(self):
Expand All @@ -23,4 +24,3 @@ def get_full_details(self):

def print_full_details(self):
print(self.get_full_details())

14 changes: 9 additions & 5 deletions openra/classes/file_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

from openra.classes.exceptions import ExceptionBase


class FileLocation:

fs: FS
path: str
file: str

def __init__(self, fs:FS, path:str, file:str):
def __init__(self, fs: FS, path: str, file: str):
self.fs = fs
self.path = path
self.file = file
Expand All @@ -36,7 +37,7 @@ def get_os_path(self):
except Exception as exception:
raise ExceptionFileLocationGetOSPath(exception, self.fs, self.path, self.file)

def copy_to_tempfs(self, filename:str):
def copy_to_tempfs(self, filename: str):
try:
temp_fs = TempFS()
copy.copy_file(
Expand All @@ -57,22 +58,25 @@ def copy_to_tempfs(self, filename:str):
except Exception as exception:
raise ExceptionFileLocationCopyToTempFS(exception, self.fs, self.path, self.file, filename)


class ExceptionFileLocationGetOSDir(ExceptionBase):
def __init__(self, exception, fs:FS, path:str, file:str):
def __init__(self, exception, fs: FS, path: str, file: str):
super().__init__()
self.message = "An exception occured while trying to get the os dir"
self.detail.append('fs type: ' + str(type(fs)))
self.detail.append('path: ' + path)
self.detail.append('file: ' + file)
self.detail.append('message: ' + str(exception))


class ExceptionFileLocationGetOSPath(ExceptionFileLocationGetOSDir):
def __init__(self, exception, fs:FS, path:str, file:str):
def __init__(self, exception, fs: FS, path: str, file: str):
super().__init__(exception, fs, path, file)
self.message = "An exception occured while trying to get the os path"


class ExceptionFileLocationCopyToTempFS(ExceptionBase):
def __init__(self, exception, fs:FS, path:str, file:str, target:str):
def __init__(self, exception, fs: FS, path: str, file: str, target: str):
super().__init__()
self.message = "An exception occured while trying to copy a file to a TempFS"
self.detail.append('fs type: ' + str(type(fs)))
Expand Down
4 changes: 2 additions & 2 deletions openra/classes/map_hash.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

class MapHash:

map_hash:str
map_hash: str

def __init__(self, map_hash:str):
def __init__(self, map_hash: str):
self.map_hash = map_hash
6 changes: 3 additions & 3 deletions openra/classes/release.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

class Release:

mod:str
version:str
mod: str
version: str

def __init__(self, mod:str, version):
def __init__(self, mod: str, version):
self.mod = mod
self.version = version

Expand Down
2 changes: 2 additions & 0 deletions openra/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from openra.services.map_search import MapSearch
from openra.services.utility import Utility


class Container(containers.DeclarativeContainer):
config = providers.Configuration()

Expand Down Expand Up @@ -60,5 +61,6 @@ class Container(containers.DeclarativeContainer):
MapSearch
)


container = Container()
container.config.from_dict(settings.__dict__)
14 changes: 7 additions & 7 deletions openra/content.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@


auth = {
'inactive':'User is inactive, please activate account first.',
'incorrect':'Incorrect username or password.',
'inactive': 'User is inactive, please activate account first.',
'incorrect': 'Incorrect username or password.',
}

titles = {
'home':'',
'login':'Sign In',
'logout':'Sign Out',
'home': '',
'login': 'Sign In',
'logout': 'Sign Out',
# TODO reformat like others
'feed':'OpenRA Resource Center - RSS Feed',
'search':'Search',
'feed': 'OpenRA Resource Center - RSS Feed',
'search': 'Search',

}
2 changes: 1 addition & 1 deletion openra/facades.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@


@inject
def log(log:Log=Provide['log']):
def log(log: Log = Provide['log']):
return log
11 changes: 5 additions & 6 deletions openra/fakes/engine_file_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@

class FakeEngineFileRepository:

engine_exists:bool
imported:List[Release]
engine_exists: bool
imported: List[Release]

def __init__(self):
self.imported = []
self.engine_exists = False

def exists(self, release:Release):
def exists(self, release: Release):
return self.engine_exists

def get_path(self, release:Release):
def get_path(self, release: Release):
if not self.engine_exists:
raise ExceptionEngineFolderNotFound(TempFS(), release, 'fake')

Expand All @@ -31,8 +31,7 @@ def get_path(self, release:Release):
file
)


def import_appimage(self, release:Release, appimage_location:FileLocation):
def import_appimage(self, release: Release, appimage_location: FileLocation):
self.imported.append(release)

temp_fs = TempFS()
Expand Down
8 changes: 4 additions & 4 deletions openra/fakes/file_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

class FakeFileDownloader:

downloaded:list
downloaded: list

def __init__(self):
self.downloaded = []

def download_file(self, url:str, filename:str):
def download_file(self, url: str, filename: str):
self.downloaded.append({
'url':url,
'filename':filename
'url': url,
'filename': filename
})

temp_fs = TempFS()
Expand Down
1 change: 1 addition & 0 deletions openra/fakes/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from openra.services.github import GithubRelease, GithubReleaseAsset


class FakeGithub():

only_one_release = False
Expand Down
Loading

0 comments on commit ff70387

Please sign in to comment.