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

[BUG] Fix Bugs when profile is being viewed #1171

Closed
AbhijithGanesh opened this issue Oct 26, 2021 · 7 comments · Fixed by #1186
Closed

[BUG] Fix Bugs when profile is being viewed #1171

AbhijithGanesh opened this issue Oct 26, 2021 · 7 comments · Fixed by #1186

Comments

@AbhijithGanesh
Copy link
Collaborator

Description

The serialization is not correct when the registered user tries to view their own profile

This comes from the serialization part of our code-base which can be viewed here

thread_wiki_data = {
        "thread_id": thread_id,
        "title": Thread_filter.title,
        "summary": Thread_filter.summary,
        "image": Thread_filter.image_url,
        "author": {
            "username": Thread_filter.author.user.username,
            "profile_image": Thread_filter.author.profile_image_url,
            "first_name": Thread_filter.author.first_name,
            "last_name": Thread_filter.author.last_name,
        },
        "contributors": [
            Profile.objects.chip_summarize(a)
            for a in Profile.objects.filter(
                pk__in=civis.distinct("author").values_list("author", flat=True)
            )
        ],
        "category": {
            "id": Thread_filter.category.id,
            "name": Thread_filter.category.name,
        },
        "categories": [{"id": c.id, "name": c.name} for c in Category.objects.all()],
        "created": Thread_filter.created_date_str,
        "num_civis": Thread_filter.num_civis,
        "num_views": Thread_filter.num_views,
        "user_votes": [
            {
                "civi_id": act.civi.id,
                "activity_type": act.activity_type,
                "c_type": act.civi.c_type,
            }
            for act in Activity.objects.filter(
                thread=Thread_filter.id, account=req_acct.id
            )
        ],
    }

What should have happened?

The serialization should return user appropriately

What browser(s) are you seeing the problem on?

Chrome, Firefox, Microsoft Edge, Safari

Further details

image

@AbhijithGanesh AbhijithGanesh added the triage Issues that have not been categorized or prioritized label Oct 26, 2021
@AbhijithGanesh
Copy link
Collaborator Author

@brylie and @gorkemarslan I'd like to take this issue

@brylie
Copy link
Member

brylie commented Oct 26, 2021

@AbhijithGanesh please remember to complete your currently assigned tasks before starting a new task.

@AbhijithGanesh
Copy link
Collaborator Author

Yeah but #1151 is dependent on this issue's patch, otherwise I would not be able to load the templates

@brylie brylie added code quality hacktoberfest-accepted help wanted bug and removed triage Issues that have not been categorized or prioritized labels Oct 26, 2021
@gorkemarslan
Copy link
Collaborator

@AbhijithGanesh, the error is caused by this line:

profile = user.profile_set.first()

We should change user.profile_set with user.profile because relation between User and Profile models defines as:

class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name="profile")

In the end, we should have:

            try:
                user = User.objects.get(username=username)
            except User.DoesNotExist:
                return HttpResponseRedirect("/404")

        form = ProfileEditForm(
            initial={
                "username": user.username,
                "email": user.email,
                "first_name": user.profile.first_name or None,
                "last_name": user.profile.last_name or None,
                "about_me": user.profile.about_me or None,
            },
            readonly=True,
        )

If you, you can close PR #1172 and commit these changes in PR #1180. Or I can commit them.

@gorkemarslan
Copy link
Collaborator

@AbhijithGanesh, could you look at my previous answer? I guess you missed it. 😄

@AbhijithGanesh
Copy link
Collaborator Author

@gorkemarslan I will

@gorkemarslan
Copy link
Collaborator

@AbhijithGanesh, I just committed the changes that I suggested. Since the issue affects the backend and the solution is simple, I decided to make changes as soon as possible.

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

Successfully merging a pull request may close this issue.

3 participants