Skip to content

Commit

Permalink
Add initial code
Browse files Browse the repository at this point in the history
  • Loading branch information
codingjoe committed Sep 5, 2023
1 parent cc97e12 commit 21ad120
Show file tree
Hide file tree
Showing 14 changed files with 336 additions and 15 deletions.
29 changes: 29 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# http://editorconfig.org

root = true

[*]
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true
charset = utf-8
end_of_line = lf
max_line_length = 88

[*.{json,yml,yaml,js,jsx,vue,toml}]
indent_size = 2

[*.{html,htm,svg,xml}]
indent_size = 2
max_line_length = 120

[*.{css,scss}]
indent_size = 2

[LICENSE]
insert_final_newline = false

[*.{md,markdown}]
indent_size = 2
max_line_length = 80
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
github:
- amureki
- codingjoe
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2
updates:
- package-ecosystem: pip
directory: "/"
schedule:
interval: weekly
reviewers:
- herrbenesch
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: weekly
reviewers:
- herrbenesch
72 changes: 72 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: CI

on:
push:
branches:
- main
pull_request:

jobs:

dist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.x"
- run: python -m pip install --upgrade pip build wheel twine
- run: python -m build --sdist --wheel
- run: python -m twine check dist/*
- uses: actions/upload-artifact@v3
with:
path: dist/*

lint:
runs-on: ubuntu-latest
strategy:
matrix:
lint-command:
- bandit -r . -x ./tests
- black --check --diff .
- flake8 .
- isort --check-only --diff .
- pydocstyle .
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.x"
cache: 'pip'
cache-dependency-path: 'linter-requirements.txt'
- run: python -m pip install -r linter-requirements.txt
- run: ${{ matrix.lint-command }}

pytest:
needs:
- lint
strategy:
matrix:
os:
- "ubuntu-latest"
python-version:
- "3.9"
- "3.10"
- "3.11"
django-version:
- "3.2" # LTS
- "4.1"
- "4.2" # LTS
extras:
- "test"

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- run: python -m pip install .[${{ matrix.extras }}]
- run: python -m pip install django~=${{ matrix.django-version }}.0
- run: python -m pytest
- uses: codecov/codecov-action@v3
21 changes: 21 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Release

on:
release:
types: [published]

jobs:

PyPi:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.x"
- run: python -m pip install --upgrade pip build wheel twine
- run: python -m build --sdist --wheel
- run: python -m twine upload dist/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
14 changes: 2 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,5 @@ dmypy.json
# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
# flit
citext/_version.py
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
BSD 3-Clause License

Copyright (c) 2023, voiio GmbH
Copyright (c) 2022, voiio GmbH
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Expand Down
57 changes: 55 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,55 @@
# django-citext
PostgreSQL CITEXT integration for Django
# Django CITEXT

PostgreSQL CITEXT integration for Django.

[![PyPi Version](https://img.shields.io/pypi/v/citext.svg)](https://pypi.python.org/pypi/citext/)
[![Test Coverage](https://codecov.io/gh/voiio/citext/branch/main/graph/badge.svg)](https://codecov.io/gh/voiio/citext)
[![GitHub License](https://img.shields.io/github/license/voiio/citext)](https://raw.githubusercontent.com/voiio/citext/master/LICENSE)

## Setup

```ShellSession
python3 -m pip install django-citext
```

```python
# settings.py
INSTALLED_APPS = [
'citext',
# ...
]
```

## Usage

```python
# myapp/models.py
from django.db import models
from citext import CITextField, CIEmailField


class MyModel(models.Model):
name = CITextField()
email = CIEmailField(unique=True)
```

```python
# myapp/views.py
from django.http import HttpResponse, HttpResponseNotFound

from . import models


def my_view(request, email):
try:
my_model = models.MyModel.objects.get(email=email)
except models.MyModel.DoesNotExist:
return HttpResponseNotFound()
return HttpResponse(my_model.name)
```

## Credits

Project is based on the Django's own CITEXT implementation,
which was removed in Django 5.0. Big thanks to the Django contributors
for their excellent work.
7 changes: 7 additions & 0 deletions citext/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""PostgreSQL CITEXT integration for Django."""

from . import _version
from .fields import * # noqa

__version__ = _version.version
VERSION = _version.version_tuple
36 changes: 36 additions & 0 deletions citext/fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from django.db.models import CharField, EmailField, TextField
from django.test.utils import ignore_warnings
from django.utils.deprecation import RemovedInDjango51Warning

__all__ = ["CICharField", "CIEmailField", "CIText", "CITextField"]


# RemovedInDjango51Warning.
class CIText:
def get_internal_type(self):
return "CI" + super().get_internal_type()

def db_type(self, connection):
return "citext"


class CICharField(CIText, CharField):


def __init__(self, *args, **kwargs):
with ignore_warnings(category=RemovedInDjango51Warning):
super().__init__(*args, **kwargs)


class CIEmailField(CIText, EmailField):

def __init__(self, *args, **kwargs):
with ignore_warnings(category=RemovedInDjango51Warning):
super().__init__(*args, **kwargs)


class CITextField(CIText, TextField):

def __init__(self, *args, **kwargs):
with ignore_warnings(category=RemovedInDjango51Warning):
super().__init__(*args, **kwargs)
6 changes: 6 additions & 0 deletions citext/operations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.contrib.postgres.operations import CreateExtension


class CITextExtension(CreateExtension):
def __init__(self):
self.name = "citext"
5 changes: 5 additions & 0 deletions linter-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bandit==1.7.5
black==23.7.0
flake8==6.0.0
isort==5.12.0
pydocstyle[toml]==6.3.0
80 changes: 80 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
[build-system]
requires = ["flit_core>=3.2", "flit_scm", "wheel"]
build-backend = "flit_scm:buildapi"

[project]
name = "citext"
authors = [
{ name = "Rust Saiargaliev", email = "fly.amureki@gmail.com" },
{ name = "Johannes Maron", email = "johannes@maron.family" },
{ name = "Jörg Benesch", email = "benesch.joerg@gmail.com" }
]
readme = "README.md"
license = { file = "LICENSE" }
keywords = ["PostgreSQL", "Django", "CITEXT", "Case Insensitive", "postgres"]
dynamic = ["version", "description"]
classifiers = [
"Development Status :: 1 - Planning",
"Programming Language :: Python",
"Environment :: Web Environment",
"License :: OSI Approved :: BSD License",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Topic :: Software Development",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Database",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Framework :: Django",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.1",
"Framework :: Django :: 4.2",
]
requires-python = ">=3.10"
dependencies = ["django", "psycopg"]

[project.optional-dependencies]
test = [
"pytest",
"pytest-cov",
"pytest-django",
"psycopg[binary]",
]

[project.urls]
Project-URL = "https://github.com/voiio/citext"
Changelog = "https://github.com/voiio/citext/releases"

[tool.flit.module]
name = "citext"

[tool.setuptools_scm]
write_to = "citext/_version.py"

[tool.pytest.ini_options]
minversion = "6.0"
addopts = "--cov --tb=short -rxs"
testpaths = ["tests"]
DJANGO_SETTINGS_MODULE = "tests.testapp.settings"

[tool.coverage.run]
source = ["citext"]
omit = ["citext/buildapi.py"]

[tool.coverage.report]
show_missing = true

[tool.isort]
atomic = true
line_length = 88
known_first_party = "citext, tests"
include_trailing_comma = true
default_section = "THIRDPARTY"
combine_as_imports = true

[tool.pydocstyle]
add_ignore = "D1"
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
max-line-length=88
select = C,E,F,W,B,B950
ignore = E203, E501, W503, E731

0 comments on commit 21ad120

Please sign in to comment.