def handle(self, *args, **options):
     chunk_size = options.get("chunk")
     bulk_mngr = BulkCreateManager(chunk_size)
     fake = Faker()
     for counter in range(self.NO_OF_SEED_LIBRARY):
         library = Library(name=fake.name() + " Library",
                           updated_at=timezone.now(),
                           archived=False)
         bulk_mngr.add(library)
     bulk_mngr.done()
     library_qs = Library.objects.all()
     print("-- Done creating libraries --")
     for library in library_qs:
         no_of_books_for_library = random.randint(
             self.MIN_NO_OF_BOOKS_PER_LIBRARY,
             self.MAX_NO_OF_BOOKS_PER_LIBRARY)
         print("-- Adding %s books to %s(%s) --" %
               (no_of_books_for_library, library.name, library.id))
         for counter in range(no_of_books_for_library):
             book = Book(title=fake.sentence(),
                         publisher=fake.company(),
                         library=library,
                         updated_at=timezone.now(),
                         archived=False)
             bulk_mngr.add(book)
         bulk_mngr.done()
def save(request):

	library_form = LibraryForm(request.POST or None)

	if library_form.is_valid():

		form_clean = library_form.cleaned_data

		pk = form_clean.get('id', None)

		if not pk:
			library_model = Library(**form_clean)
			library_model.save()
		else:
			library_model = get_object_or_404(Library, pk=pk)

			library_model.title = form_clean.get('title', '')
			library_model.description = form_clean.get('description', '')
			library_model.status = form_clean.get('status', '')
			library_model.friend_name = form_clean.get('friend_name', '')
			library_model.friend_email = form_clean.get('friend_email', '')
			
			library_model.save()

		return HttpResponseRedirect(reverse('index'))

	book_list = Library.objects.all()

	return render(request, 'library/library.html', {'book_list': book_list, 'library_form': library_form})
Exemplo n.º 3
0
def create_library(name,
                   status=0,
                   save=True,
                   read_length=None,
                   index_type=None):
    organism = Organism(name='Organism')
    organism.save()

    concentration_method = ConcentrationMethod(name='Concentration Method')
    concentration_method.save()

    if read_length is None:
        read_length = ReadLength(name='Read Length')
        read_length.save()

    library_protocol = LibraryProtocol(
        name='Protocol',
        type='DNA',
        provider='-',
        catalog='-',
        explanation='-',
        input_requirements='-',
        typical_application='-',
    )
    library_protocol.save()

    library_type = LibraryType(name='Library Type')
    library_type.save()
    library_type.library_protocol.add(library_protocol)

    if index_type is None:
        index_type = IndexType(name='Index Type')
        index_type.save()

    library = Library(
        name=name,
        status=status,
        organism_id=organism.pk,
        concentration=1.0,
        concentration_method_id=concentration_method.pk,
        read_length_id=read_length.pk,
        sequencing_depth=1,
        library_protocol_id=library_protocol.pk,
        library_type_id=library_type.pk,
        amplification_cycles=1,
        index_type_id=index_type.pk,
        index_reads=0,
        mean_fragment_size=1,
    )

    if save:
        library.save()

    return library
Exemplo n.º 4
0
    def post(self, request):
        user = User.objects.get(id=request.POST.get('user'))
        library = Library()

        library.title = request.POST.get('title')

        library.save()

        library.user.add(user)

        return redirect("library:libraries")