Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
itsthejoker committed Dec 3, 2021
1 parent edc6be3 commit 08c4a64
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
line_length = 88
multi_line_output = 3
include_trailing_comma = True
known_third_party = beeline,better_exceptions,blossom_wrapper,bugsnag,dateparser,django,django_filters,dotenv,dpath,drf_yasg,mimesis,praw,prawcore,psaw,pytest,pytest_django,pytz,requests,rest_framework,rest_framework_api_key,slack,social_core,stripe,toml
known_third_party = beeline,better_exceptions,blossom_wrapper,bugsnag,dateparser,django,django_filters,dotenv,dpath,drf_yasg,helpers,mimesis,praw,prawcore,psaw,pytest,pytest_django,pytz,requests,rest_framework,rest_framework_api_key,slack,social_core,social_django,stripe,toml
skip=venv,.venv,env,migrations
5 changes: 4 additions & 1 deletion app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@

from app import views

urlpatterns = [path("practice/", views.PracticeTranscription.as_view())]
urlpatterns = [
path("practice/", views.PracticeTranscription.as_view()),
path("", views.index_test),
]
24 changes: 24 additions & 0 deletions app/views.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
import random

from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.http import HttpRequest, HttpResponse, HttpResponseServerError
from django.shortcuts import get_object_or_404, render
from django.views.generic import View
from praw import Reddit
from social_django.utils import load_strategy

from api.models import Transcription
from utils.mixins import CSRFExemptMixin
from website.helpers import get_additional_context


@login_required
def index_test(request: HttpRequest) -> HttpResponse:
"""Test stuff."""
strategy = load_strategy(request)
social = request.user.social_auth.filter(provider="reddit")[0]
social.refresh_token(
strategy=strategy, redirect_uri="http://localhost:8000/complete/reddit/"
)
asdf = Reddit(
client_id=settings.SOCIAL_AUTH_REDDIT_KEY,
client_secret=settings.SOCIAL_AUTH_REDDIT_SECRET,
refresh_token=request.user.social_auth.first().extra_data["refresh_token"],
user_agent="blossomtest - contact u/itsthejoker with questions",
)

# asdf.auth.authorize(request.user.social_auth.first().access_token)

return render(request, "app/index_test.html", {"reddit": asdf})


class PracticeTranscription(CSRFExemptMixin, View):
"""
A page to practice writing transcriptions.
Expand Down
21 changes: 19 additions & 2 deletions blossom/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import dotenv
from django.urls import reverse_lazy

from blossom import __version__
from blossom import __version__ # noqa

dotenv.load_dotenv()
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -106,6 +106,8 @@
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"social_django.context_processors.backends",
"social_django.context_processors.login_redirect",
],
},
},
Expand Down Expand Up @@ -172,7 +174,7 @@

AUTHENTICATION_BACKENDS = [
"authentication.backends.EmailBackend",
"blossom.social_auth.reddit.RedditOAuth2",
"social_core.backends.reddit.RedditOAuth2",
"django.contrib.auth.backends.ModelBackend",
]

Expand Down Expand Up @@ -235,6 +237,21 @@
"puu.sh",
"i.redditmedia.com",
]
SOCIAL_AUTH_REDDIT_KEY = os.environ.get("SOCIAL_AUTH_REDDIT_KEY")
SOCIAL_AUTH_REDDIT_SECRET = os.environ.get("SOCIAL_AUTH_REDDIT_SECRET")
SOCIAL_AUTH_REDDIT_AUTH_EXTRA_ARGUMENTS = {"duration": "permanent"}
SOCIAL_AUTH_REDDIT_SCOPE = ["submit"]
SOCIAL_AUTH_JSONFIELD_ENABLED = True
SOCIAL_AUTH_PIPELINE = (
"social_core.pipeline.social_auth.social_details",
"social_core.pipeline.social_auth.social_uid",
"social_core.pipeline.social_auth.auth_allowed",
"utils.pipeline.load_user",
"social_core.pipeline.social_auth.social_user",
"social_core.pipeline.social_auth.associate_user",
"social_core.pipeline.social_auth.load_extra_data",
"social_core.pipeline.user.user_details",
)

DEFAULT_AUTO_FIELD = "django.db.models.AutoField"

Expand Down
Empty file removed blossom/social_auth/__init__.py
Empty file.
42 changes: 0 additions & 42 deletions blossom/social_auth/reddit.py

This file was deleted.

4 changes: 0 additions & 4 deletions blossom/social_auth/urls.py

This file was deleted.

7 changes: 7 additions & 0 deletions blossom/templates/app/index_test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends "website/partials/base.partial" %}

{% block content %}
YOU ARE LOGGED IN AS: {{ request.user }}
<p></p>
YOUR REDDIT USERNAME ACCORDING TO PRAW IS: {{ reddit.user.me }}
{% endblock %}
3 changes: 3 additions & 0 deletions blossom/templates/website/generic_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ <h4>{{ subheader }}</h4>
</div>
{% endif %}
</div>
{% if 'login' in request.path %}
<a href="{% url "social:begin" "reddit" %}?next={{ request.path }}">Login with Reddit</a>
{% endif %}

<script>
document.addEventListener("DOMContentLoaded", function () {
Expand Down
1 change: 1 addition & 0 deletions blossom/templates/website/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{% load fun_footers %}

{% block content %}
YOU ARE: {{ request.user }}
{% if not posts %}
<p>
<h1 class="text-center">There's nothing here! Why not <a href="{% url "post_create" %}"
Expand Down
2 changes: 2 additions & 0 deletions blossom/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.conf import settings
from django.conf.urls import url
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import include, path
Expand All @@ -20,6 +21,7 @@
path("payments/", include("payments.urls")),
path("engineering/", include("engineeringblog.urls")),
path("", include("website.urls")),
url("", include("social_django.urls", namespace="social")),
]

if settings.DEBUG:
Expand Down
14 changes: 14 additions & 0 deletions bootstrap/stuff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from helpers import *

r = redis()

users = get_user_list_from_redis(r)
user_data = pull_user_data_from_redis(users, r)

data = {}

for piece in user_data:
data[piece.get_username()] = piece.to_dict()

with open("redis_data.json", "w") as outfile:
json.dump(data, outfile, indent=2)
Loading

0 comments on commit 08c4a64

Please sign in to comment.