コード例 #1
0
ファイル: views.py プロジェクト: vernondcole/formhub
def activity_api(request, username):
    from bson.objectid import ObjectId

    def stringify_unknowns(obj):
        if isinstance(obj, ObjectId):
            return str(obj)
        if isinstance(obj, datetime):
            return obj.strftime(DATETIME_FORMAT)
        # raise TypeError
        return None

    try:
        query_args = {
            "username": username,
            "query": json.loads(request.GET.get("query")) if request.GET.get("query") else {},
            "fields": json.loads(request.GET.get("fields")) if request.GET.get("fields") else [],
            "sort": json.loads(request.GET.get("sort")) if request.GET.get("sort") else {},
        }
        if "start" in request.GET:
            query_args["start"] = int(request.GET.get("start"))
        if "limit" in request.GET:
            query_args["limit"] = int(request.GET.get("limit"))
        if "count" in request.GET:
            query_args["count"] = True if int(request.GET.get("count")) > 0 else False
        cursor = AuditLog.query_mongo(**query_args)
    except ValueError, e:
        return HttpResponseBadRequest(e.__str__())
コード例 #2
0
ファイル: views.py プロジェクト: tremolo/formhub
def activity_api(request, username):
    from bson.objectid import ObjectId

    def stringify_unknowns(obj):
        if isinstance(obj, ObjectId):
            return str(obj)
        if isinstance(obj, datetime):
            return obj.strftime(DATETIME_FORMAT)
        #raise TypeError
        return None
    try:
        query_args = {
            'username': username,
            'query': json.loads(request.GET.get('query'))
            if request.GET.get('query') else {},
            'fields': json.loads(request.GET.get('fields'))
            if request.GET.get('fields') else [],
            'sort': json.loads(request.GET.get('sort'))
            if request.GET.get('sort') else {}
        }
        if 'start' in request.GET:
            query_args["start"] = int(request.GET.get('start'))
        if 'limit' in request.GET:
            query_args["limit"] = int(request.GET.get('limit'))
        if 'count' in request.GET:
            query_args["count"] = True \
                if int(request.GET.get('count')) > 0 else False
        cursor = AuditLog.query_mongo(**query_args)
    except ValueError, e:
        return HttpResponseBadRequest(e.__str__())
コード例 #3
0
ファイル: test_audit_log.py プロジェクト: ACTillage/formhub
 def test_audit_log_call(self):
     account_user = self._create_user("alice", "alice")
     self._create_user_and_login("bob", "bob")
     request = RequestFactory().get("/")
     # create a log
     audit = {}
     audit_log(Actions.FORM_PUBLISHED, self.user, account_user,
         "Form published", audit, request)
     # function should just run without exception so we are good at this point
     # query for this log entry
     sort = {"created_on": -1}
     cursor = AuditLog.query_mongo(account_user.username, None, None, sort, 0, 1)
     record = cursor.next()
     self.assertEqual(record['account'], "alice")
     self.assertEqual(record['user'], "bob")
     self.assertEqual(record['action'], Actions.FORM_PUBLISHED)
コード例 #4
0
 def test_audit_log_call(self):
     account_user = self._create_user("alice", "alice")
     self._create_user_and_login("bob", "bob")
     request = RequestFactory().get("/")
     # create a log
     audit = {}
     audit_log(Actions.FORM_PUBLISHED, self.user, account_user,
               "Form published", audit, request)
     # function should just run without exception so we are good at this point
     # query for this log entry
     sort = {"created_on": -1}
     cursor = AuditLog.query_mongo(account_user.username, None, None, sort,
                                   0, 1)
     record = cursor.next()
     self.assertEqual(record['account'], "alice")
     self.assertEqual(record['user'], "bob")
     self.assertEqual(record['action'], Actions.FORM_PUBLISHED)