Skip to content

Commit

Permalink
Merge PR #211 from WayneLambert/develop
Browse files Browse the repository at this point in the history
Remove Oxford Dictionaries API Functionality
  • Loading branch information
WayneLambert authored Mar 5, 2024
2 parents eab58fc + 6fb5667 commit be64066
Show file tree
Hide file tree
Showing 28 changed files with 37 additions and 2,626 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

services:
postgres:
image: postgres:13.4
image: postgres:14.6
env:
POSTGRES_DB: github_actions
POSTGRES_USER: postgres
Expand All @@ -35,10 +35,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v1

- name: Set up Python 3.10.8
- name: Set up Python 3.12.0
uses: actions/setup-python@v1
with:
python-version: 3.10.8
python-version: 3.12.0

- name: Install Poetry
uses: snok/install-poetry@v1
Expand Down Expand Up @@ -78,9 +78,6 @@ jobs:
EMAIL_HOST_SES: ${{ secrets.EMAIL_HOST_SES }}
EMAIL_HOST_USER_SES: ${{ secrets.EMAIL_HOST_USER_SES }}
FIELD_ENCRYPTION_KEY: ${{ secrets.FIELD_ENCRYPTION_KEY }}
OD_API_BASE_URL: ${{ secrets.OD_API_BASE_URL }}
OD_APPLICATION_ID: ${{ secrets.OD_APPLICATION_ID }}
OD_APPLICATION_KEY_1: ${{ secrets.OD_APPLICATION_KEY_1 }}
PYTEST_TEST_PASSWORD: ${{ secrets.PYTEST_TEST_PASSWORD }}
RECAPTCHA_PRIVATE_KEY: ${{ secrets.RECAPTCHA_PRIVATE_KEY }}
RECAPTCHA_PUBLIC_KEY: ${{ secrets.RECAPTCHA_PUBLIC_KEY }}
Expand Down
1 change: 1 addition & 0 deletions aa_project/settings/pytest/pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
},
}


# Eliminates warning about missing staticfiles directory
WHITENOISE_AUTOREFRESH = True

Expand Down
5 changes: 2 additions & 3 deletions apps/api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.contrib.auth import get_user_model

from django.contrib.auth.models import User
from rest_framework import serializers

from apps.blog.models import Category, Post
Expand All @@ -10,7 +9,7 @@ class UserSerializer(serializers.ModelSerializer):
username = serializers.CharField(required=False, allow_blank=True, read_only=True)

class Meta:
model = get_user_model()
model = User
fields = (
"username",
"first_name",
Expand Down
5 changes: 2 additions & 3 deletions apps/blog/models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import math

from django.contrib.auth import get_user_model
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist
from django.core.validators import MinLengthValidator
from django.db import models
from django.template.defaultfilters import slugify
from django.urls import reverse

from tinymce.models import HTMLField

from apps.blog.managers import PublishedManager
Expand Down Expand Up @@ -49,7 +48,7 @@ class Post(models.Model):
help_text="For bests results, use an image that is 1,200px wide x 600px high",
)
status = models.IntegerField(db_index=True, choices=STATUS, default=0)
author = models.ForeignKey(get_user_model(), related_name="author", on_delete=models.CASCADE)
author = models.ForeignKey(User, related_name="author", on_delete=models.CASCADE)
categories = models.ManyToManyField(
Category,
related_name="posts",
Expand Down
9 changes: 1 addition & 8 deletions apps/blog/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
import datetime

from django.contrib.auth import get_user_model
import pytest
from django.db import models
from django.shortcuts import reverse
from django.utils.text import slugify

import pytest

from mixer.backend.django import mixer
from tinymce.models import HTMLField

from apps.blog.models import Category, Post


pytestmark = pytest.mark.django_db(reset_sequences=True)


user_model = get_user_model()


class TestCategory:
def test_name_is_charfield(self):
category = mixer.blend(Category, pk=1)
Expand Down
4 changes: 2 additions & 2 deletions apps/blog/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from time import perf_counter

from django.contrib import messages
from django.contrib.auth import get_user_model
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.contrib.auth.models import User
from django.contrib.postgres.search import SearchQuery, SearchRank, SearchVector
from django.shortcuts import get_list_or_404, get_object_or_404
from django.urls import reverse, reverse_lazy
Expand Down Expand Up @@ -93,7 +93,7 @@ class AuthorPostListView(PostView):
paginate_orphans = 3

def get_queryset(self):
user = get_object_or_404(get_user_model(), username=self.kwargs["username"])
user = get_object_or_404(User, username=self.kwargs["username"])
return super().get_queryset().filter(author=user)

def get_context_data(self, **kwargs):
Expand Down
43 changes: 2 additions & 41 deletions apps/countdown_letters/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@
"""

import os

from collections import Counter
from random import choices, random
from typing import Dict, List, Set

import requests

from aa_project.settings.base import APPS_DIR
from apps.countdown_letters import validations
from apps.countdown_letters.oxford_api import API


class GameSetup:
Expand Down Expand Up @@ -141,9 +136,8 @@ def get_longest_possible_word(shortlisted_words: List) -> str:
indexed position
"""
for item in shortlisted_words:
if validations.is_in_oxford_api(item[0]):
longest_possible_word = item[0]
return longest_possible_word.upper()
longest_possible_word = item[0]
return longest_possible_word.upper()
return None


Expand All @@ -152,39 +146,6 @@ def get_game_score(word_len: int) -> int:
return word_len * 2 if word_len == 9 else word_len


def get_lemmas_response_json(word: str) -> Dict:
"""
Returns lemmas data component of given `word` from Oxford Online API
The `lemmas` endpoint is used to determine presence in the dictionary.
"""
lemmas_url = f"{API.LEMMAS_URL}{word.lower()}"
lemmas_response = requests.get(lemmas_url, headers=API.headers)
return lemmas_response.json()


def lookup_definition_data(word: str) -> Dict:
"""
Retrieve dictionary definition of winning word using 'Oxford
Dictionaries API'.
"""
response = requests.get(url=API.WORDS_URL, params={"q": word}, headers=API.headers)
if response.status_code == 200:
try:
json = response.json()
idx = 0 if json["results"][0]["type"] == "headword" else 1
d = json["results"][idx]["lexicalEntries"][0]["entries"][0]["senses"][0]
definition = d["definitions"][0].capitalize()
word_class = json["results"][0]["lexicalEntries"][idx]["lexicalCategory"]["text"]
except KeyError:
definition = f"The definition for '{word}' cannot be found in the Oxford Dictionaries API."
word_class = "N/A"

return {
"definition": definition,
"word_class": word_class,
}


def get_result(player_word: str, comp_word: str) -> str:
"""Returns the winning player for the game"""
if len(player_word) > len(comp_word):
Expand Down
24 changes: 0 additions & 24 deletions apps/countdown_letters/oxford_api.py

This file was deleted.

21 changes: 0 additions & 21 deletions apps/countdown_letters/templates/countdown_letters/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,6 @@ <h6 class="font-weight-bold mb-0 lead mb-4">Player Answers</h6>
</blockquote>
</div>

<!--- Word Definition -->
<div class="client-quote d-flex flex-column results-card mb-1 mt-3">
<blockquote class="quote-content text-left">
<h6 class="font-weight-bold mb-0 lead mb-4">Word Definition</h6>
<table>
<tr>
<h6 class="text-uppercase">
<strong>{{ winning_word|lower|capfirst }}</strong>
</h6>
</tr>
<tr>
<div class="inner theme-bg-light">
<p class="text-small text-muted">{{ definition_data.word_class }}</p>
<p class="word-definition">{{ definition_data.definition }}</p>
<em class="small">(British - English)</em>
</div>
</tr>
</table>
</blockquote>
</div>

<!--- Scores Message -->
<div class="client-quote d-flex flex-column results-card mt-3">
<blockquote class="quote-content text-left">
Expand Down

This file was deleted.

Loading

0 comments on commit be64066

Please sign in to comment.