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

Allow registered users to edit their reviews #67

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

Conversation

nsandler1
Copy link
Member

@nsandler1 nsandler1 commented Dec 25, 2022

Registered users will be able to edit all aspects of a review except the professor's name and the course, if there is one. If there is no course, one can be added.

If the content of the review (the text) is edited, then the review will be marked as pending for admins to approve. This applies to reviews with any status (verified, pending, rejected). Any other edit will be reflected immediately without the need for admins to approve.

home/views/add_professor.py Outdated Show resolved Hide resolved
Comment on lines +281 to +289
review = {
"professor": escape(Professor.unfiltered.get(pk=model_obj.professor_id).name),
"rating": model_obj.rating,
"anonymous": model_obj.anonymous,
"course": None if not model_obj.course_id else {"id": model_obj.course_id, "name": Course.unfiltered.get(pk=model_obj.course_id).name},
"grade": None if not model_obj.grade else model_obj.grade,
"id": model_obj.pk,
"content": escape(model_obj.content)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't looked into this deeply, but this is sketch. I would expect model_obj to already be a Review here - why go through all this trouble instead of dumping model_obj?

Django's serializers should have a built-in way to follow and dump foreign keys as well.

Copy link
Member Author

@nsandler1 nsandler1 Jun 2, 2023

Choose a reason for hiding this comment

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

model_obj is an instance of a Review but without any of the related fields. All such fields are just the pk to the column in the corresponding table, which is not what we want here.

By default, django serializers don't actually forward foreign keys and m2m relationships; the pk is used instead and we are required to add natural keys to our model managers to change this behavior. If you think this is worth the effort and is better than the current approach then I'll go ahead and do it.

@tybug
Copy link
Contributor

tybug commented May 29, 2023

Errors when trying to view another user's profile as admin due to not passing an edit_form here:

"form": ProfileForm(instance=user, allow_edits=False)

We'll likely need to pull the same allow_edits=False trick as we did for ProfileForm. Or refactor how admin profile viewing works, which is a bit hacky.

home/templates/profile.html Show resolved Hide resolved
@nsandler1
Copy link
Member Author

Something weird is suddenly going on with the tabs on the profile page and the settings now appear at the bottom of the reviews tab when clicked. I compared the changes made to profile.html in this PR to the version on master and I can't see any changes that would cause this behavior. Other than that, this PR is ready for review!

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.

2 participants