<s> from django . shortcuts import render , redirect <EOL> from django . http import HttpResponse <EOL> from tapiriik . database import db <EOL> from tapiriik . settings import WITHDRAWN_SERVICES <EOL> import json <EOL> import datetime <EOL> def activities_dashboard ( req ) : <EOL> if not req . user : <EOL> return redirect ( "<STR_LIT:/>" ) <EOL> return render ( req , "<STR_LIT>" ) <EOL> def activities_fetch_json ( req ) : <EOL> if not req . user : <EOL> return HttpResponse ( status = <NUM_LIT> ) <EOL> retrieve_fields = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> activityRecords = db . activity_records . find_one ( { "<STR_LIT>" : req . user [ "<STR_LIT>" ] } , dict ( [ ( x , <NUM_LIT:1> ) for x in retrieve_fields ] ) ) <EOL> if not activityRecords : <EOL> return HttpResponse ( "<STR_LIT>" , content_type = "<STR_LIT:application/json>" ) <EOL> cleanedRecords = [ ] <EOL> for activity in activityRecords [ "<STR_LIT>" ] : <EOL> for presence in activity [ "<STR_LIT>" ] : <EOL> del activity [ "<STR_LIT>" ] [ presence ] [ "<STR_LIT>" ] <EOL> for abscence in activity [ "<STR_LIT>" ] : <EOL> if activity [ "<STR_LIT>" ] [ abscence ] [ "<STR_LIT>" ] : <EOL> del activity [ "<STR_LIT>" ] [ abscence ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> del activity [ "<STR_LIT>" ] [ abscence ] [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> activity [ "<STR_LIT>" ] . update ( activity [ "<STR_LIT>" ] ) <EOL> for svc in WITHDRAWN_SERVICES : <EOL> if svc in activity [ "<STR_LIT>" ] : <EOL> del activity [ "<STR_LIT>" ] [ svc ] <EOL> del activity [ "<STR_LIT>" ] <EOL> cleanedRecords . append ( activity ) <EOL> dthandler = lambda obj : obj . isoformat ( ) if isinstance ( obj , datetime . datetime ) or isinstance ( obj , datetime . date ) else None <EOL> return HttpResponse ( json . dumps ( cleanedRecords , default = dthandler ) , content_type = "<STR_LIT:application/json>" ) </s>
