Repository: CiviWiki/OpenCiviWiki

Issue:
[BUG] Fix Bugs when profile is being viewed
### 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](https://github.com/CiviWiki/OpenCiviWiki/blob/develop/project/threads/views.py#L181-L245)

```py
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](https://user-images.githubusercontent.com/67182544/138872174-8fadf9a9-bf2e-40fb-a9b8-7c630ba8a676.png)


Discussion:
@brylie and @gorkemarslan I'd like to take this issue
@AbhijithGanesh please remember to complete your [currently assigned tasks](https://github.com/CiviWiki/OpenCiviWiki/issues/assigned/AbhijithGanesh) before starting a new task.
Yeah but #1151 is dependent on this issue's patch, otherwise I would not be able to load the templates
@AbhijithGanesh, the error is caused by this line:

https://github.com/CiviWiki/OpenCiviWiki/blob/ab96113090654bc78c3674a47e46c2f9aa08d2b3/project/accounts/views.py#L180

We should change `user.profile_set` with `user.profile` because relation between User and Profile models defines as:
https://github.com/CiviWiki/OpenCiviWiki/blob/ab96113090654bc78c3674a47e46c2f9aa08d2b3/project/accounts/models.py#L94-L95

In the end, we should have:
```python
            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.
@AbhijithGanesh, could you look at my previous answer? I guess you missed it. :smile: 
@gorkemarslan I will

Resolving patch:
diff --git a/project/accounts/views.py b/project/accounts/views.py
--- a/project/accounts/views.py
+++ b/project/accounts/views.py
@@ -177,7 +177,6 @@ def user_profile(request, username=None):
             is_owner = username == request.user.username
             try:
                 user = User.objects.get(username=username)
-                profile = user.profile_set.first()
             except User.DoesNotExist:
                 return HttpResponseRedirect("/404")
 
@@ -185,9 +184,9 @@ def user_profile(request, username=None):
             initial={
                 "username": user.username,
                 "email": user.email,
-                "first_name": profile.first_name or None,
-                "last_name": profile.last_name or None,
-                "about_me": profile.about_me or None,
+                "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,
         )


Test patch: