Beispiel #1
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
Beispiel #2
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")
Beispiel #3
0
def pandora_import(request):
    '''Handles post request of pandora username for artists import from
    pandora.

    '''
    form = forms.PandoraUsernameForm(request.POST)
    if form.is_valid():
        username = form.cleaned_data.get('username')
        library = Library(name=username)
        library.save()
        tasks.import_pandora_artists.delay(library.id, username)
        library_id = utils.encrypt_id(library.pk)
        return redirect('library_success', library_id)
    else:
        form = forms.PandoraUsernameForm()
        return direct_to_template(request, 'library/upload.html', locals())
Beispiel #4
0
 def post_form_data(self, request):
     '''
     Accepts an 'application/x-www-form-urlencoded' post request with 
     key-value pairs of artist=album and a name=name of library pair
     
     '''
     logger.debug('form posted')
     data = request.POST
     if 'name' in data:
         library_name = data['name']
         library = Library(name=library_name)
     else:
         library = Library()
     library.save()
     tasks.import_form_data.delay(library.pk, data)
     return library.pk
 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()
Beispiel #6
0
 def post_library(self, request):
     form = forms.UploadFileForm(request.POST, request.FILES)
     if form.is_valid():
         library_name = form.cleaned_data.get('name', None)
         if library_name == None:
             library = Library()
         else:
             library = Library(name=library_name)
         library.save()
         
         library_filename = self._save_library_file(request.FILES['file'])
         
         tasks.import_itunes_file.delay(library.id, library_filename)
         
         return library, None
     return None, form
Beispiel #7
0
def lastfm_import(request):
    '''Handles post request of last.fm username for artists import from
    last.fm.

    '''
    if request.method == 'POST':
        form = forms.LastfmUsernameForm(request.POST)
        if form.is_valid():
            user = form.user
            library = Library(name=user.name)
            library.save()
            tasks.import_lastfm_artists.delay(library.id, user)
            library_id = utils.encrypt_id(library.pk)
            return redirect('library_success', library_id)
    else:
        form = forms.LastfmUsernameForm()
    return direct_to_template(request, 'test_form.html', {'form': form})
Beispiel #8
0
    def setUp(self):
        user = User.objects.create_user(email='*****@*****.**', password='******')
        pool = Pool(name='_Foo', user=user)
        pool.save()

        library = Library.get_test_library('Library')
        library.save()
        pool.libraries.add(library)
Beispiel #9
0
    def setUp(self):
        user = User.objects.create_user(email='*****@*****.**', password='******')
        pool = Pool(name='_Foo', user=user)
        pool.save()

        library = Library.get_test_library('Library')
        library.save()
        pool.libraries.add(library)
Beispiel #10
0
 def get(self, *args, **kwargs):
     session = self.get_session()
     page_num = self.get_int_argument('page', 0)
     libraries, page_num, page_count = Library.list_by_page(page_num)
     return self.render('library/list.html',
                        session=session,
                        libraries=libraries,
                        page_num=page_num,
                        page_count=page_count)
Beispiel #11
0
 def post(self, *args, **kwargs):
     keyword = self.get_str_argument('keyword', '')
     page_num = self.get_int_argument('page')
     page_num, page_count, libraries = Library.search_text_by_page(
         keyword, page_num)
     return self.render('library/search_text_results.html',
                        libraries=libraries,
                        keyword=keyword,
                        page_num=page_num,
                        page_count=page_count)
Beispiel #12
0
 def post(self, *args, **kwargs):
     search_datas = self.get_json_argument('searchDatas', [])
     page_num = self.get_int_argument('page')
     libraries, page_num, page_count = Library.search_manual_by_page(
         search_datas, page_num)
     return self.render('library/search_manual_results.html',
                        libraries=libraries,
                        search_datas=search_datas,
                        page_num=page_num,
                        page_count=page_count)
Beispiel #13
0
    def setUp(self):
        user = User.objects.create_user(email='*****@*****.**', password='******')
        user.save()

        self.request = Request(user=user)
        self.request.save()

        self.library = Library.get_test_library('Library')
        self.sample = Sample.get_test_sample('Sample')
        self.library.save()
        self.sample.save()
Beispiel #14
0
    def setUp(self):
        user = User.objects.create_user(email='*****@*****.**', password='******')
        user.save()

        self.request = Request(user=user)
        self.request.save()

        self.library = Library.get_test_library('Library')
        self.sample = Sample.get_test_sample('Sample')
        self.library.save()
        self.sample.save()
Beispiel #15
0
 def post(self, *args, **kwargs):
     library_id = self.get_str_argument('id', '')
     title = self.get_str_argument('title', '')
     black_player_name = self.get_str_argument('blackPlayerName', '')
     white_player_name = self.get_str_argument('whitePlayerName', '')
     manual = self.get_json_argument('manual', {})
     library = Library.save_and_index(self.current_user,
                                      id=library_id,
                                      title=title,
                                      blackPlayerName=black_player_name,
                                      whitePlayerName=white_player_name,
                                      manual=manual)
     return self.api_succeed({'id': str(library.id)})
Beispiel #16
0
    def setUp(self):
        user = User.objects.create_user(email='*****@*****.**', password='******')
        pool = Pool(name='_Foo', user=user)
        pool.save()

        library_1 = Library.get_test_library('Library1')
        library_2 = Library.get_test_library('Library2')
        library_1.save()
        library_2.save()

        sample_1 = Sample.get_test_sample('Sample1')
        sample_2 = Sample.get_test_sample('Sample2')
        sample_1.save()
        sample_2.save()

        pool.libraries.add(library_1)
        pool.samples.add(sample_1)

        self.request = Request(user=user)
        self.request.save()
        self.request.libraries.add(*[library_1, library_2])
        self.request.samples.add(*[sample_1, sample_2])
Beispiel #17
0
    def setUp(self):
        user = User.objects.create_user(email='*****@*****.**', password='******')
        pool = Pool(name='_Foo', user=user)
        pool.save()

        library_1 = Library.get_test_library('Library1')
        library_2 = Library.get_test_library('Library2')
        library_1.save()
        library_2.save()

        sample_1 = Sample.get_test_sample('Sample1')
        sample_2 = Sample.get_test_sample('Sample2')
        sample_1.save()
        sample_2.save()

        pool.libraries.add(library_1)
        pool.samples.add(sample_1)

        self.request = Request(user=user)
        self.request.save()
        self.request.libraries.add(*[library_1, library_2])
        self.request.samples.add(*[sample_1, sample_2])
Beispiel #18
0
    def test_get_all_empty(self):
        self.client.login(email='*****@*****.**', password='******')

        library = Library.get_test_library('Library2')
        library.save()

        sample = Sample.get_test_sample('Sample2')
        sample.save()

        self.request.libraries.add(library)
        self.request.samples.add(sample)

        response = self.client.get(reverse('library.get_all'),
                                   {'quality_check': 'true'})
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content, b'[]')
Beispiel #19
0
    def test_get_all_empty(self):
        self.client.login(email='*****@*****.**', password='******')

        library = Library.get_test_library('Library2')
        library.save()

        sample = Sample.get_test_sample('Sample2')
        sample.save()

        self.request.libraries.add(library)
        self.request.samples.add(sample)

        response = self.client.get(reverse('library.get_all'), {
            'quality_check': 'true'
        })
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content, b'[]')
def render_report_tool_box_function(header: str,
                                    xpath: str,
                                    section: str,
                                    libraries: Library,
                                    instruction: Instruction = None,
                                    library_history: LibraryHistory = None):
    split_head = header.split()
    guid = xpath[xpath.find('{') +
                 1:xpath.find('}')]  # get guid in xpath between bracket
    temp_header = []  # temp for concat each splitted head to final_header
    final_header = header
    library_history = library_history if library_history else LibraryHistory.objects.filter(
        instruction=instruction)
    replaced_indexes = set()
    skip_amount_loop = 0
    if libraries:
        libraries = libraries.order_by(Length('key').desc())
        for i, head in enumerate(split_head):
            if skip_amount_loop == 0:
                k = i
                library_matched = False
                highlight_html = '''
                    <span class="highlight-library d-inline-block">
                        <span class="{}">{}</span>
                        <span class="dropdown-options" data-guid="{}" data-word_idx="{}" data-section="{}">
                            <a href="#/" class="highlight-redact">Redact</a>
                            <a href="#/" class="highlight-replace">Replace</a>
                            <a href="#/" class="highlight-replaceall">Replace all</a>
                        </span>
                    </span>
                '''

                for library in libraries:
                    step = len(library.key.split(' '))
                    phrase = " ".join((split_head[k:k + step]))
                    if str.upper(library.key) == str.upper(
                            phrase.replace(
                                ',',
                                '')) and not replaced_indexes.intersection(
                                    set({k, k + step})):
                        trail = ''
                        if phrase[
                                -1] not in string.ascii_letters + string.digits:
                            trail = phrase[-1]
                        replace_word = phrase.replace(',', '')
                        library_matched = True
                        highlight_class = 'bg-warning'

                        if not library.value:
                            highlight_html = '''
                                <span class="highlight-library d-inline-block">
                                    <span class="{}">{}</span>
                                    <span class="dropdown-options" data-guid="{}" data-word_idx="{}" data-section="{}">
                                        <a href="#/" class="highlight-redact">Redact</a>
                                    </span>
                                </span>
                            '''
                        for history in library_history:
                            action = history.action
                            if str.upper(history.old) == str.upper(
                                    phrase.replace(',', '')):
                                if action == LibraryHistory.ACTION_REPLACE \
                                        and history.guid == guid \
                                        and history.index == i \
                                        and history.section == section:
                                    replace_word = history.new
                                    highlight_class = 'text-danger'
                                    break  # already matched HISTORY exist loop
                                elif action == LibraryHistory.ACTION_HIGHLIGHT_REDACT \
                                        and history.guid == guid \
                                        and history.index == i \
                                        and history.section == section:
                                    highlight_class = 'bg-dark text-dark'
                                    break  # already matched HISTORY exist loop
                                elif action == LibraryHistory.ACTION_REPLACE_ALL:
                                    replace_word = history.new
                                    highlight_class = 'text-danger'
                                    break  # already matched HISTORY exist loop

                        replaced_indexes = replaced_indexes.union(
                            set(list(range(k, k + step))))
                        highlight_html = highlight_html.format(
                            highlight_class, replace_word, guid, i, section)
                        temp_header.append(highlight_html + trail)
                        skip_amount_loop = step - 1
                        break  # already matched LIBRARY WORD exist loop
                k += 1

                if not library_matched:
                    temp_header.append(head)
            else:
                skip_amount_loop -= 1

        final_header = format_html(" ".join(temp_header))

    return final_header
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})
Beispiel #22
0
 def setUp(self):
     self.library = Library.get_test_library('Library')
     self.pooling = Pooling(library=self.library)