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 #2
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 #3
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 #4
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 #5
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
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})