Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
UCC
uccportal
Commits
51e912ac
Commit
51e912ac
authored
Feb 02, 2019
by
Zack Wong
Browse files
added create_account skeleton
parent
d54c6372
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/account/actions.py
View file @
51e912ac
...
...
@@ -5,9 +5,11 @@ from django.conf import settings
from
django.core.exceptions
import
ImproperlyConfigured
import
ldap
import
memberdb.models
from
datetime
import
date
from
squarepay
import
dispense
log
=
logging
.
getLogger
(
'ldap'
)
# load config
...
...
@@ -98,3 +100,11 @@ def unlock_account(username):
reason
=
"account unlocked by uccportal on %s"
%
str
(
today
)
dispense
.
set_dispense_flag
(
username
,
'!disabled'
,
reason
)
def
create_account
(
member
):
return
None
;
src/gms/__init__.py
0 → 100644
View file @
51e912ac
default_app_config
=
'gms.apps.GmsConfig'
src/squarepay/dispense.py
View file @
51e912ac
...
...
@@ -15,12 +15,11 @@ if DISPENSE_BIN is None:
log
.
warning
(
"DISPENSE_BIN is not defined! Lookups for prices will fallback to weird numbers (for testing)!"
)
def
run_dispense
(
*
args
):
<<<<<<<
HEAD
if
DISPENSE_BIN
is
None
:
return
None
cmd
=
[
DISPENSE_BIN
]
+
args
log
.
info
(
"run_dispense: "
+
cmd
)
cmd
=
(
DISPENSE_BIN
,
)
+
args
log
.
info
(
"run_dispense: "
+
str
(
cmd
)
)
try
:
# get a string containing the output of the program
res
=
subprocess
.
check_output
(
cmd
,
timeout
=
4
,
universal_newlines
=
True
)
...
...
@@ -49,7 +48,7 @@ def get_item_price(itemid):
return
None
else
:
# return the price as a number of cents
return
int
(
float
(
s
[
0
])
*
100
)
return
int
(
float
(
s
[
1
])
*
100
)
def
set_dispense_flag
(
user
,
flag
,
reason
):
if
DISPENSE_BIN
is
None
:
...
...
@@ -64,39 +63,3 @@ def set_dispense_flag(user, flag, reason):
log
.
warning
(
"set_dispense_flag: user was not updated with error: "
+
out
)
return
False
;
return
True
;
=======
if
DISPENSE_BIN
is
None
:
return
None
cmd
=
(
DISPENSE_BIN
,
)
+
args
log
.
info
(
"run_dispense: "
+
str
(
cmd
))
try
:
# get a string containing the output of the program
res
=
subprocess
.
check_output
(
cmd
,
timeout
=
4
,
universal_newlines
=
True
)
except
CalledProcessError
as
e
:
log
.
warning
(
"dispense returned error code %d, output: '%s'"
%
(
e
.
returncode
,
e
.
output
))
return
None
except
TimeoutExpired
as
e
:
log
.
error
(
e
)
return
None
return
res
def
get_item_price
(
itemid
):
""" gets the price of the given dispense item in cents """
if
(
itemid
is
None
or
itemid
==
""
):
return
None
if
DISPENSE_BIN
is
None
:
return
2223
out
=
run_dispense
(
'iteminfo'
,
itemid
)
if
out
is
None
:
return
None
s
=
out
.
split
()
# get something like ['pseudo:7', '25.00', 'membership', '(non-student', 'and', 'non-guild)']
if
(
s
[
0
]
!=
itemid
):
log
.
warning
(
"get_item_price: got result for incorrect item: %s"
+
s
)
return
None
else
:
# return the price as a number of cents
return
int
(
float
(
s
[
1
])
*
100
)
>>>>>>>
origin
/
frekk
-
testing
src/squarepay/dispense.py.orig
0 → 100644
View file @
51e912ac
"""
this file contains utilities for wrapping the opendispense2 CLI utility `dispense`
It is essentially a hack to avoid having to write an actual dispense client here.
"""
import subprocess
from subprocess import CalledProcessError, TimeoutExpired
from django.conf import settings
from .payments import log
DISPENSE_BIN = getattr(settings, 'DISPENSE_BIN', None)
if DISPENSE_BIN is None:
log.warning("DISPENSE_BIN is not defined! Lookups for prices will fallback to weird numbers (for testing)!")
def run_dispense(*args):
<<<<<<< HEAD
if DISPENSE_BIN is None:
return None
cmd = [DISPENSE_BIN] + args
log.info("run_dispense: " + cmd)
try:
# get a string containing the output of the program
res = subprocess.check_output(cmd, timeout=4, universal_newlines=True)
except CalledProcessError as e:
log.warning("dispense returned error code %d, output: '%s'" % (e.returncode, e.output))
return None
except TimeoutExpired as e:
log.error(e)
return None
return res
def get_item_price(itemid):
""" gets the price of the given dispense item in cents """
if (itemid is None or itemid == ""):
return None
if DISPENSE_BIN is None:
return 2223
out = run_dispense('iteminfo', itemid)
if out is None:
return None
s = out.split() # get something like ['pseudo:7', '25.00', 'membership', '(non-student', 'and', 'non-guild)']
if (s[0] != itemid):
log.warning("get_item_price: got result for incorrect item: %s" + s)
return None
else:
# return the price as a number of cents
return int(float(s[0]) * 100)
def set_dispense_flag(user, flag, reason):
if DISPENSE_BIN is None:
log.warning("DISPENSE_BIN is not defined, user will not be disabled")
return False
cmd = [DISPENSE_BIN] + args
out = run_dispense('user', 'type', user, flag, reason)
s = out.split()
if s[2] != "updated":
# user was not updated
log.warning("set_dispense_flag: user was not updated with error: " + out)
return False;
return True;
=======
if DISPENSE_BIN is None:
return None
cmd = (DISPENSE_BIN, ) + args
log.info("run_dispense: " + str(cmd))
try:
# get a string containing the output of the program
res = subprocess.check_output(cmd, timeout=4, universal_newlines=True)
except CalledProcessError as e:
log.warning("dispense returned error code %d, output: '%s'" % (e.returncode, e.output))
return None
except TimeoutExpired as e:
log.error(e)
return None
return res
def get_item_price(itemid):
""" gets the price of the given dispense item in cents """
if (itemid is None or itemid == ""):
return None
if DISPENSE_BIN is None:
return 2223
out = run_dispense('iteminfo', itemid)
if out is None:
return None
s = out.split() # get something like ['pseudo:7', '25.00', 'membership', '(non-student', 'and', 'non-guild)']
if (s[0] != itemid):
log.warning("get_item_price: got result for incorrect item: %s" + s)
return None
else:
# return the price as a number of cents
return int(float(s[1]) * 100)
>>>>>>> origin/frekk-testing
src/squarepay/migrations/0001_initial.py
0 → 100644
View file @
51e912ac
# Generated by Django 2.1.5 on 2019-01-29 04:02
from
django.db
import
migrations
,
models
import
django.db.models.deletion
import
uuid
class
Migration
(
migrations
.
Migration
):
initial
=
True
dependencies
=
[
(
'memberdb'
,
'__first__'
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'CardPayment'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
(
'description'
,
models
.
CharField
(
max_length
=
255
,
verbose_name
=
'Description'
)),
(
'amount'
,
models
.
IntegerField
(
verbose_name
=
'Amount in cents'
)),
(
'idempotency_key'
,
models
.
CharField
(
default
=
uuid
.
uuid1
,
max_length
=
64
,
verbose_name
=
'Square Transactions API idempotency key'
)),
(
'is_paid'
,
models
.
BooleanField
(
blank
=
True
,
default
=
False
,
verbose_name
=
'Has been paid'
)),
(
'dispense_synced'
,
models
.
BooleanField
(
blank
=
True
,
default
=
False
,
verbose_name
=
'Payment logged in dispense'
)),
(
'date_created'
,
models
.
DateTimeField
(
auto_now_add
=
True
,
verbose_name
=
'Date created'
)),
(
'date_paid'
,
models
.
DateTimeField
(
blank
=
True
,
null
=
True
,
verbose_name
=
'Date paid (payment captured)'
)),
],
),
migrations
.
CreateModel
(
name
=
'MembershipPayment'
,
fields
=
[
(
'cardpayment_ptr'
,
models
.
OneToOneField
(
auto_created
=
True
,
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
parent_link
=
True
,
primary_key
=
True
,
serialize
=
False
,
to
=
'squarepay.CardPayment'
)),
(
'membership'
,
models
.
ForeignKey
(
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
related_name
=
'payments'
,
to
=
'memberdb.Membership'
)),
],
bases
=
(
'squarepay.cardpayment'
,),
),
]
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