Skip to content

Commit

Permalink
[#18, #27] user messages, email, admin user
Browse files Browse the repository at this point in the history
  • Loading branch information
mjstealey committed Oct 28, 2022
1 parent 10b3500 commit 35d3e80
Show file tree
Hide file tree
Showing 30 changed files with 1,029 additions and 84 deletions.
1 change: 1 addition & 0 deletions compose/docker-compose.yml.docker
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ services:
- UWSGI_UID=${UWSGI_UID}
- UWSGI_GID=${UWSGI_GID}
- LOAD_FIXTURES=${LOAD_FIXTURES:-0}
- MAKE_MIGRATIONS=${MAKE_MIGRATIONS:-0}
restart: unless-stopped

networks:
Expand Down
10 changes: 7 additions & 3 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ done

>&2 echo "Postgres is up - continuing"

if [[ "${LOAD_FIXTURES}" -eq 1 ]]; then
./run_server.sh --mode docker --load-fixtures
if [ "${LOAD_FIXTURES}" -eq 1 ] && [ "${MAKE_MIGRATIONS}" -eq 1 ]; then
./run_server.sh --run-mode docker --load-fixtures --make-migrations
elif [ "${LOAD_FIXTURES}" -eq 1 ]; then
./run_server.sh --run-mode docker --load-fixtures
elif [ "${MAKE_MIGRATIONS}" -eq 1 ]; then
./run_server.sh --run-mode docker --make-migrations
else
./run_server.sh --mode docker
./run_server.sh --run-mode docker
fi

exec "$@"
5 changes: 3 additions & 2 deletions portal/apps/experiment_files/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ def experiment_file_list(request):
max_range = int(current_page - 1) * int(REST_FRAMEWORK['PAGE_SIZE']) + int(REST_FRAMEWORK['PAGE_SIZE'])
if max_range > count:
max_range = count

else:
experiment_files = {}
item_range = '{0} - {1}'.format(str(min_range), str(max_range))
except Exception as exc:
message = exc
experiment_files = None
experiment_files = {}
item_range = None
next_page = None
prev_page = None
Expand Down
10 changes: 6 additions & 4 deletions portal/apps/experiments/api/experiment_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ def active_development_to_saving_development(request, experiment: AerpawExperime
else:
# PRODUCTION:
if exit_development:
command = "sudo python3 /home/aerpawops/AERPAW-Dev/workflow-scripts/apcf_saveexit_ve_exp.py {0} save-and-exit".format(experiment.id)
command = "sudo python3 /home/aerpawops/AERPAW-Dev/workflow-scripts/apcf_saveexit_ve_exp.py {0} save-and-exit".format(
experiment.id)
else:
command = "sudo python3 /home/aerpawops/AERPAW-Dev/workflow-scripts/apcf_saveexit_ve_exp.py {0} save".format(experiment.id)

command = "sudo python3 /home/aerpawops/AERPAW-Dev/workflow-scripts/apcf_saveexit_ve_exp.py {0} save".format(
experiment.id)

ssh_thread = threading.Thread(target=saving_development, args=(request, experiment, command, exit_development))
ssh_thread.start()
Expand Down Expand Up @@ -923,7 +924,8 @@ def saving_development(request, experiment: AerpawExperiment, command: str, exit
detail="SaveError: something occurred during the save for /experiments/{0}/state".format(experiment.id))
else:
raise NotFound(
detail="SaveError: unable to deploy active_development for /experiments/{0}/state".format(experiment.id))
detail="SaveError: unable to deploy active_development for /experiments/{0}/state".format(
experiment.id))


def saving_sandbox(request, experiment: AerpawExperiment, command: str, exit_sandbox: bool):
Expand Down
4 changes: 3 additions & 1 deletion portal/apps/experiments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ def experiment_list(request):
max_range = int(current_page - 1) * int(REST_FRAMEWORK['PAGE_SIZE']) + int(REST_FRAMEWORK['PAGE_SIZE'])
if max_range > count:
max_range = count
else:
experiments = {}
item_range = '{0} - {1}'.format(str(min_range), str(max_range))
except Exception as exc:
message = exc
experiments = None
experiments = {}
item_range = None
next_page = None
prev_page = None
Expand Down
39 changes: 29 additions & 10 deletions portal/apps/profiles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
from django.http import HttpRequest
from django.shortcuts import get_object_or_404, render
from django.views.decorators.csrf import csrf_exempt
from rest_framework.request import Request
from rest_framework.request import QueryDict, Request

from portal.apps.credentials.api.viewsets import CredentialViewSet
from portal.apps.user_messages.api.viewsets import UserMessageViewSet
from portal.apps.user_requests.api.viewsets import UserRequestViewSet
from portal.apps.user_requests.models import AerpawUserRequest
from portal.apps.users.api.viewsets import UserViewSet
Expand Down Expand Up @@ -93,26 +94,44 @@ def profile(request):
api_request.user = request.user
api_request.method = 'GET'
u = UserViewSet(request=api_request)
# requests data
ur_api_request = Request(request=HttpRequest())
ur_api_request.user = request.user
ur_api_request.method = 'GET'
ur_api_request.query_params.update(
{'user_id': user.id})
ur = UserRequestViewSet(request=ur_api_request)

user_requests = dict(ur.list(request=ur_api_request).data)
user_credentials = u.credentials(request=request, pk=request.user.id).data
user_data = u.retrieve(request=request, pk=request.user.id).data
user_tokens = u.tokens(request=api_request, pk=request.user.id).data

# modify query_params to get requests and messages data
request.query_params = QueryDict('', mutable=True)
request.query_params.update({'user_id': user.id, 'show_read': False, 'show_deleted': False})

# user requests data
ur = UserRequestViewSet(request=request)
user_requests = dict(ur.list(request=request).data)

# user messages data
um = UserMessageViewSet(request=request)
user_messages = dict(um.list(request=request).data)

return render(request,
'profile.html',
{
'user': user,
'user_data': user_data,
'user_tokens': user_tokens,
'user_credentials': user_credentials,
'user_messages': user_messages,
'user_requests': user_requests,
'message': message,
'debug': DEBUG
})


def session_expired(request):
"""
:param request:
:return:
"""
print('session_expired')
return render(request,
'login.html',
{
'session_expired': True
})
5 changes: 3 additions & 2 deletions portal/apps/resources/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ def resource_list(request):
max_range = int(current_page - 1) * int(REST_FRAMEWORK['PAGE_SIZE']) + int(REST_FRAMEWORK['PAGE_SIZE'])
if max_range > count:
max_range = count

else:
resources = {}
item_range = '{0} - {1}'.format(str(min_range), str(max_range))
except Exception as exc:
message = exc
resources = None
resources = {}
item_range = None
next_page = None
prev_page = None
Expand Down
Empty file.
1 change: 1 addition & 0 deletions portal/apps/user_messages/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Register your models here.
54 changes: 54 additions & 0 deletions portal/apps/user_messages/api/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from rest_framework import serializers

from portal.apps.user_messages.models import AerpawUserMessage


class UserMessageSerializerList(serializers.ModelSerializer):
"""
- created - string:sent_date
- created_by - string
- id - int:message_id
- is_deleted - bool
- is_read - bool
- message_body - string
- message_subject - string
- modified - string:last_modified_date
- modified_by - string
- read_date - string
- received_by (fk) - array of int:user_id
- sent_by (fk) - int:user_id
- uuid - string
"""
message_id = serializers.IntegerField(source='id', read_only=True)
sent_date = serializers.DateTimeField(source='created')

class Meta:
model = AerpawUserMessage
fields = ['is_deleted', 'is_read', 'message_body', 'message_id', 'message_subject', 'sent_by', 'sent_date']


class UserMessageSerializerDetail(serializers.ModelSerializer):
"""
- created - string:sent_date
- created_by - string
- id - int:message_id
- is_deleted - bool
- is_read - bool
- message_body - string
- message_subject - string
- modified - string:last_modified_date
- modified_by - string
- read_date - string
- received_by (fk) - array of int:user_id
- sent_by (fk) - int:user_id
- uuid - string
"""
last_modified_by = serializers.CharField(source='modified_by')
modified_date = serializers.DateTimeField(source='modified')
message_id = serializers.IntegerField(source='id', read_only=True)
sent_date = serializers.DateTimeField(source='created')

class Meta:
model = AerpawUserMessage
fields = ['is_deleted', 'is_read', 'last_modified_by', 'message_body', 'message_id', 'message_subject',
'modified_date', 'received_by', 'read_date', 'sent_by', 'sent_date']
Loading

0 comments on commit 35d3e80

Please sign in to comment.