Skip to content

Commit 64ef8ff

Browse files
authored
Hide unclaimed scratches (#1823)
* Don't show unclaimed scratches in frontend * logging. should be logger. * woops
1 parent d7cffb0 commit 64ef8ff

File tree

6 files changed

+31
-9
lines changed

6 files changed

+31
-9
lines changed

backend/coreapp/compiler_wrapper.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def compile_code(
182182
cc_cmd = cc_cmd.replace("-non_shared", "")
183183

184184
if compiler.platform != platforms.DUMMY and not compiler.path.exists():
185-
logging.warning("%s does not exist, creating it!", compiler.path)
185+
logger.warning("%s does not exist, creating it!", compiler.path)
186186
compiler.path.mkdir(parents=True)
187187

188188
# Run compiler
@@ -220,16 +220,16 @@ def compile_code(
220220
timeout=settings.COMPILATION_TIMEOUT_SECONDS,
221221
)
222222
et = round(time.time() * 1000)
223-
logging.debug(f"Compilation finished in: {et - st} ms")
223+
logger.debug(f"Compilation finished in: {et - st} ms")
224224
except subprocess.CalledProcessError as e:
225225
# Compilation failed
226226
msg = e.stdout
227227

228-
logging.debug("Compilation failed: %s", msg)
228+
logger.debug("Compilation failed: %s", msg)
229229
raise CompilationError(CompilerWrapper.filter_compile_errors(msg))
230230
except ValueError as e:
231231
# Shlex issue?
232-
logging.debug("Compilation failed: %s", e)
232+
logger.debug("Compilation failed: %s", e)
233233
raise CompilationError(str(e))
234234
except subprocess.TimeoutExpired:
235235
raise CompilationError("Compilation failed: timeout expired")
@@ -238,7 +238,7 @@ def compile_code(
238238
error_msg = (
239239
"Compiler did not create an object file: %s" % compile_proc.stdout
240240
)
241-
logging.debug(error_msg)
241+
logger.debug(error_msg)
242242
raise CompilationError(error_msg)
243243

244244
object_bytes = object_path.read_bytes()

backend/coreapp/filters/scratch.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from typing import Optional
2+
import django_filters
3+
4+
from django.db.models.query import QuerySet
5+
6+
from ..models.scratch import Scratch
7+
8+
9+
class ScratchFilter(django_filters.FilterSet):
10+
has_owner = django_filters.BooleanFilter(method="filter_has_owner")
11+
12+
def filter_has_owner(
13+
self, queryset: QuerySet[Scratch], name: str, value: Optional[bool]
14+
) -> QuerySet[Scratch]:
15+
if value is None:
16+
return queryset
17+
return queryset.filter(owner__isnull=not value)
18+
19+
class Meta:
20+
model = Scratch
21+
fields = ["platform", "compiler", "preset"]

backend/coreapp/views/scratch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from ..decorators.django import condition
3232
from ..diff_wrapper import DiffWrapper
3333
from ..error import CompilationError, DiffError
34+
from ..filters.scratch import ScratchFilter
3435
from ..filters.search import NonEmptySearchFilter
3536
from ..flags import Language
3637
from ..libraries import Library
@@ -292,7 +293,7 @@ class ScratchViewSet(
292293
.annotate(match_percent=match_percent)
293294
)
294295
pagination_class = ScratchPagination
295-
filterset_fields = ["platform", "compiler", "preset"]
296+
filterset_class = ScratchFilter
296297
filter_backends = [
297298
django_filters.rest_framework.DjangoFilterBackend,
298299
NonEmptySearchFilter,

frontend/src/app/(navfooter)/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default function Page() {
4141
</section>
4242
<section className="md:w-1/2 lg:w-3/4">
4343
<h2 className="mb-2 text-lg">Recent activity</h2>
44-
<ScratchList url="/scratch?page_size=20" />
44+
<ScratchList url="/scratch?page_size=20&has_owner=true" />
4545
</section>
4646
</div>
4747
</main>

frontend/src/app/(navfooter)/platform/[id]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default async function Page(props: { params: Promise<{ id: number }> }) {
8080

8181
<section>
8282
<ScratchList
83-
url={`/scratch?platform=${platform.id}&page_size=20`}
83+
url={`/scratch?platform=${platform.id}&page_size=20&has_owner=true`}
8484
item={ScratchItemPlatformList}
8585
isSortable={true}
8686
title={`Scratches (${scratch_count.num_scratches.toLocaleString("en-US")})`}

frontend/src/app/(navfooter)/preset/[id]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default async function Page(props: { params: Promise<{ id: number }> }) {
7070

7171
<section>
7272
<ScratchList
73-
url={`/scratch?preset=${preset.id}&page_size=20`}
73+
url={`/scratch?preset=${preset.id}&page_size=20&has_owner=true`}
7474
item={ScratchItemPresetList}
7575
isSortable={true}
7676
title={`Scratches (${preset.num_scratches.toLocaleString("en-US")})`}

0 commit comments

Comments
 (0)