def writecomment(request): try: if not checkConnection(): return HttpResponseServerError('Brak połączenia z Internetem.') data = json.loads(request.body) if len(data['comment']) == 0: return HttpResponseServerError('Treść komentarza nie może być pusta.') newcomment = { 'uid': config['uid'], 'timestamp': gettimestamp(), 'readby': {}, 'comment': data['comment'], 'history': [] } newcomment['readby'][config['uid']] = newcomment['timestamp'] newcomment['history'].append({'timestamp': newcomment['timestamp'], 'comment': newcomment['comment']}) fullpath = os.path.join(data['fullthreadpath'], newcomment['timestamp'] + fileseparator + config['uid']) saveJSON(fullpath, newcomment) return JsonResponse(newcomment, safe=False) except: return HttpResponseServerError('Wystąpił nieznany błąd podczas dodawania komentarza.')
def writenewthread(request): try: if not checkConnection(): return HttpResponseServerError('Brak połączenia z Internetem.') # getting and preparing data timestamp = gettimestamp() data = json.loads(request.body) folderpath = data['folderpath'] fileabout = '' if data['fileabout'] == "<brak>" else os.path.join(data['insidepath'], data['fileabout']) fullthreadpath = os.path.join(folderpath, '.Comments', data['insidepath'][1:], timestamp + fileseparator + config['uid']) response = { 'timestamp': timestamp, 'name': data['topic'], 'type': 'thread', 'numberofcomments': 1, 'unreadcomment': False, 'lastcomment': timestamp, 'fullpath': fullthreadpath, 'insidepath': fullthreadpath.replace(folderpath + '/.Comments', ''), } meta = { 'uid': config['uid'], 'timestamp': timestamp, 'topic': data['topic'], 'fileabout': fileabout } comment = { 'uid': config['uid'], 'timestamp': timestamp, 'comment': data['comment'], 'readby': {}, 'history': [] } comment['readby'][config['uid']] = timestamp comment['history'].append({'timestamp': timestamp, 'comment': comment['comment']}) if os.path.isdir(fullthreadpath): return HttpResponseServerError('Podany wątek już istnieje.') os.makedirs(fullthreadpath) saveJSON(os.path.join(fullthreadpath, 'meta'), meta) saveJSON(os.path.join(fullthreadpath, timestamp + fileseparator + config['uid']), comment) return JsonResponse(response, safe=False) except: return HttpResponseServerError('Wystąpił nieznany błąd podczas dodawania nowego wątku.')
def editcomment(request): try: if not checkConnection(): return HttpResponseServerError('Brak połączenia z Internetem.') editedcomment = json.loads(request.body)['comment'] threadfullpath = json.loads(request.body)['threadfullpath'] #print json.dumps(editedcomment, indent=4) #print threadfullpath commentpath = os.path.join(threadfullpath, editedcomment['timestamp'] + fileseparator + editedcomment['uid']) comment = loadJSON(commentpath) comment['history'].append({'timestamp': gettimestamp(), 'comment': editedcomment['comment']}) comment['comment'] = editedcomment['comment'] saveJSON(commentpath, comment) return JsonResponse({}, safe=False) except: return HttpResponseServerError('Wystąpił nieznany błąd podczas edycji komentarza.')