Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template based challenges - Backend #2925

Closed
wants to merge 10 commits into from

Conversation

KhalidRmb
Copy link
Member

This is the backend for the template based challenges, creating a new model and serializers. Also, created a new API to fetch all template based challenges. Also, modified the challenge creation API to allow for template based challenges.
@RishabhJain2018 @deshraj @Ram81

@KhalidRmb KhalidRmb changed the title Template based challenges. Template based challenges - Backend Aug 3, 2020
title = models.CharField(max_length=500)
template_file = models.FileField(
upload_to=RandomFileName("templates")
) # stores the challenge zip file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change this to # Stores the challenge config zip file

@@ -677,20 +681,78 @@ def create_challenge_using_zip_file(request, challenge_host_team_pk):
"""
Creates a challenge using a zip file.
"""
if request.data.get("is_template_challenge"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to is_challenge_template

if request.data.get("is_template_challenge"):
is_template_challenge = True
else:
is_template_challenge = False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

# All files download and extract location.
BASE_LOCATION = tempfile.mkdtemp()

if is_template_challenge:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

samer here

if is_template_challenge:
template_id = request.data.get("templateId")
try:
template = ChallengeTemplate.objects.get(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you create a function like get_challenge_model for the challenge template get too. And use that here.

challenge_phases_data_from_hosts = challenge_data_from_hosts.get(
"challenge_phases"
)
for i in range(len(challenge_phases_data)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename i to data

] = challenge_phases_data_from_hosts.get("challenge_phases")[
i
].get(
"name"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here. Use an array of field names to loop through and override values if present in request


# Mapping the dataset splits data to that in yaml_file_data
dataset_splits = yaml_file_data["dataset_splits"]
for i in range(len(dataset_splits)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename i to split

challenges = ChallengeTemplate.objects.filter(**q_params).order_by("-pk")
serializer = ChallengeTemplateSerializer(challenges, many=True)
response_data = serializer.data
return Response(response_data, status=status.HTTP_200_OK)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add newline

apps/challenges/views.py Show resolved Hide resolved
@@ -181,4 +181,9 @@
views.manage_worker,
name="manage_worker",
),
url(
r"^get_all_challenge_templates$",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @KhalidRmb can you please add a / at the end of this url as we have all the api's ending with / only.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will do.

@RishabhJain2018
Copy link
Member

@KhalidRmb What is the plan on resolving the comments here?
cc: @Ram81 @deshraj

@KhalidRmb
Copy link
Member Author

KhalidRmb commented Aug 16, 2020

@RishabhJain2018 So, I kept this on hold until finishing the github based challenges hopefully this week. I was basically waiting for Kajol's frontend changes to continue working on the backend (since I've moved on to Github challenges) but as she's understandably occupied, I'll continue with this and the frontend after GitHub based challenges.
cc: @Ram81

@RishabhJain2018
Copy link
Member

sounds good, Thanks for letting me know.

@KhalidRmb
Copy link
Member Author

Closing on account of #2989

@KhalidRmb KhalidRmb closed this Sep 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants