def create_annotation(request): """ POST to create_annotation creates a text. Does not actually create an Annotation record Redirects to an annotation_editing_view. """ #takes a post if request.method != 'POST': return redirect('/') c = RequestContext(request) user_id = request.user.id url = request.POST.get('url') text = request.POST.get('text') if url: text_info = Text.get_or_create_text_by_url(url) text_id = text_info.get('_id') elif text: c['text'] = text text_id = Text.add_text({'text':text}) else: return redirect('/') return redirect('/edit/%s' % text_id)
def render_annotation(request, username, text_id): annotation_user = Profile.objects.get(username=username) text_info = Text.find_by_id(text_id) c = RequestContext(request) c['annotation_username'] = annotation_user.username c['annotation_user_id'] = annotation_user.id c['text_id'] = text_id c['text'] = text_info.get('text') annotation = Annotation.find_by_user_id_and_text_id(annotation_user.id, text_id) comments = [] if annotation: comments = annotation.get('comments') c['initial_comments'] = simplejson.dumps(comments) return render_to_response('annotation.html', c)
def edit_annotation(request, text_id): c = RequestContext(request) if text_id is not None and request.user.is_authenticated(): text_info = Text.find_by_id(text_id) else: return redirect('/') c['user'] = request.user c['annotation_username'] = request.user.username c['annotation_user_id'] = request.user.id c['text_id'] = text_id c['text'] = text_info.get('text') c['text_title'] = text_info.get('title') c['edit_mode'] = True annotation = Annotation.find_by_user_id_and_text_id(request.user.id, text_id) comments = [] if annotation: comments = annotation.get('comments') c['initial_comments'] = simplejson.dumps(comments) return render_to_response('annotation.html', c)
def actionCalled(self): """ Dodaje child node """ parent = QApplication.instance().selectionModel if isinstance(parent, Book): newName, ok = QInputDialog.getText(None, "New Chapter name", "Enter desired new name") if ok: if parent.isValidName(newName): parent.addChild(Chapter(newName)) else: while not parent.isValidName(newName): dialog = QMessageBox() dialog.setWindowTitle("Error") dialog.setText("That name is not valid") dialog.setWindowIcon(QIcon("src/notification.png")) dialog.setModal(True) dialog.exec_() newName, cancel = QInputDialog.getText( None, "New Chapter name", "Enter desired new name") if not cancel: break else: if parent.isValidName(newName): parent.addChild(Chapter(newName)) break if isinstance(parent, Chapter): if len(parent.getChildren()) > 0: parent.addChild( Page(parent.getChildren()[-1].getName()[:-1] + str(int(parent.getChildren()[-1].getName()[-1:]) + 1))) else: parent.addChild(Page("Strana1")) if isinstance(parent, Page): item, ok = QInputDialog.getItem(QInputDialog(), "Add an element", "Choose one option:", ["Add text", "Add picture"], 0, False) if ok: if item == "Add text": tmpList = [] for child in parent.getChildren(): if isinstance(child, Text): tmpList.append(child) if len(tmpList) > 0: parent.addChild( Text(tmpList[-1].getName()[:-1] + str(int(tmpList[-1].getName()[-1:]) + 1))) else: parent.addChild(Text("Text1")) if item == "Add picture": image = QFileDialog.getOpenFileName(None, 'OpenFile', '') if image[1]: path = image[0] if path != None: tmpPic = Picture(path.split("/")[-1]) tmpPic.setPicture(path) parent.addChild(tmpPic)