forked from pylint-dev/pylint-django
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for django.contrib.postgres.fields and also UUIDField
NOTE: merged with modifications: - resolved conflicts - updated where test files are on disk Original PR: pylint-dev#84
- Loading branch information
Showing
8 changed files
with
138 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
pylint_django/transforms/transforms/django_contrib_postgres_fields.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from django.contrib.postgres import fields as django_fields | ||
from psycopg2 import extras | ||
|
||
|
||
# -------- | ||
# lists | ||
|
||
class ArrayField(list, django_fields.ArrayField): | ||
pass | ||
|
||
|
||
# -------- | ||
# dicts | ||
|
||
class HStoreField(dict, django_fields.HStoreField): | ||
pass | ||
|
||
|
||
class JSONField(dict, django_fields.JSONField): | ||
pass | ||
|
||
|
||
# -------- | ||
# ranges | ||
|
||
class RangeField(extras.Range, django_fields.RangeField): | ||
pass | ||
|
||
|
||
class IntegerRangeField(extras.NumericRange, django_fields.IntegerRangeField): | ||
pass | ||
|
||
|
||
class BigIntegerRangeField(extras.NumericRange, django_fields.BigIntegerRangeField): | ||
pass | ||
|
||
|
||
class FloatRangeField(extras.NumericRange, django_fields.FloatRangeField): | ||
pass | ||
|
||
|
||
class DateTimeRangeField(extras.DateTimeTZRange, django_fields.DateRangeField): | ||
pass | ||
|
||
|
||
class DateRangeField(extras.DateRange, django_fields.DateRangeField): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
""" | ||
Checks that Pylint does not complain Postgres model fields. | ||
""" | ||
# pylint: disable=C0111,W5101 | ||
from __future__ import print_function | ||
|
||
from django.contrib.postgres import fields | ||
from django.db import models | ||
|
||
|
||
class PostgresFieldsModel(models.Model): | ||
arrayfield = fields.ArrayField(models.CharField()) | ||
hstorefield = fields.HStoreField() | ||
jsonfield = fields.JSONField() | ||
rangefield = fields.RangeField() | ||
integerrangefield = fields.IntegerRangeField() | ||
bigintegerrangefield = fields.BigIntegerRangeField() | ||
floatrangefield = fields.FloatRangeField() | ||
datetimerangefield = fields.DateTimeRangeField() | ||
daterangefield = fields.DateRangeField() | ||
|
||
def arrayfield_tests(self): | ||
sorted_array = self.arrayfield.sort() | ||
print(sorted_array) | ||
|
||
def dictfield_tests(self): | ||
print(self.hstorefield.keys()) | ||
print(self.hstorefield.values()) | ||
print(self.hstorefield.update({'foo': 'bar'})) | ||
|
||
print(self.jsonfield.keys()) | ||
print(self.jsonfield.values()) | ||
print(self.jsonfield.update({'foo': 'bar'})) | ||
|
||
def rangefield_tests(self): | ||
print(self.rangefield.lower) | ||
print(self.rangefield.upper) | ||
|
||
print(self.integerrangefield.lower) | ||
print(self.integerrangefield.upper) | ||
|
||
print(self.bigintegerrangefield.lower) | ||
print(self.bigintegerrangefield.upper) | ||
|
||
print(self.floatrangefield.lower) | ||
print(self.floatrangefield.upper) | ||
|
||
print(self.datetimerangefield.lower) | ||
print(self.datetimerangefield.upper) | ||
|
||
print(self.daterangefield.lower) | ||
print(self.daterangefield.upper) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[testoptions] | ||
requires = psycopg2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
""" | ||
Checks that Pylint does not complain about UUID fields. | ||
""" | ||
# pylint: disable=C0111,W5101 | ||
from __future__ import print_function | ||
from django.db import models | ||
|
||
|
||
class LotsOfFieldsModel(models.Model): | ||
uuidfield = models.UUIDField() | ||
|
||
def uuidfield_tests(self): | ||
print(self.uuidfield.bytes) | ||
print(self.uuidfield.bytes_le) | ||
print(self.uuidfield.fields[2]) | ||
print(self.uuidfield.hex) | ||
# print(self.uuidfield.int) # Don't know how to properly check this one | ||
print(self.uuidfield.variant) | ||
print(self.uuidfield.version) |