Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
David Seaward
Keel - LDH Middleware
Commits
640870e4
Commit
640870e4
authored
Dec 09, 2017
by
David Seaward
Browse files
convert Service and ExternalParser to enums
parent
c995f11e
Changes
3
Hide whitespace changes
Inline
Side-by-side
limitmonitor/migrations/0003_auto_20171208_1327.py
0 → 100644
View file @
640870e4
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2017-12-08 13:27
from
__future__
import
unicode_literals
import
choicesenum.django.fields
from
django.db
import
migrations
import
limitmonitor.models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'limitmonitor'
,
'0002_auto_20171009_2334'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'externalbundle'
,
name
=
'parser'
,
field
=
choicesenum
.
django
.
fields
.
EnumIntegerField
(
default
=
limitmonitor
.
models
.
ExternalParser
(
0
),
enum
=
limitmonitor
.
models
.
ExternalParser
),
),
migrations
.
AlterField
(
model_name
=
'externalbundle'
,
name
=
'service'
,
field
=
choicesenum
.
django
.
fields
.
EnumIntegerField
(
default
=
limitmonitor
.
models
.
Service
(
0
),
enum
=
limitmonitor
.
models
.
Service
),
),
migrations
.
AlterField
(
model_name
=
'externalcredit'
,
name
=
'parser'
,
field
=
choicesenum
.
django
.
fields
.
EnumIntegerField
(
default
=
limitmonitor
.
models
.
ExternalParser
(
0
),
enum
=
limitmonitor
.
models
.
ExternalParser
),
),
migrations
.
AlterField
(
model_name
=
'limit'
,
name
=
'service'
,
field
=
choicesenum
.
django
.
fields
.
EnumIntegerField
(
default
=
limitmonitor
.
models
.
Service
(
0
),
enum
=
limitmonitor
.
models
.
Service
),
),
]
limitmonitor/models.py
View file @
640870e4
from
choicesenum
import
ChoicesEnum
from
choicesenum.django.fields
import
EnumIntegerField
from
django.conf
import
settings
from
django.db
import
models
from
django.utils
import
timezone
EXTERNAL_PARSER_CHOICES
=
(
(
"WOO1"
,
"WooCommerce v1"
),
(
"WOOSUB1"
,
"WooCommerce Subscription v1"
),
)
SERVICE_CHOICES
=
(
(
"TUNNEL"
,
"Tunnel"
),
(
"COMMUNICATION"
,
"Communication"
),
)
class
ExternalParser
(
ChoicesEnum
):
UNDEFINED
=
0
,
"Undefined"
WOO1
=
1
,
"WooCommerce v1"
WOOSUB1
=
2
,
"WooCommerce Subscription v1"
class
Service
(
ChoicesEnum
):
UNDEFINED
=
0
,
"Undefined"
TUNNEL
=
1
,
"Tunnel"
COMMUNICATION
=
2
,
"Communication"
def
create_missing_user_limits
(
user
):
for
code
,
label
in
SERVICE_CHOICES
:
if
not
Limit
.
objects
.
filter
(
user
=
user
,
service
=
code
).
exists
():
for
code
,
label
in
Service
.
choices
():
is_undefined
=
code
==
Service
.
UNDEFINED
.
value
is_exists
=
Limit
.
objects
.
filter
(
user
=
user
,
service
=
code
).
exists
()
if
not
is_undefined
and
not
is_exists
:
Limit
(
user
=
user
,
service
=
code
).
save
()
class
Limit
(
models
.
Model
):
user
=
models
.
ForeignKey
(
settings
.
AUTH_USER_MODEL
)
service
=
models
.
CharField
(
max_length
=
30
,
choices
=
SERVICE_CHOICES
)
service
=
EnumIntegerField
(
enum
=
Service
,
default
=
Service
.
UNDEFINED
)
renewal_date
=
models
.
DateTimeField
(
default
=
None
,
blank
=
True
,
null
=
True
)
expiry_date
=
models
.
DateTimeField
(
default
=
None
,
blank
=
True
,
null
=
True
)
volume_total
=
models
.
DecimalField
(
default
=
0
,
decimal_places
=
2
,
max_digits
=
6
)
...
...
@@ -33,7 +39,7 @@ class Limit(models.Model):
def
service_label
(
self
):
label
=
"None"
for
key
,
value
in
S
ERVICE_CHOICES
:
for
key
,
value
in
S
ervice
.
choices
()
:
if
self
.
service
==
key
:
label
=
value
...
...
@@ -106,9 +112,9 @@ class Limit(models.Model):
class
ExternalBundle
(
models
.
Model
):
parser
=
models
.
CharField
(
max_length
=
30
,
choices
=
EXTERNAL_PARSER_CHOICES
)
parser
=
EnumIntegerField
(
enum
=
ExternalParser
,
default
=
ExternalParser
.
UNDEFINED
)
external_key
=
models
.
CharField
(
max_length
=
30
)
service
=
models
.
CharField
(
max_length
=
30
,
choices
=
SERVICE_CHOICES
)
service
=
EnumIntegerField
(
enum
=
Service
,
default
=
Service
.
UNDEFINED
)
time_credit
=
models
.
DecimalField
(
default
=
0
,
decimal_places
=
2
,
max_digits
=
6
)
volume_credit
=
models
.
DecimalField
(
default
=
0
,
decimal_places
=
2
,
max_digits
=
6
)
created_date
=
models
.
DateTimeField
(
default
=
timezone
.
now
)
...
...
@@ -116,7 +122,7 @@ class ExternalBundle(models.Model):
class
ExternalCredit
(
models
.
Model
):
parser
=
models
.
CharField
(
max_length
=
30
,
choices
=
EXTERNAL_PARSER_CHOICES
)
parser
=
EnumIntegerField
(
enum
=
ExternalParser
,
default
=
ExternalParser
.
UNDEFINED
)
external_key
=
models
.
CharField
(
max_length
=
30
)
label
=
models
.
CharField
(
max_length
=
30
)
bundle_key
=
models
.
CharField
(
max_length
=
30
)
...
...
purist/migrations/0002_auto_20171208_1327.py
0 → 100644
View file @
640870e4
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2017-12-08 13:27
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
import
purist.custom
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'purist'
,
'0001_initial'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'user'
,
name
=
'username'
,
field
=
models
.
CharField
(
error_messages
=
{
'unique'
:
'A user with that username already exists.'
},
help_text
=
'Required. Start with a letter, followed by letters and numbers.'
,
max_length
=
150
,
unique
=
True
,
validators
=
[
purist
.
custom
.
UsernameValidator
()],
verbose_name
=
'username'
),
),
]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment