Skip to content

Commit

Permalink
Remove more old django references
Browse files Browse the repository at this point in the history
  • Loading branch information
davegaeddert committed Aug 22, 2024
1 parent 8247991 commit b3a759c
Show file tree
Hide file tree
Showing 17 changed files with 25 additions and 1,478 deletions.
452 changes: 2 additions & 450 deletions plain-code/poetry.lock

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions plain-code/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,12 @@ authors = ["Dave Gaeddert <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.11"

plain = "<1.0.0"

ruff = "^0.1.0"

[tool.poetry.group.dev.dependencies]
plain = { path = "../plain", develop = true }

pytest = "^7.1.2"
ipdb = "^0.13.9"
isort = "^5.10.1"
black = "^23.1.0"
pytest-django = "^4.5.2"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
452 changes: 2 additions & 450 deletions plain-elements/poetry.lock

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions plain-elements/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ plain = "<1.0.0"

[tool.poetry.group.dev.dependencies]
plain = { path = "../plain", develop = true }
pytest = "^7.1.2"
ipdb = "^0.13.9"
isort = "^5.10.1"
black = "^23.1.0"
pytest-django = "^4.5.2"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
2 changes: 1 addition & 1 deletion plain-importmap/plain/importmap/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(
self.map_dev = {}

def load(self):
# TODO django check to compare lock and config hash
# TODO preflight check to compare lock and config hash

self.config = self.load_config()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,7 @@ def get_constraints(self, cursor, table_name):
) in cursor.fetchall():
if index not in constraints:
basic_index = (
type_ == self.index_default_access_method
and
# '_btree' references
# django.contrib.postgres.indexes.BTreeIndex.suffix.
not index.endswith("_btree")
and options is None
type_ == self.index_default_access_method and options is None
)
constraints[index] = {
"columns": columns if columns != [None] else [],
Expand Down
9 changes: 3 additions & 6 deletions plain-models/plain/models/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from plain.models.migrations.utils import get_migration_name_timestamp
from plain.models.migrations.writer import MigrationWriter
from plain.packages import packages
from plain.runtime import __version__, settings
from plain.runtime import settings
from plain.utils.module_loading import module_has_submodule
from plain.utils.text import Truncator

Expand Down Expand Up @@ -988,9 +988,7 @@ def optimize_migration(package_label, migration_name, check, verbosity):
if migration.replaces:
raise click.ClickException(
"Migration will require manual porting but is already a squashed "
"migration.\nTransition to a normal migration first: "
f"https://docs.djangoproject.com/en/{__version__}/topics/migrations/"
"#squashing-migrations"
"migration.\nTransition to a normal migration first."
)
# Make a new migration with those operations.
subclass = type(
Expand Down Expand Up @@ -1270,8 +1268,7 @@ def find_migration(loader, package_label, name):
if smigration.replaces:
raise click.ClickException(
"You cannot squash squashed migrations! Please transition it to a "
f"normal migration first: https://docs.djangoproject.com/en/{__version__}/"
"topics/migrations/#squashing-migrations"
"normal migration first"
)
operations.extend(smigration.operations)
for dependency in smigration.dependencies:
Expand Down
1 change: 0 additions & 1 deletion plain-models/plain/models/database_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
urlparse.uses_netloc.append(key)


# From https://docs.djangoproject.com/en/4.0/ref/settings/#databases
class DBConfig(TypedDict, total=False):
AUTOCOMMIT: bool
CONN_MAX_AGE: int | None
Expand Down
12 changes: 6 additions & 6 deletions plain-models/plain/models/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from plain.utils.module_loading import import_string

DEFAULT_DB_ALIAS = "default"
PLAIN_VERSION_PICKLE_KEY = "_django_version"
PLAIN_VERSION_PICKLE_KEY = "_plain_version"


class Error(Exception):
Expand Down Expand Up @@ -68,7 +68,7 @@ def __enter__(self):
def __exit__(self, exc_type, exc_value, traceback):
if exc_type is None:
return
for dj_exc_type in (
for plain_exc_type in (
DataError,
OperationalError,
IntegrityError,
Expand All @@ -79,14 +79,14 @@ def __exit__(self, exc_type, exc_value, traceback):
InterfaceError,
Error,
):
db_exc_type = getattr(self.wrapper.Database, dj_exc_type.__name__)
db_exc_type = getattr(self.wrapper.Database, plain_exc_type.__name__)
if issubclass(exc_type, db_exc_type):
dj_exc_value = dj_exc_type(*exc_value.args)
plain_exc_value = plain_exc_type(*exc_value.args)
# Only set the 'errors_occurred' flag for errors that may make
# the connection unusable.
if dj_exc_type not in (DataError, IntegrityError):
if plain_exc_type not in (DataError, IntegrityError):
self.wrapper.errors_occurred = True
raise dj_exc_value.with_traceback(traceback) from exc_value
raise plain_exc_value.with_traceback(traceback) from exc_value

def __call__(self, func):
# Note that we are intentionally not using @wraps here for performance
Expand Down
9 changes: 2 additions & 7 deletions plain-models/plain/models/migrations/questioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from plain.models.fields import NOT_PROVIDED
from plain.packages import packages
from plain.runtime import __version__
from plain.utils import timezone

from .loader import MigrationLoader
Expand Down Expand Up @@ -276,17 +275,13 @@ def ask_auto_now_add_addition(self, field_name, model_name):
def ask_unique_callable_default_addition(self, field_name, model_name):
"""Adding a unique field with a callable default."""
if not self.dry_run:
version = __version__
choice = self._choice_input(
f"Callable default on unique field {model_name}.{field_name} "
f"will not generate unique values upon migrating.\n"
f"Please choose how to proceed:\n",
[
f"Continue making this migration as the first step in "
f"writing a manual migration to generate unique values "
f"described here: "
f"https://docs.djangoproject.com/en/{version}/howto/"
f"writing-migrations/#migrations-that-add-unique-fields.",
"Continue making this migration as the first step in "
"writing a manual migration to generate unique values.",
"Quit and edit field options in models.py.",
],
)
Expand Down
34 changes: 3 additions & 31 deletions plain-oauth/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<!-- This file is compiled from plain-oauth/plain/oauth/README.md. Do not edit this file directly. -->

<!-- This file is compiled from plain-oauth/plain/oauth/README.md. Do not edit this file directly. -->

# plain.oauth

Let users log in with OAuth providers.
Expand Down Expand Up @@ -139,36 +141,6 @@ That's pretty much it!

## Advanced usage

### Email addresses should be unique

When you're integrating with an OAuth provider,
we think that the user's email address is the best "primary key" when linking to your `User` model in your app.
Unfortunately in Django, by default an email address is not required to be unique!
**We strongly recommend you require email addresses to be unique in your app.**

[As suggested by the Django docs](https://docs.djangoproject.com/en/4.0/topics/auth/customizing/#using-a-custom-user-model-when-starting-a-project),
one way to do this is to have your own `User` model:

```python
# In an app named "users", for example
from plain.auth.models import BaseUser

class User(BaseUser):
email = models.EmailField(unique=True)


# In settings.py
AUTH_USER_MODEL = 'users.User'
```

You'll also notice that there are no "email confirmation" or "email verification" flows in this library.
This is also intentional.
You can implement something like that yourself if you need to,
but the easier solution in our opinion is to use an OAuth provider you *trust to have done that already*.
If you look at our [provider examples](https://github.com/forgepackages/plain-oauth/tree/master/provider_examples) you'll notice how we often use provider APIs to get the email address which is "primary" and "verified" already.
If they've already done that work,
then we can just use that information.

### Handling OAuth errors

The most common error you'll run into is if an existing user clicks a login button,
Expand Down Expand Up @@ -277,7 +249,7 @@ python manage.py check --database default

## FAQs

### How is this different from [other Django OAuth libraries](https://djangopackages.org/grids/g/oauth/)?
### How is this different from [Django OAuth libraries](https://djangopackages.org/grids/g/oauth/)?

The short answer is that *it does less*.

Expand Down
34 changes: 3 additions & 31 deletions plain-oauth/plain/oauth/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<!-- This file is compiled from plain-oauth/plain/oauth/README.md. Do not edit this file directly. -->

# plain.oauth

Let users log in with OAuth providers.
Expand Down Expand Up @@ -137,36 +139,6 @@ That's pretty much it!

## Advanced usage

### Email addresses should be unique

When you're integrating with an OAuth provider,
we think that the user's email address is the best "primary key" when linking to your `User` model in your app.
Unfortunately in Django, by default an email address is not required to be unique!
**We strongly recommend you require email addresses to be unique in your app.**

[As suggested by the Django docs](https://docs.djangoproject.com/en/4.0/topics/auth/customizing/#using-a-custom-user-model-when-starting-a-project),
one way to do this is to have your own `User` model:

```python
# In an app named "users", for example
from plain.auth.models import BaseUser

class User(BaseUser):
email = models.EmailField(unique=True)


# In settings.py
AUTH_USER_MODEL = 'users.User'
```

You'll also notice that there are no "email confirmation" or "email verification" flows in this library.
This is also intentional.
You can implement something like that yourself if you need to,
but the easier solution in our opinion is to use an OAuth provider you *trust to have done that already*.
If you look at our [provider examples](https://github.com/forgepackages/plain-oauth/tree/master/provider_examples) you'll notice how we often use provider APIs to get the email address which is "primary" and "verified" already.
If they've already done that work,
then we can just use that information.

### Handling OAuth errors

The most common error you'll run into is if an existing user clicks a login button,
Expand Down Expand Up @@ -275,7 +247,7 @@ python manage.py check --database default

## FAQs

### How is this different from [other Django OAuth libraries](https://djangopackages.org/grids/g/oauth/)?
### How is this different from [Django OAuth libraries](https://djangopackages.org/grids/g/oauth/)?

The short answer is that *it does less*.

Expand Down
Loading

0 comments on commit b3a759c

Please sign in to comment.