Skip to content

Commit

Permalink
feat: added api for Experience pages (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matavatar authored Oct 6, 2022
2 parents 52e3c88 + 232cbad commit 4cecb48
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 47 deletions.
1 change: 1 addition & 0 deletions bfportal/bfportal/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"wagtail.admin",
"wagtail.core",
"wagtail.contrib.routable_page",
"wagtail.api.v2",
"wagtail_color_panel",
"modelcluster",
"taggit",
Expand Down
2 changes: 2 additions & 0 deletions bfportal/bfportal/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from ajax_select import urls as ajax_select_urls
from core.api import api_router
from core.views import CategoriesAutocomplete, TagsAutocomplete, handle_like_request
from django.conf import settings
from django.contrib import admin
Expand Down Expand Up @@ -42,6 +43,7 @@
handle_like_request,
name="add_like_to_experience_page",
),
path("api/", api_router.urls),
re_path(r"^ajax_select/", include(ajax_select_urls)),
path("markdownx/", include("markdownx.urls")),
]
Expand Down
30 changes: 30 additions & 0 deletions bfportal/core/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from rest_framework.renderers import JSONRenderer
from wagtail.api.v2.router import WagtailAPIRouter
from wagtail.api.v2.views import BaseAPIViewSet, PagesAPIViewSet

from .models import ExperiencePage


class ExperiencePageAPIViewSet(BaseAPIViewSet):
"""Class that defines how page api works."""

renderer_classes = [JSONRenderer]
model = ExperiencePage
filter_backends = PagesAPIViewSet.filter_backends
body_fields = [
"url",
"id",
"full_url",
"title",
"description",
"cover_img_url",
"code",
"exp_url",
"featured",
"bugged",
]
listing_default_fields = body_fields


api_router = WagtailAPIRouter("wagtailapi")
api_router.register_endpoint("experiences", ExperiencePageAPIViewSet)
15 changes: 7 additions & 8 deletions bfportal/core/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ class ExperiencePageAdmin(ModelAdmin):

def get_owner(self, page: ExperiencePage):
"""Returns html formatted string containing avatar and username."""
if social_account := page.owner.socialaccount_set.first():
extra_data = social_account.extra_data
if extra_data["avatar"]:
src = f"https://cdn.discordapp.com/avatars/{extra_data['id']}/{extra_data['avatar']}.png"
else:
src = ""
else:
src = ""
src = ""
if socialaccount_set := page.owner.socialaccount_set:
if social_account := socialaccount_set.first():
extra_data = social_account.extra_data
if extra_data["avatar"]:
src = f"https://cdn.discordapp.com/avatars/{extra_data['id']}/{extra_data['avatar']}.png"

return format_html(
"""
<div style="display:flex;align-items:center;column-gap:5px" >
Expand Down
47 changes: 8 additions & 39 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,18 @@ With the release of battlefield 2042, ripple effect studio, added the ability to
This project will replace the current website at https://bfportal.gg/

# Info
project is now in beta testing
head over to http://vmi656705.contaboserver.net:8000/, and try it out

### Screenshots of several parts of the website
<details>

<summary>
Click to show
</summary>


## Home Page
![image](https://user-images.githubusercontent.com/22869882/162639043-ec231408-b2e2-4f7a-b89e-38e48fec75e3.png)
## Profile Page
![image](https://user-images.githubusercontent.com/22869882/162639063-19c9bd0b-888b-4116-ab25-cfc3d67692ec.png)
## Experience Info Page
![image](https://user-images.githubusercontent.com/22869882/162639079-105111d8-0557-4ce2-a697-6cb3b8091b16.png)
## Experience Submission and edit page
![image](https://user-images.githubusercontent.com/22869882/162639108-f3fef6b3-1c44-4283-a504-8ab959815bd8.png)
## Discord Login process
![image](https://user-images.githubusercontent.com/22869882/162639135-30265c6e-690a-47b2-b9c5-842f98061051.png)
![image](https://user-images.githubusercontent.com/22869882/162639149-6ca41096-9892-4c5c-ab3f-0d1c7dd9b1d0.png)

</details>
Head over to [bfportal.gg](https://bfportal.gg/), and try it out

## Features
- User system (Discord login for intregation with bfportal community discord server)
- User system (Discord login for integration with portal community discord server)
- Auto Fill API for forms
- Pagination and website wide search

## How it works
It is pretty straight forward

- You use your discord account to make a new account on the website and submit your experiences.
- On the submission page if u choose to share the playgound Url of the experience, the submission form will auto fill 😃.
- On the submission page if u choose to share the playground Url of the experience, the submission form will autofill 😃.

You can later edit your experience if u like.

Expand All @@ -57,16 +34,8 @@ You can later edit your experience if u like.

- create and activate a venv
- install dependencies `python -m pip install -r requirements.txt`
- create a .env file with the following values
- ```
DB_NAME=<postgres_db_name>
DB_USERNAME=<postgres_username>
DB_PASSWORD=<postgres_password>
POSTGRES_HOST=127.0.0.1
SU_PASSWD=1234
DISCORD_CLIENT_ID=931965340764737608
DISCORD_SECRET=SuzQK6oAV_ArY3HGXUYIOUjFT46C5OtW
```
- copy the [.env.template](bfportal/.env.template) file and rename it to .env
- fill the appropriate data in .env file
- Do first run migrate
- run `python manage.py ensure_superuser --username bfportal --email [email protected] --password <password>`
- run `python manage.py ensure_initialization`
Expand All @@ -79,7 +48,7 @@ You can later edit your experience if u like.


### Special Thanks to
- [gametools.network](https://gametools.network/) for providing API to auto fill submisson form 🥰
- [Wagtail](https://github.com/wagtail/wagtail) for providing a awesome framework that makes managing submissions very easy ✅
- [gametools.network](https://gametools.network/) for providing API to autofill submisson form 🥰
- [Wagtail](https://github.com/wagtail/wagtail) for providing an awesome framework that makes managing submissions very easy ✅
- [tailwindcss](https://github.com/tailwindlabs/tailwindcss) for saving the lives of backend developers. 🙏
- [Matavatar](https://discord.com/users/236802771381125120) from BFportal discord community for providing valuable feedback 🤝
- [Matavatar](https://discord.com/users/236802771381125120) from BFportal discord community for designing UI of the website 🤝

0 comments on commit 4cecb48

Please sign in to comment.