示例#1
0
 def get_queryset(self):
     query = (Q('registration_schema', 'eq', get_prereg_schema())
              & Q('approval', 'ne', None))
     ordering = self.get_ordering()
     if 'initiator' in ordering:
         return DraftRegistration.find(query).sort(ordering)
     if ordering == SORT_BY['title']:
         return DraftRegistration.find(query).sort(
             'registration_metadata.q1.value')
     if ordering == SORT_BY['n_title']:
         return DraftRegistration.find(query).sort(
             '-registration_metadata.q1.value')
     return sort_drafts(DraftRegistration.find(query), ordering)
示例#2
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)
示例#3
0
 def dispatch(self, request, *args, **kwargs):
     self.draft = DraftRegistration.load(self.kwargs.get('draft_pk'))
     if self.draft is None:
         raise Http404('{} with id "{}" not found.'.format(
             self.context_object_name.title(),
             self.kwargs.get('draft_pk')
         ))
     return super(DraftFormView, self).dispatch(request, *args, **kwargs)
示例#4
0
 def get_object(self, queryset=None):
     draft = DraftRegistration.load(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')))
示例#5
0
 def get_object(self, *args, **kwargs):
     return DraftRegistration.load(self.kwargs.get('draft_pk'))