Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/bcgov/tfrs
Browse files Browse the repository at this point in the history
UI updates
  • Loading branch information
Hall authored and Hall committed May 4, 2017
2 parents 24e863f + 41a4306 commit 938e183
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 89 deletions.
25 changes: 13 additions & 12 deletions TFRS.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,24 @@
<Compile Include="wsgi.py" />
</ItemGroup>
<ItemGroup>
<Content Include="requirements.txt" />
<Content Include="server\models\__pycache__\Attachment.cpython-35.pyc" />
<Content Include="server\models\__pycache__\AttachmentViewModel.cpython-35.pyc" />
<Content Include="server\models\__pycache__\Audit.cpython-35.pyc" />
<Content Include="server\models\__pycache__\CompliancePeriod.cpython-35.pyc" />
<Content Include="server\models\__pycache__\Contact.cpython-35.pyc" />
<Content Include="server\models\__pycache__\CreditTrade.cpython-35.pyc" />
<Content Include="server\models\__pycache__\FuelSupplier.cpython-35.pyc" />
<Content Include="server\models\__pycache__\History.cpython-35.pyc" />
<Content Include="server\models\__pycache__\Note.cpython-35.pyc" />
<Content Include="server\models\__pycache__\__init__.cpython-35.pyc" />
<Content Include="requirements.txt" />
<Content Include="tfrs\templates\account-activity.html" />
<Content Include="tfrs\templates\base.html" />
<Content Include="tfrs\templates\dashboard.html" />
<Content Include="tfrs\templates\new-transaction.html" />
<Content Include="tfrs\templates\db-notifications.html" />
<Content Include="tfrs\templates\notifications.html" />
<Content Include="tfrs\templates\settings.html" />
<Content Include="tfrs\templates\tfrs\fuelSupply.html" />
<Content Include="tfrs\templates\tfrs\index.html" />
<Content Include="tfrs\templates\transaction-summary.html" />
</ItemGroup>
<ItemGroup>
<Folder Include="server\" />
<Folder Include="server\migrations\" />
<Folder Include="server\models\" />
<Folder Include="server\models\__pycache__\" />
<Folder Include="tfrs\templates\" />
<Folder Include="tfrs\templates\tfrs\" />
<Folder Include="welcome\" />
<Folder Include="tfrs\" />
</ItemGroup>
Expand Down
29 changes: 0 additions & 29 deletions server/database.py

This file was deleted.

8 changes: 6 additions & 2 deletions server/test_api_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ def test_groupsIdUsersGet(self):
fuelSupplierId = self.createFuelSupplier(contactId)
userId = self.createUser(fuelSupplierId)
# add user to group.
userGroupUrl = "/api/users/" + str(userId) + "/groups"
userGroupUrl = "/api/users/" + str(groupId) + "/groups"
# create a new group membership.
payload = {'active': True, 'group':groupId, 'user':userId}
jsonString = json.dumps(payload)
Expand Down Expand Up @@ -1427,7 +1427,11 @@ def test_usersSearchGet(self):
self.deleteUser(userId)
self.deleteFuelSupplier(fuelSupplierId)
self.deleteContact(contactId)


def test_ApiViewer(self):
testUrl = "/api/"
response = self.client.get(testUrl)
assert status.HTTP_200_OK == response.status_code

if __name__ == '__main__':
unittest.main()
Expand Down
109 changes: 65 additions & 44 deletions server/views_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ def post(self, request):
class credittradesIdNotesGet(APIView):
"""
Returns notes for a particular CreditTrade
"""
# enter code for this routine here.

"""
def get(self, request, id):
"""
Returns notes for a particular CreditTrade
Expand Down Expand Up @@ -253,8 +251,7 @@ def put(self, request):
class usersCurrentFavouritesSearchGet(APIView):
"""
Returns a user's favourites of a given type.
"""
# enter code for this routine here.
"""

def get(self, request):
currentUser = User.objects.all()[0] # replace with current user
Expand All @@ -270,9 +267,7 @@ def get(self, request):
class usersCurrentGet(APIView):
"""
Get the currently logged in user
"""
# enter code for this routine here.

"""
def get(self, request, ):
currentUser = User.objects.all()[0] # replace with current user
serializer = serializers.UserSerializer(currentUser)
Expand All @@ -282,7 +277,6 @@ class fuelsuppliersIdAttachmentsGet(mixins.CreateModelMixin, APIView):
"""
Returns attachments for a particular FuelSupplier
"""
# enter code for this routine here.
lookup_field = 'id'
permission_classes = (permissions.AllowAny,)
queryset = History.objects.all()
Expand Down Expand Up @@ -315,8 +309,7 @@ def post(self, request, id):
class fuelsuppliersIdHistoryGet(APIView):
"""
Returns History for a particular FuelSupplier
"""

"""
def get(self, request, id, offset = None, limit = None):
fuelSupplier = FuelSupplier.objects.get(id=id)
serializer = serializers.HistorySerializer(fuelSupplier.history, many=true)
Expand Down Expand Up @@ -350,8 +343,7 @@ def post(self, request, id ):
"""
Add a note to the FuelSupplier
"""
fuelSupplier = FuelSupplier.objects.get(id=id)
# the body of the post is the data to be added.
fuelSupplier = FuelSupplier.objects.get(id=id)
jsonString = request.body.decode('utf-8')
data = json.loads(jsonString)
note = Note(noteText=data['noteText'], isNoLongerRelevant=data['isNoLongerRelevant'])
Expand All @@ -378,22 +370,18 @@ def get(self, request, fuelSupplierName = None, includeInactive = None):
class groupsIdUsersGet(APIView):
"""
returns users in a given Group
"""
# enter code for this routine here.

"""
def get(self, request, id):
group = Group.objects.get (id = id)
groupMembership = GroupMembership.objects.filter(group=group)
serializer = serializers.GroupMembershipSerializer(groupMembership.users, many=True)
serializer = serializers.GroupMembershipSerializer(groupMembership, many=True)
return Response(serializer.data)


class rolesIdPermissionsGet(APIView):
"""
Get all the permissions for a role
"""
# enter code for this routine here.

"""
def get(self, request, id):
role = Role.objects.get (id = id)
rolePermissions = RolePermission.objects.filter(role = role)
Expand Down Expand Up @@ -433,23 +421,32 @@ def put(self, request, id):
class rolesIdUsersGet(APIView):
"""
Gets all the users for a role
"""
# enter code for this routine here.

"""
def get(self, request, id):
role = Role.objects.get (id = id)
serializer = serializers.UserSerializer(role.users)
role = Role.objects.get (id = id)
userRoles = UserRole.objects.filter(role = role)
serializer = serializers.UserRoleSerializer(userRoles)
return Response(serializer.data)

class rolesIdUsersPut(APIView):
"""
Updates the users for a role
"""
# enter code for this routine here.

def put(self, request, id, items):
return Response()
def put(self, request, id):
"""
Updates the users for a role
"""
role = Role.objects.get (id = id)
jsonString = request.body.decode('utf-8')
alldata = json.loads(jsonString)
# clear existing User Roles.
UserRole.objects.filter(user=user).delete()

# add the replacement User Role
for data in alldata:
role = Role.objects.get(id = data['role'])
userRole = UserRole(effectiveDate = data['effectiveDate'], expiryDate = data['expiryDate'],role = role, user = user)
userRole.save()
result = UserRole.objects.filter(user=user)
serializer = serializers.UserRoleSerializer(result, many=True)
return Response(serializer.data)

class usersIdFavouritesGet(APIView):
def get(self, request, id):
"""
Expand Down Expand Up @@ -490,8 +487,7 @@ def put(self, request, id):
serializer = serializers.UserFavouriteSerializer(result, many=True)
return Response(serializer.data)

class usersIdGroupsGet(APIView):

class usersIdGroupsGet(APIView):
def get(self, request, id):
"""
Returns all groups that a user is a member of
Expand All @@ -515,7 +511,23 @@ def post(self, request, id):
return Response(serializer.data)

def put(self, request, id):
return Response()
"""
Updates a user's group membership
"""
user = User.objects.get(id=id)
jsonString = request.body.decode('utf-8')
alldata = json.loads(jsonString)
# clear existing favourites.
GroupMembership.objects.filter(user=user).delete()

# add the replacement GroupMemberships
for data in alldata:
group = Group.objects.get(id = data['group'])
groupMembership = GroupMembership(active = data['active'], group = group, user = user)
groupMembership.save()
result = GroupMembership.objects.filter(user=user)
serializer = serializers.GroupMembershipSerializer(result, many=True)
return Response(serializer.data)

class usersIdNotificationsGet(APIView):

Expand All @@ -542,12 +554,10 @@ def post(self, request, id):
return Response(serializer.data)

class usersIdPermissionsGet(APIView):
"""
Returns the set of permissions for a user
"""

def get(self, request, id):
"""
Returns a user's permissions
Returns the set of permissions for a user
"""
user = User.objects.get(id=id)
userRoles = UserRole.objects.filter(user=user)
Expand Down Expand Up @@ -586,7 +596,20 @@ def put(self, request, id):
"""
Updates the roles for a user
"""
return Response()
user = User.objects.get(id=id)
jsonString = request.body.decode('utf-8')
alldata = json.loads(jsonString)
# clear existing favourites.
UserRole.objects.filter(user=user).delete()

# add the replacement User Role
for data in alldata:
role = Role.objects.get(id = data['role'])
userRole = UserRole(effectiveDate = data['effectiveDate'], expiryDate = data['expiryDate'],role = role, user = user)
userRole.save()
result = UserRole.objects.filter(user=user)
serializer = serializers.UserRoleSerializer(result, many=True)
return Response(serializer.data)

class usersSearchGet(APIView):
def get(self, request, fuelSuppliers = None, surname = None, includeInactive = None):
Expand All @@ -605,6 +628,4 @@ def get(self, request, fuelSuppliers = None, surname = None, includeInactive = N
result = result.filter(status = 'Active')

serializer = serializers.UserSerializer(result, many=True)
return Response(serializer.data)


return Response(serializer.data)
44 changes: 44 additions & 0 deletions tfrs/templates/db-notifications.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{% extends "base.html" %}

{% block title %}Notifications{% endblock %}

{% block content %}
<div class="row">
<div class="col-xs-8 col-xs-offset-2">
<h2>Notifications</h2>
<div>
<div class="list-group notification-list">
<a href="#" class="list-group-item notifications-header">
<span class="col-xs-9">Subject</span>
<span class="col-xs-3">Date</span>
</a>
{% for notification in notifications %}
<a href="#" data-toggle="modal" data-target="#{{ notification.id }}-notification" class="list-group-item">
<span class="col-xs-9">{{ notification.event.eventTypeCode }}</span>
<span class="col-xs-3">{{ notification.event.eventTime }}</span>
</a>
{% endfor %}
</div>
</div>
</div>
</div>

{% for notification in notifications %}
<div class="modal fade" id="{{ notification.id }}-notification" tabindex="-1" role="dialog" aria-labelledby="partnerNotFound">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">{{ notification.event.eventTypeCode }}</h4>
</div>
<div class="modal-body">
<p>{{ notification.event.notes }}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
{% endfor %}
{% endblock %}
4 changes: 2 additions & 2 deletions tfrs/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.conf.urls import include, url
from django.contrib import admin

from welcome.views import index, health
from . import views

urlpatterns = [
Expand All @@ -10,9 +9,10 @@
url(r'^settings/$', views.settings),
url(r'^test/$', views.settings),
url(r'^notifications/$', views.notifications),
url(r'^db-notifications/$', views.db_notifications),
url(r'^new-transaction/$', views.new_transaction),
url(r'^transaction-summary/$', views.transaction_summary),
# url(r'^admin/', include(admin.site.urls)),
url(r'^health$', health),
url(r'^api/', include('server.urls')),
url(r'^health$', views.health),
]
15 changes: 15 additions & 0 deletions tfrs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.http import HttpResponse
from django.shortcuts import render
from server.models.FuelSupplier import FuelSupplier

def dashboard(request):
table_data = [
Expand Down Expand Up @@ -63,3 +64,17 @@ def notifications(request):
{'id': 3, 'subject': 'Credits Awarded - Part Three', 'date': '2017-02-15', 'flagged': False, 'message': 'Credits have been awarded by Part Three Agreement'}
]
return render(request, 'notifications.html', {'notifications': notifications})

# example of connecting a view to the generated API

from server.models.Notification import Notification

def db_notifications(request):
notifications = Notification.objects.all() # .select_related()
return render(request, 'db-notifications.html', {'notifications': notifications})

def health(request):
"""
Health check for OpenShift
"""
return HttpResponse(FuelSupplier.objects.count())

0 comments on commit 938e183

Please sign in to comment.