def add_concept(self, request, pk=None): group = get_object_or_404(Group, pk=pk) self.check_object_permissions(request, group.course) serializer = ConceptSerializer(data=request.DATA) if serializer.is_valid(): document = Document( title='dummy', description='dummy' ) document.save() concept = Concept( group=group, title_document=document, title=serializer.data['title'], description=serializer.data['description'] ) if request.FILES != {}: concept.image = request.FILES['image'] concept.save() group.playlist = playlist.append(concept.id, group.playlist) group.save() return Response(ConceptSerializer(concept).data) else: content = serializer.errors return Response(content, status.HTTP_400_BAD_REQUEST)
def create_revision( owner, template, title, content, bibliography, images, comments, submission_id, revision_version, ): revision = Document() revision.owner = owner revision.template = template revision.title = title revision.content = content revision.bibliography = bibliography revision.path = f"/Submission {submission_id}/{title.replace('/', '')} ({revision_version})" revision.comments = comments revision.save() for image in images: if image is None: image = Image() image.uploader = owner f = open( path.join(settings.PROJECT_PATH, "base/static/img/error.png") ) image.image.save("error.png", File(f)) image.save() DocumentImage.objects.create(document=revision, image=image, title="") return revision
def save(self, commit=True): savedoc = Document() savedoc.name = self.data.get("name") savedoc.description = self.data.get("description") savedoc.user = self.user savedoc.save() return savedoc
def create_target_document(self): target = Document() target.id = 2 target.content = '<document>' \ '<header><name>name</name><place>place</place></header>' \ '<section id="chapter_1" level="chapter" name="name" number="1">' \ '<article id="article_1" level="article" name="name" number="1">test</article>' \ '<article id="article_2" level="article" name="name" number="2">test</article>' \ '</section>' \ '</document>' target.uploaded_date = datetime.now() target.save() return target
def create_source_document(self): source = Document() source.id = 1 source.content = '<document>' \ '<header><name>name</name><place>place</place></header>' \ '<section id="chapter_1" level="chapter" name="name" number="1">' \ '<article id="article_1" level="article" name="name" number="1">test</article>' \ '<article id="article_2" level="article" name="name" number="2">test</article>' \ '</section>' \ '</document>' source.uploaded_date = datetime.now() source.save() return source
def add_document(self, request, pk=None): concept = get_object_or_404(Concept, pk=pk) self.check_object_permissions(request, concept.group.course) serializer = DocumentSerializer(data=request.DATA) if serializer.is_valid(): document = Document(title=serializer.data['title'], description=serializer.data['description']) document.save() concept.playlist = typed_playlist.append(document.id, concept.playlist, 2) concept.pages.add(document) concept.save() return Response(document.to_dict()) else: content = serializer.errors return Response(content, status.HTTP_400_BAD_REQUEST)
def add_document(self, request, pk=None): concept = get_object_or_404(Concept, pk=pk) self.check_object_permissions(request, concept.group.course) serializer = DocumentSerializer(data=request.DATA) if serializer.is_valid(): document = Document( title=serializer.data['title'], description=serializer.data['description'] ) document.save() concept.playlist = typed_playlist.append(document.id, concept.playlist, 2) concept.pages.add(document) concept.save() return Response(document.to_dict()) else: content = serializer.errors return Response(content, status.HTTP_400_BAD_REQUEST)
def add_page(self, request, pk=None): _course = get_object_or_404(Course, pk=pk) self.check_object_permissions(request, _course) serializer = DocumentSerializer(data=request.DATA) if serializer.is_valid(): document = Document(title=serializer.data['title'], is_heading=True, description=serializer.data['description']) document.save() _course.pages.add(document) _course.page_playlist = playlist.append(document.id, _course.page_playlist) _course.save() return Response(DocumentSerializer(document).data) else: content = serializer.errors return Response(content, status.HTTP_400_BAD_REQUEST)
def create_new_document(self, repository_url, jdata = {}): d = Document() dups = self.agent_get_existing(self.AGENT_NAME, self.AGENT_VERSION, repository_url) if dups: return None # to do - Handle IN-PROGRESS dups that are now explicitely not included in agent_get_existing() # d.agent_state = STATE_DUP # d.agent_dup = dups[0] # logger.info("Duplicate found %s - %s" % (thesis_url, dups[0])) # d.save() # continue d.agent_name = self.AGENT_NAME d.agent_version = self.AGENT_VERSION d.agent_repository_url = repository_url d.agent_date = timezone.now() d.status = STATE_WAITING # d.agent_json_data = json.dumps(jdata) d.save() return d
def add_page(self, request, pk=None): _course = get_object_or_404(Course, pk=pk) self.check_object_permissions(request, _course) serializer = DocumentSerializer(data=request.DATA) if serializer.is_valid(): document = Document( title=serializer.data['title'], is_heading=True, description=serializer.data['description'] ) document.save() _course.pages.add(document) _course.page_playlist = playlist.append( document.id, _course.page_playlist) _course.save() return Response(DocumentSerializer(document).data) else: content = serializer.errors return Response(content, status.HTTP_400_BAD_REQUEST)
def add_concept(self, request, pk=None): group = get_object_or_404(Group, pk=pk) self.check_object_permissions(request, group.course) serializer = ConceptSerializer(data=request.DATA) if serializer.is_valid(): document = Document(title='dummy', description='dummy') document.save() concept = Concept(group=group, title_document=document, title=serializer.data['title'], description=serializer.data['description']) if request.FILES != {}: concept.image = request.FILES['image'] concept.save() group.playlist = playlist.append(concept.id, group.playlist) group.save() return Response(ConceptSerializer(concept).data) else: content = serializer.errors return Response(content, status.HTTP_400_BAD_REQUEST)
def __insert_document(cls, doc: Document) -> None: """ Purpose: during plugin tests we experienced Integrity errors at the end of tests. This exception occurs while handling another exception, so in order to have a clean tests output we raise the exception in a way we don't output misleading error messages related to different exceptions :param doc: socket document model instance :return: None """ from django.db.utils import IntegrityError try: doc.save() except IntegrityError as e: raise IntegrityError( 'plugin test error when we try to save a doc already deleted ' 'along with the rest of db data so it ' 'raises an Integrity error: {}'.format(e)) from None
def post(self, request, key): #create document doc = Document(owner=self.request.user, last_update_user=self.request.user) doc.save() #create document attachment fs = get_object_or_404(FileStorage, key=key) attach = DocumentAttach(document=doc, file=fs) attach.save() #save to rebuild index doc.save() #send signal signals.post_attach_file.send(sender=self.__class__, file=fs, document=doc, user=self.request.user) return self.render_to_response({ "document_id": doc.id, "filestorage_id": attach.id })
def save_week_document_import(request): if request.method == "POST": # try: year_name = request.POST.get("year") student_year_name = request.POST.get("student_year") subject_name = request.POST.get("subject") weeks = request.POST.getlist("week") # except: # pass for w in weeks: day_types = request.POST.getlist("day_type" + str(w)) day_numbers = request.POST.getlist("day_number" + str(w)) day_contents = request.POST.getlist("day_content" + str(w)) day_notes = request.POST.getlist("day_note" + str(w)) week_require = request.POST.get("week_require" + str(w)) # Find document subject_student_year = SubjectStudentYear.objects.get(subject__name=subject_name, student_year__name=student_year_name, year__name=year_name) try: document = Document.objects.get(subject=subject_student_year) except Document.DoesNotExist: document = Document() document.subject = subject_student_year document.save() # Find Week try: week_obj = Week.objects.get(document=document, number=w) except Week.DoesNotExist: print "Week does not exist" week_obj = Week() week_obj.number = w week_obj.document = document week_obj.require = week_require week_obj.save() for i in range(len(day_numbers)): if day_types[i] == u'None': day_type = None elif day_types[i] == u'True': day_type = True else: day_type = False day_content = day_contents[i] day_number = day_numbers[i] day_note = day_notes[i] try: day = Day.objects.get(week=week_obj, number=day_number, type=day_type) except Day.DoesNotExist: print "Day does not exist" day = Day() day.content = day_content day.number = day_number day.note = day_note day.type = day_type day.week = week_obj day.save() return HttpResponseRedirect("/import/week/document/") else: return HttpResponseRedirect("/import/week/document/") return HttpResponse("Saved") # End Import week document
def create_document(file_id=None, text=None, user=None): data = dict(processed_text=text, file_id=file_id, author=user) document = Document(**data) document.save()
def author_first_submit(self): # The document is not part of an existing submission. journal_id = self.get_argument('journal_id') self.submission = Submission() self.submission.submitter = self.user self.submission.journal_id = journal_id self.submission.save() self.revision = SubmissionRevision() self.revision.submission = self.submission self.revision.version = "1.0.0" version = "1.0.0" # Connect a new document to the submission. title = self.get_argument('title') abstract = self.get_argument('abstract') contents = self.get_argument('contents') bibliography = self.get_argument('bibliography') image_ids = list( filter(None, self.get_argument('image_ids').split(','))) document = Document() journal = Journal.objects.get(id=journal_id) document.owner = journal.editor document.title = title document.contents = contents document.bibliography = bibliography document.save() for id in image_ids: image = Image.objects.filter(id=id).first() if image is None: image = Image() image.pk = id image.uploader = journal.editor f = open( os.path.join(settings.PROJECT_PATH, "base/static/img/error.png")) image.image.save('error.png', File(f)) image.save() DocumentImage.objects.create(document=document, image=image, title='') self.revision.document = document self.revision.save() fidus_url = '{protocol}://{host}'.format( protocol=self.request.protocol, host=self.request.host) post_data = { 'username': self.user.username.encode('utf8'), 'title': title.encode('utf8'), 'abstract': abstract.encode('utf8'), 'first_name': self.get_argument('firstname').encode('utf8'), 'last_name': self.get_argument('lastname').encode('utf8'), 'email': self.user.email.encode('utf8'), 'affiliation': self.get_argument('affiliation').encode('utf8'), 'author_url': self.get_argument('author_url').encode('utf8'), 'journal_id': journal.ojs_jid, 'fidus_url': fidus_url, 'fidus_id': self.submission.id, 'version': version } body = urlencode(post_data) key = journal.ojs_key base_url = journal.ojs_url url = base_url + self.plugin_path + 'authorSubmit' http = AsyncHTTPClient() http.fetch(HTTPRequest(url_concat(url, {'key': key}), 'POST', None, body), callback=self.on_author_first_submit_response)
elif "journal" in doc: publisher = doc['journal'] # print publisher else: publisher = None if publisher: try: publisher = Publisher.objects.get(name=publisher) except: publisher = Publisher(name=publisher) publisher.save() document.publisher = publisher else: document.publisher = None if "link" in doc: link = doc['link'] # print link document.link = link document.save() for author in authors: document.authors.add(author) for field in fields: document.fields.add(field) document.projects.add(pro) document.save() # exit() # document = Document(title=title, url=url, description=description, publish_time=publish_time) # document.save()