Beispiel #1
0
 def post(self, request, *args, **kwargs):
     try:
         data = json.loads(request.body).get('schema_data', {})
         draft = DraftRegistration.load(self.kwargs.get('draft_pk'))
         draft.update_metadata(data)
         draft.save()
         log_message = list()
         for key, value in data.iteritems():
             comments = data.get(key, {}).get('comments', [])
             for comment in comments:
                 log_message.append('{}: {}'.format(key, comment['value']))
         update_admin_log(
             user_id=request.user.id,
             object_id=draft._id,
             object_repr='Draft Registration',
             message='Comments: <p>{}</p>'.format('</p><p>'.join(log_message)),
             action_flag=COMMENT_PREREG
         )
         return JsonResponse(serializers.serialize_draft_registration(draft))
     except AttributeError:
         raise Http404('{} with id "{}" not found.'.format(
             self.context_object_name.title(),
             self.kwargs.get('draft_pk')
         ))
     except NodeStateError as e:
         return bad_request(request, e)
Beispiel #2
0
 def get_context_data(self, **kwargs):
     kwargs.setdefault(
         'draft',
         serializers.serialize_draft_registration(self.draft,
                                                  json_safe=False))
     kwargs.setdefault('IMMEDIATE', serializers.IMMEDIATE)
     return super(DraftFormView, self).get_context_data(**kwargs)
Beispiel #3
0
def prereg(request):
    """Redirects to prereg page if user has prereg access
    :param request: Current logged in user
    :return: Redirect to prereg page with username, reviewers, and user obj
    """
    paginator = Paginator(get_prereg_drafts(user=request.user), 5)

    try:
        page_number = int(request.GET.get('page'))
    except (TypeError, ValueError):
        page_number = 1

    page = paginator.page(page_number)

    try:
        drafts = [
            serializers.serialize_draft_registration(d, json_safe=False)
            for d in page
        ]
    except EmptyPage:
        drafts = []

    for draft in drafts:
        draft['form'] = DraftRegistrationForm(draft)

    context = {'drafts': drafts, 'page': page}
    return render(request, 'pre_reg/prereg.html', context)
Beispiel #4
0
 def post(self, request, *args, **kwargs):
     try:
         data = json.loads(request.body).get('schema_data', {})
         draft = DraftRegistration.load(self.kwargs.get('draft_pk'))
         draft.update_metadata(data)
         draft.save()
         log_message = list()
         for key, value in data.iteritems():
             comments = data.get(key, {}).get('comments', [])
             for comment in comments:
                 log_message.append('{}: {}'.format(key, comment['value']))
         update_admin_log(
             user_id=request.user.id,
             object_id=draft._id,
             object_repr='Draft Registration',
             message='Comments: <p>{}</p>'.format('</p><p>'.join(log_message)),
             action_flag=COMMENT_PREREG
         )
         return JsonResponse(serializers.serialize_draft_registration(draft))
     except AttributeError:
         raise Http404('{} with id "{}" not found.'.format(
             self.context_object_name.title(),
             self.kwargs.get('draft_pk')
         ))
     except NodeStateError as e:
         return bad_request(request, e)
Beispiel #5
0
def update_draft(request, draft_pk):
    """Updates current draft to save admin comments

    :param draft_pk: Unique id for current draft
    :return: DraftRegistration obj
    """
    data = json.loads(request.body)
    draft = get_draft_or_error(draft_pk)

    if 'admin_settings' in data:
        form = DraftRegistrationForm(data=data['admin_settings'])
        if not form.is_valid():
            return HttpResponseBadRequest("Invalid form data")
        admin_settings = form.cleaned_data
        draft.notes = admin_settings.get('notes', draft.notes)
        del admin_settings['notes']
        draft.flags = admin_settings
        draft.save()
    else:
        schema_data = data.get('schema_data', {})
        data = deepcopy(draft.registration_metadata)
        for key, value in data.items():
            data[key]['comments'] = schema_data.get(key, {}).get('comments', [])
        try:
            draft.update_metadata(data)
            draft.save()
        except (NodeStateError):
            raise HTTPError(http.BAD_REQUEST)
    return JsonResponse(serializers.serialize_draft_registration(draft))
Beispiel #6
0
 def get_context_data(self, **kwargs):
     kwargs.setdefault('draft', serializers.serialize_draft_registration(
         self.draft,
         json_safe=False
     ))
     kwargs.setdefault('IMMEDIATE', serializers.IMMEDIATE)
     return super(DraftFormView, self).get_context_data(**kwargs)
Beispiel #7
0
def prereg(request):
    """Redirects to prereg page if user has prereg access
    :param request: Current logged in user
    :return: Redirect to prereg page with username, reviewers, and user obj
    """
    paginator = Paginator(get_prereg_drafts(user=request.user), 5)

    try:
        page_number = int(request.GET.get('page'))
    except (TypeError, ValueError):
        page_number = 1

    page = paginator.page(page_number)

    try:
        drafts = [serializers.serialize_draft_registration(d, json_safe=False) for d in page]
    except EmptyPage:
        drafts = []

    for draft in drafts:
        draft['form'] = DraftRegistrationForm(draft)

    context = {
        'drafts': drafts,
        'page': page,
        'IMMEDIATE': serializers.IMMEDIATE,
    }
    return render(request, 'pre_reg/prereg.html', context)
Beispiel #8
0
 def get_object(self, queryset=None):
     try:
         return serializers.serialize_draft_registration(
             DraftRegistration.load(self.kwargs.get('draft_pk')))
     except AttributeError:
         raise Http404('{} with id "{}" not found.'.format(
             self.context_object_name.title(), self.kwargs.get('draft_pk')))
Beispiel #9
0
def update_draft(request, draft_pk):
    """Updates current draft to save admin comments

    :param draft_pk: Unique id for current draft
    :return: DraftRegistration obj
    """
    data = json.loads(request.body)
    draft = get_draft_or_error(draft_pk)

    if 'admin_settings' in data:
        form = DraftRegistrationForm(data=data['admin_settings'])
        if not form.is_valid():
            return HttpResponseBadRequest("Invalid form data")
        admin_settings = form.cleaned_data
        draft.notes = admin_settings.get('notes', draft.notes)
        del admin_settings['notes']
        draft.flags = admin_settings
        draft.save()
    else:
        schema_data = data.get('schema_data', {})
        data = deepcopy(draft.registration_metadata)
        for key, value in data.items():
            data[key]['comments'] = schema_data.get(key,
                                                    {}).get('comments', [])
        try:
            draft.update_metadata(data)
            draft.save()
        except (NodeStateError):
            raise HTTPError(http.BAD_REQUEST)
    return JsonResponse(serializers.serialize_draft_registration(draft))
Beispiel #10
0
def view_draft(request, draft_pk):
    """Redirects to prereg form review page if user has prereg access
    :param draft_pk: Unique id for selected draft
    :return: Redirect to prereg form review page with draft obj
    """
    draft = get_draft_or_error(draft_pk)
    context = {'draft': serializers.serialize_draft_registration(draft)}
    return render(request, 'pre_reg/edit_draft_registration.html', context)
Beispiel #11
0
 def get_object(self, queryset=None):
     draft = DraftRegistration.objects.select_related('approval').get(
         _id=self.kwargs.get('draft_pk'))
     self.checkout_files(draft)
     try:
         return serializers.serialize_draft_registration(draft)
     except AttributeError:
         raise Http404('{} with id "{}" not found.'.format(
             self.context_object_name.title(), self.kwargs.get('draft_pk')))
Beispiel #12
0
 def get_object(self, queryset=None):
     try:
         return serializers.serialize_draft_registration(
             DraftRegistration.load(self.kwargs.get('draft_pk'))
         )
     except AttributeError:
         raise Http404('{} with id "{}" not found.'.format(
             self.context_object_name.title(),
             self.kwargs.get('draft_pk')
         ))
Beispiel #13
0
 def get_object(self, queryset=None):
     draft = DraftRegistration.objects.select_related('approval').get(_id=self.kwargs.get('draft_pk'))
     self.checkout_files(draft)
     try:
         return serializers.serialize_draft_registration(draft)
     except AttributeError:
         raise Http404('{} with id "{}" not found.'.format(
             self.context_object_name.title(),
             self.kwargs.get('draft_pk')
         ))
Beispiel #14
0
def view_draft(request, draft_pk):
    """Redirects to prereg form review page if user has prereg access
    :param draft_pk: Unique id for selected draft
    :return: Redirect to prereg form review page with draft obj
    """
    draft = get_draft_or_error(draft_pk)
    context = {
        'draft': serializers.serialize_draft_registration(draft)
    }
    return render(request, 'pre_reg/edit_draft_registration.html', context)
Beispiel #15
0
 def get_context_data(self, **kwargs):
     query_set = kwargs.pop('object_list', self.object_list)
     page_size = self.get_paginate_by(query_set)
     paginator, page, query_set, is_paginated = self.paginate_queryset(
         query_set, page_size)
     return {
         'drafts': [
             serializers.serialize_draft_registration(d, json_safe=False)
             for d in query_set
         ],
         'page': page,
     }
Beispiel #16
0
 def get_context_data(self, **kwargs):
     query_set = kwargs.pop('object_list', self.object_list)
     page_size = self.get_paginate_by(query_set)
     paginator, page, query_set, is_paginated = self.paginate_queryset(
         query_set, page_size)
     return {
         'drafts': [
             serializers.serialize_draft_registration(d, json_safe=False)
             for d in query_set
         ],
         'page':
         page,
     }
Beispiel #17
0
 def get_context_data(self, **kwargs):
     query_set = kwargs.pop('object_list', self.object_list)
     page_size = self.get_paginate_by(query_set)
     paginator, page, query_set, is_paginated = self.paginate_queryset(
         query_set, page_size)
     return {
         'drafts': [
             serializers.serialize_draft_registration(d, json_safe=False)
             for d in query_set
         ],
         'page': page,
         'p': self.get_paginate_by(query_set),
         'SORT_BY': SORT_BY,
         'order': self.get_ordering(),
         'status': self.request.GET.get('status', 'all'),
     }
Beispiel #18
0
 def get_context_data(self, **kwargs):
     query_set = kwargs.pop('object_list', self.object_list)
     page_size = self.get_paginate_by(query_set)
     paginator, page, query_set, is_paginated = self.paginate_queryset(
         query_set, page_size)
     return {
         'drafts': [
             serializers.serialize_draft_registration(d, json_safe=False)
             for d in query_set
         ],
         'page': page,
         'p': self.get_paginate_by(query_set),
         'SORT_BY': SORT_BY,
         'order': self.get_ordering(),
         'status': self.request.GET.get('status', 'all'),
     }
Beispiel #19
0
def update_draft(request, draft_pk):
    """Updates current draft to save admin comments

    :param draft_pk: Unique id for current draft
    :return: DraftRegistration obj
    """
    data = json.loads(request.body)
    draft = get_draft_or_error(draft_pk)

    if 'admin_settings' in data:
        form = DraftRegistrationForm(data=data['admin_settings'])
        if not form.is_valid():
            return HttpResponseBadRequest("Invalid form data")
        admin_settings = form.cleaned_data
        draft.notes = admin_settings.get('notes', draft.notes)
        del admin_settings['notes']
        draft.flags = admin_settings
        draft.save()
    else:
        schema_data = data.get('schema_data', {})
        data = deepcopy(draft.registration_metadata)
        log_message = list()
        for key, value in data.items():
            comments = schema_data.get(key, {}).get('comments', [])
            for comment in comments:
                log_message.append('{}: {}'.format(key, comment['value']))
        try:
            draft.update_metadata(data)
            draft.save()
            update_admin_log(
                user_id=request.user.id,
                object_id=draft._id,
                object_repr='Draft Registration',
                message='Comments: <p>{}</p>'.format('</p><p>'.join(log_message)),
                action_flag=COMMENT_PREREG
            )
        except (NodeStateError):
            raise HTTPError(http.BAD_REQUEST)
    return JsonResponse(serializers.serialize_draft_registration(draft))
Beispiel #20
0
def update_draft(request, draft_pk):
    """Updates current draft to save admin comments

    :param draft_pk: Unique id for current draft
    :return: DraftRegistration obj
    """
    data = json.loads(request.body)
    draft = get_draft_or_error(draft_pk)

    if 'admin_settings' in data:
        form = DraftRegistrationForm(data=data['admin_settings'])
        if not form.is_valid():
            return HttpResponseBadRequest("Invalid form data")
        admin_settings = form.cleaned_data
        draft.notes = admin_settings.get('notes', draft.notes)
        del admin_settings['notes']
        draft.flags = admin_settings
        draft.save()
    else:
        schema_data = data.get('schema_data', {})
        data = deepcopy(draft.registration_metadata)
        log_message = list()
        for key, value in data.items():
            comments = schema_data.get(key, {}).get('comments', [])
            for comment in comments:
                log_message.append('{}: {}'.format(key, comment['value']))
        try:
            draft.update_metadata(data)
            draft.save()
            update_admin_log(user_id=request.user.id,
                             object_id=draft._id,
                             object_repr='Draft Registration',
                             message='Comments: <p>{}</p>'.format(
                                 '</p><p>'.join(log_message)),
                             action_flag=COMMENT_PREREG)
        except (NodeStateError):
            raise HTTPError(http.BAD_REQUEST)
    return JsonResponse(serializers.serialize_draft_registration(draft))