def get(self, kind = None, time_offset = None):
        if time_offset is None:
            time_offset = str(datetime.datetime.now())

        try:
            time_begin = dateutil.parser.parse(time_offset)
        except ValueError:
            raise APIException("Invalid Offset Time", 400)

        if kind is None:
            notifications = Notification.past(
                destined = current_user.id,
                acquired__lt = time_begin
            )

            notif_list = [_.repr for _ in notifications.limit(5)]
            next_page = False
            try:
                next_page = notif_list[-1]['acquired']
            except Exception:
                "No next page URI"
                pass

            doc = {
                'remaininglen': notifications.count(),
                'next': next_page,
                'data': notif_list,
                'new': Notification.unflagged_count()
            }
            return doc

        if kind == 'surveyresponsenotification':
            notifications = SurveyResponseNotification.past(
                destined = current_user.id,
                acquired__lt = time_begin
            )

            notif_list = [_.repr for _ in notifications.limit(5)]
            next_page = False
            try:
                next_page = notif_list[-1]['acquired']
            except Exception:
                "No next page URI"
                pass

            doc = {
                'remaininglen': notifications.count(),
                'next': next_page,
                'data': notif_list,
                'new': Notification.unflagged_count()
            }
            return doc

        raise APIException("Must specify a valid option", 400,
            usage = {'surveyresponsenotification': 'Survey Responses'}
        )
Beispiel #2
0
def create_response_notification(survey, **kwargs):
    doc = SurveyResponseNotification.objects(
        response = kwargs['response']
    ).modify(
        upsert  = True,
        new     = True,
        set__acquired   = datetime.datetime.now(),
        set__response   = kwargs['response'],
        set__survey     = survey,
        set__destined   = survey.created_by
    )

    doc.payload.update({kwargs['qid']: kwargs['qres']})
    doc.transmit = False
    doc.save()