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

Upgrade all dependencies #895

Merged
merged 5 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,12 @@ repos:
hooks:
- id: django-upgrade
args: [--target-version, "4.2"]
- repo: https://github.com/ambv/black
rev: "22.3.0"
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.5.2
hooks:
- id: black
# Since the pre-commit runs on a file by file basis rather than a whole project,
# The excludes in pyproject.toml are ignored
exclude: migrations
language_version: python3
- repo: https://github.com/asottile/reorder_python_imports
rev: v2.7.1
hooks:
- id: reorder-python-imports
language_version: python3
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
25 changes: 2 additions & 23 deletions adserver/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Django admin configuration for the ad server."""

from datetime import timedelta

import stripe
Expand Down Expand Up @@ -46,7 +47,6 @@


class RemoveDeleteMixin:

"""Removes the ability to delete this model from the admin."""

def get_actions(self, request):
Expand All @@ -55,14 +55,11 @@ def get_actions(self, request):
del actions["delete_selected"] # pragma: no cover
return actions

def has_delete_permission(
self, request, obj=None
): # pylint: disable=unused-argument
def has_delete_permission(self, request, obj=None): # pylint: disable=unused-argument
return False


class KeywordInline(admin.TabularInline):

"""For inlining the keywords on the topic admin."""

model = Keyword.topics.through
Expand Down Expand Up @@ -111,7 +108,6 @@ class CountryRegionAdmin(admin.ModelAdmin):


class CountryInline(admin.TabularInline):

"""For inlining the countries on the region admin."""

model = CountryRegion
Expand Down Expand Up @@ -147,7 +143,6 @@ class RegionAdmin(admin.ModelAdmin):

@admin.register(Publisher)
class PublisherAdmin(RemoveDeleteMixin, SimpleHistoryAdmin):

"""Django admin configuration for publishers."""

list_display = (
Expand Down Expand Up @@ -196,7 +191,6 @@ def report(self, instance):


class CampaignInline(admin.TabularInline):

"""For inlining the campaigns on the advertiser admin."""

model = Campaign
Expand All @@ -219,7 +213,6 @@ def has_add_permission(self, request, obj=None):

@admin.register(Advertiser)
class AdvertiserAdmin(RemoveDeleteMixin, SimpleHistoryAdmin):

"""Django admin configuration for advertisers."""

actions = ["action_create_draft_invoice"]
Expand Down Expand Up @@ -314,7 +307,6 @@ def stripe_customer(self, obj):

@admin.register(AdType)
class AdTypeAdmin(SimpleHistoryAdmin):

"""Django admin configuration for ad types."""

model = AdType
Expand All @@ -335,7 +327,6 @@ class AdTypeAdmin(SimpleHistoryAdmin):


class AdvertisementMixin:

"""Used by the AdvertisementInline and the AdvertisementAdmin."""

MAX_IMAGE_WIDTH = 120
Expand Down Expand Up @@ -367,7 +358,6 @@ def get_queryset(self, request):

@admin.register(Advertisement)
class AdvertisementAdmin(RemoveDeleteMixin, AdvertisementMixin, SimpleHistoryAdmin):

"""Django admin configuration for advertisements."""

form = AdvertisementAdminForm
Expand Down Expand Up @@ -430,7 +420,6 @@ def queryset(self, request, queryset):


class AdvertisementsInline(AdvertisementMixin, admin.TabularInline):

"""An inline for displaying non-editable list of advertisements."""

model = Advertisement
Expand Down Expand Up @@ -482,7 +471,6 @@ def has_add_permission(self, request, obj=None):


class InvoiceInline(admin.TabularInline):

"""List of Stripe invoices for a flight."""

model = Flight.invoices.through
Expand Down Expand Up @@ -513,7 +501,6 @@ def status(self, obj):


class FlightMixin:

"""Used by the FlightAdmin and FlightInline."""

def num_ads(self, obj):
Expand All @@ -537,7 +524,6 @@ def ecpm(self, obj):

@admin.register(Flight)
class FlightAdmin(RemoveDeleteMixin, FlightMixin, SimpleHistoryAdmin):

"""Django admin admin configuration for ad Flights."""

model = Flight
Expand Down Expand Up @@ -720,7 +706,6 @@ def get_queryset(self, request):


class FlightsInline(FlightMixin, admin.TabularInline):

"""An inline for displaying non-editable list of flights."""

model = Flight
Expand Down Expand Up @@ -750,7 +735,6 @@ def has_add_permission(self, request, obj=None):

@admin.register(Campaign)
class CampaignAdmin(RemoveDeleteMixin, SimpleHistoryAdmin):

"""Django admin configuration for ad campaigns."""

model = Campaign
Expand Down Expand Up @@ -798,7 +782,6 @@ def get_queryset(self, request):


class ImpressionsAdmin(RemoveDeleteMixin, admin.ModelAdmin):

"""Django admin configuration for the ad impressions."""

readonly_fields = (
Expand Down Expand Up @@ -905,7 +888,6 @@ class KeywordImpressionAdmin(ImpressionsAdmin):


class AdBaseAdmin(RemoveDeleteMixin, admin.ModelAdmin):

"""Django admin configuration for the base class of ad views and clicks."""

readonly_fields = (
Expand Down Expand Up @@ -964,7 +946,6 @@ def has_add_permission(self, request):

@admin.register(Offer)
class OfferAdmin(AdBaseAdmin):

"""Django admin configuration for ad offers."""

model = Offer
Expand Down Expand Up @@ -1024,15 +1005,13 @@ def refund_impressions(self, request, queryset):

@admin.register(Click)
class ClickAdmin(AdBaseAdmin):

"""Django admin configuration for ad clicks."""

model = Click


@admin.register(View)
class ViewAdmin(AdBaseAdmin):

"""Django admin configuration for ad views."""

model = View
Expand Down
3 changes: 1 addition & 2 deletions adserver/analyzer/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Django admin configuration for the ad server URL analyzer."""

from django.contrib import admin
from simple_history.admin import SimpleHistoryAdmin

Expand All @@ -8,7 +9,6 @@

@admin.register(AnalyzedUrl)
class AnalyzedUrlAdmin(SimpleHistoryAdmin):

"""Django admin configuration for analyzed URLs."""

list_display = (
Expand All @@ -29,7 +29,6 @@ class AnalyzedUrlAdmin(SimpleHistoryAdmin):

@admin.register(AnalyzedAdvertiserUrl)
class AnalyzedAdvertiserUrlAdmin(SimpleHistoryAdmin):

"""Django admin configuration for analyzed ads."""

list_display = (
Expand Down
2 changes: 1 addition & 1 deletion adserver/analyzer/apps.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""App config for ad server analyzer."""

from django.apps import AppConfig


class AdServerAnalyzerConfig(AppConfig):

"""Simple app config setup."""

name = "adserver.analyzer"
Expand Down
1 change: 1 addition & 0 deletions adserver/analyzer/backends/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Base class for all topic/keyword analyzers."""

import logging

import requests
Expand Down
2 changes: 1 addition & 1 deletion adserver/analyzer/backends/eatopics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Spacy-based topic classifier that uses our trained model and gives a likelihood that text is about our topics."""

import logging
import textwrap

Expand All @@ -11,7 +12,6 @@


class EthicalAdsTopicsBackend(TextacyAnalyzerBackend):

"""A model that uses our own custom dataset behind the scenes."""

# Name of the model package
Expand Down
2 changes: 1 addition & 1 deletion adserver/analyzer/backends/naive.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Naive keyword analyzer that is simply based on keyword counts."""

import collections

from bs4 import BeautifulSoup
Expand All @@ -8,7 +9,6 @@


class NaiveKeywordAnalyzerBackend(BaseAnalyzerBackend):

"""
A very naive keyword analyzer.

Expand Down
2 changes: 1 addition & 1 deletion adserver/analyzer/backends/textacynlp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Textacy/Spacy-based keyword analyzer that lemmatizes and uses textrank for keyphrase extraction."""

import collections
import logging

Expand All @@ -12,7 +13,6 @@


class TextacyAnalyzerBackend(NaiveKeywordAnalyzerBackend):

"""
An analyzer backend that uses textacy for lemmatization and keyword extraction.

Expand Down
1 change: 1 addition & 0 deletions adserver/analyzer/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Contants used for the ad server keyword/topic analyzer."""

# Query parameters on URLs to ignore
IGNORED_QUERY_PARAMS = (
"q",
Expand Down
2 changes: 1 addition & 1 deletion adserver/analyzer/management/commands/runmodel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Run the ML model on the specified URLs."""

from django.conf import settings
from django.core.management.base import BaseCommand
from django.core.validators import URLValidator
Expand Down Expand Up @@ -37,7 +38,6 @@ def handle_url(self, url):

keywords = []
for backend in get_url_analyzer_backends():

backend_instance = backend(url)
response = backend_instance.fetch()
if not response:
Expand Down
2 changes: 1 addition & 1 deletion adserver/analyzer/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Stored results of offline content targeting analysis."""

from django.db import models
from django.utils.translation import gettext_lazy as _
from django_extensions.db.models import TimeStampedModel
Expand All @@ -10,7 +11,6 @@


class BaseAnalyzedUrl(TimeStampedModel):

url = models.URLField(
db_index=True,
max_length=1024,
Expand Down
4 changes: 3 additions & 1 deletion adserver/analyzer/tasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tasks for analyzing URLs for topics and keywords."""

import datetime
import logging

Expand All @@ -8,14 +9,15 @@
from django.db import models
from django.utils import timezone

from config.celery_app import app

from ..constants import PAID
from ..models import Offer
from ..models import Publisher
from ..utils import get_day
from .models import AnalyzedUrl
from .utils import get_url_analyzer_backends
from .utils import normalize_url
from config.celery_app import app


log = logging.getLogger(__name__) # noqa
Expand Down
1 change: 1 addition & 0 deletions adserver/analyzer/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Helper utilities for the adserver analyzer."""

import re
from urllib import parse as urlparse

Expand Down
2 changes: 1 addition & 1 deletion adserver/analyzer/validators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Custom validators for the ad server analyzer."""

from django.core.exceptions import ValidationError
from django.core.validators import BaseValidator
from django.utils.deconstruct import deconstructible
Expand All @@ -7,7 +8,6 @@

@deconstructible
class KeywordsValidator(BaseValidator):

"""A Django model and form validator for keyword analysis."""

message = _("Enter a valid value")
Expand Down
2 changes: 1 addition & 1 deletion adserver/api/mixins.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Mixins for API views and viewsets."""

from django.conf import settings

from ..utils import generate_client_id
Expand All @@ -8,7 +9,6 @@


class GeoIpMixin:

"""
A mixin that attaches updated IP, User Agent, and Geolocation data to the request.

Expand Down
3 changes: 1 addition & 2 deletions adserver/api/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

https://www.django-rest-framework.org/api-guide/permissions/#custom-permissions
"""

from rest_framework import permissions

from ..models import Advertiser
from ..models import Publisher


class AdvertiserPermission(permissions.IsAuthenticated):

"""
Checks whether the authenticated user is associated with the given advertiser.

Expand All @@ -30,7 +30,6 @@ def has_object_permission(self, request, view, obj):


class PublisherPermission(permissions.IsAuthenticated):

"""
Checks whether the authenticated user is associated with the given publisher.

Expand Down
Loading
Loading