Skip to content

Commit ee1198d

Browse files
committed
Fixed DatePicker issue #129. Issue was in sortPost.py, any input date was being reset as the current date.
1 parent 41b0f74 commit ee1198d

File tree

8 files changed

+40
-8
lines changed

8 files changed

+40
-8
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ data/inventory.sqlite
88
.~c9*
99
*.sqlite-shm
1010
*.sqlite-wal
11+
.cache/

application/controllers/allCont/ContainerInfoController.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ def maContainerInfo(chemId, barcodeId):
4242
data = request.form
4343
cont = getContainer(barcodeId)
4444
updateHistory(cont, "Checked Out", data['storageId'], user)
45-
changeLocation(cont, True, data) #This line is causing issues because the container info page checkout is different from the snip
45+
status = False
46+
if data['formName'] == 'checkOutForm':
47+
status = True
48+
changeLocation(cont, status, data, user.username) #This line is causing issues because the container info page checkout is different from the snip
4649
# add form data to container as checked out
4750
return redirect('/ViewChemical/%s/' %(chemId))
4851
# Find a way to combine these

application/logic/sortPost.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ def sortPost( data, model):
3434
field_type = getattr(instance, "db_field")
3535
if field_type == "datetime":
3636
fixed_date = convert_to_datetime(data[key])
37-
fixed_date_string = datetime.date.today()
38-
model_data[key] = fixed_date_string
37+
model_data[key] = fixed_date
3938
elif field_type == bool:
4039
model_data[key] = bool(data[key])
4140
else:
@@ -46,4 +45,4 @@ def sortPost( data, model):
4645
return ( model_data, extra_data )
4746

4847
def convert_to_datetime(dateString):
49-
datetime_object = datetime.datetime.strptime(dateString, '%Y-%m-%d')
48+
return datetime.datetime.strptime(dateString, '%Y-%m-%d').date()

application/models/containersModel.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def getContainer(barcode):
3232
"""Returns a Containers object with the given barcode"""
3333
return Containers.get(Containers.barcodeId == barcode)
3434

35-
def changeLocation(cont, status, data):
35+
def changeLocation(cont, status, data, user):
3636
"""Used to check containers in and out
3737
3838
Args:
@@ -45,9 +45,9 @@ def changeLocation(cont, status, data):
4545
if status: # True if checking out
4646
cont.storageId = data['storageId']
4747
cont.checkedOut = status
48-
cont.checkOutReason = data['forClass']
48+
cont.checkOutReason = data['class']
4949
cont.forProf = data['forProf']
50-
cont.checkedOutBy = data['user']
50+
cont.checkedOutBy = user
5151
cont.save()
5252
else: # Checking in
5353
cont.storageId = data['storageId']

application/models/usersModel.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from application.models.util import *
22
from application.logic.sortPost import *
3+
import pytest
34

45
class Users (Model):
56
userId = PrimaryKeyField()
@@ -15,6 +16,18 @@ class Users (Model):
1516
class Meta:
1617
database = getDB("inventory", "dynamic")
1718

19+
def getUsers(username = None):
20+
if username != None:
21+
return Users.get(Users.username == username)
22+
else:
23+
return Users.select()
24+
25+
@pytest.fixture
26+
def getUsersTest():
27+
assert type(getUsers('ballz')) is Users
28+
from peewee import SelectQuery
29+
assert type(getUsers()) is SelectQuery
30+
1831
def createUser(data, createdBy, approval, authLevel = "systemUser"):
1932
"""Used to check containers in and out
2033
@@ -35,7 +48,7 @@ def createUser(data, createdBy, approval, authLevel = "systemUser"):
3548
if 'auth_level' not in modelData:
3649
modelData['auth_level'] = authLevel
3750
# Peewee has a get_or_create function. Would that be more useful than putting this in a try/except?
38-
if modelData['end_date'] >= datetime.date.today():
51+
if modelData['end_date'] <= datetime.date.today():
3952
return("Error: User could not be added. End Date must be later than today.", 'list-group-item list-group-item-danger')
4053
try:
4154
Users.create(**modelData)

application/test/test_queries.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def test_fixture(): #Need a new 'def test_*():' for every test you wish to run
2+
pytest.mark.usefixtures(getUsersTest())

setup.sh

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ PEEWEE_VERSION="${PEEWEE_VERSION:-2.8.1}"
1212
WTF_PEEWEE_VERSION="${WTF_PEEWEE_VERSION:-0.2.6}"
1313
PYYAML_VERSION="${PYYAML_VERSION:-3.11}"
1414
CONFIGURE_VERSION="${CONFIGURE_VERSION:-0.5}"
15+
PYTEST_VERSION="${PYTEST_VERSION:-3.0.5}"
1516

1617
# Check for virtualenv
1718
command -v virtualenv >/dev/null 2>&1 || {
@@ -68,3 +69,6 @@ pip install -U "wtf-peewee==$WTF_PEEWEE_VERSION"
6869

6970
pip install -U "configure==$CONFIGURE_VERSION"
7071
# http://configure.readthedocs.io/en/latest/#
72+
73+
pip install -U "pytest==$PYTEST_VERSION"
74+
# http://docs.pytest.org/en/latest/

test.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def gcd(m, n, count=1):
2+
if m%n == 0:
3+
return(count)
4+
else:
5+
return gcd(n, m%n, count+1)
6+
7+
for i in range(1, 10):
8+
for r in range(1, 10):
9+
print i, r
10+
print gcd(i, r)

0 commit comments

Comments
 (0)