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

Add Sublet Drafting #271

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

Add Sublet Drafting #271

wants to merge 16 commits into from

Conversation

dr-Jess
Copy link
Contributor

@dr-Jess dr-Jess commented Mar 17, 2024

  • Add sublet drafting field
  • Implement validation to ensure minimum required fields when publishing

Copy link

codecov bot commented Mar 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.50%. Comparing base (a4f5305) to head (8859861).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #271      +/-   ##
==========================================
+ Coverage   91.46%   91.50%   +0.03%     
==========================================
  Files          60       60              
  Lines        2543     2554      +11     
==========================================
+ Hits         2326     2337      +11     
  Misses        217      217              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

)
)
]:
raise serializers.ValidationError(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha this doesn't work I don't know why haha 😭 will fix

Copy link
Member

Choose a reason for hiding this comment

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

thanks haha. is there any way we can break this down? i get that its the least amount of lines but i feel like its getting a little hard to read

Copy link
Member

Choose a reason for hiding this comment

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

would really suggest breaking it into first checking if the function came from a PUT/PATCH or a POST

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so it would seem that patching with "" as the address passes the old address into validated_data??? really not sure why but will investigate further tomorrow.

Copy link
Member

Choose a reason for hiding this comment

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

that is weird ...

Copy link
Member

@judtinzhang judtinzhang left a comment

Choose a reason for hiding this comment

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

LGTM! Code cleanup comments


def field_bad(field, validated_data, instance):
if field in validated_data:
if not validated_data[field]:
Copy link
Member

Choose a reason for hiding this comment

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

suggest: can compress these two if statements into one

if field in validated_data:
if not validated_data[field]:
return True
else:
Copy link
Member

Choose a reason for hiding this comment

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

can compress this into elif

Copy link
Member

@judtinzhang judtinzhang left a comment

Choose a reason for hiding this comment

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

Almost there! Need one more cycle of reviews because there is currently a test failing. Minor comment

newest_fields = [
(field, validated_data[field])
if field in validated_data
else (field, getattr(instance, field))
Copy link
Member

Choose a reason for hiding this comment

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

getattr has a default parameter, so we can do getattr(instance, field, None) to simplify a bit!

"expires_at",
]

newest_fields = [
Copy link
Member

Choose a reason for hiding this comment

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

Looks great, a lot simpler and readable! :D

@@ -148,6 +148,7 @@ def list(self, request, *args, **kwargs):
queryset = queryset.filter(subletter=request.user)
else:
queryset = queryset.filter(expires_at__gte=timezone.now())
queryset = queryset.filter(is_published=True)
Copy link
Member

Choose a reason for hiding this comment

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

Nice

else getattr(instance, field, None)
if instance
else None
),
Copy link
Contributor

Choose a reason for hiding this comment

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

technically i think u can also do validated_data.get(field) or getattr(instance, field, None)

Copy link
Member

Choose a reason for hiding this comment

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

image

Yep, confirmed! I think I like this better can we perhaps change it to that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants