Example #1
0
class MusicBaseTest(BaseTest):
    def setUp(self):
        super().setUp()

        self.genre = Genre(description='test', genre_image=self._get_image())

        self.band = Band(name='test',
                         genre=self.genre,
                         band_image=self._get_image())

        self.album = Album(name='test',
                           band=self.band,
                           release_date=2020,
                           cover_image=self._get_image())

        self.genre.save()
        self.band.save()
        self.album.save()

    def tearDown(self):
        self.genre.delete()
        self.band.delete()

        super().tearDown()

    def get_new_music(self):
        music = Music(name='Test',
                      album=self.album,
                      order=1,
                      file=self._get_mp3())

        music.save()
        return music
Example #2
0
    def test_gera_codigo_gravadora(self):
        album = AlbumModel()

        # Metodo que sincroniza nao nos interessa nesse teste, entao será mockado para nao retornar nada
        album.sincroniza = MagicMock(return_value=None)

        codigo = album.gera_codigo_gravadora_e_sincroniza(album_id=1, artista_id=5)

        self.assertEqual('15', codigo)
Example #3
0
def create_album(request):
    if request.method == "POST":
        user = request.user
        if user.is_authenticated():
            name = request.POST["album_name_create"]
            description = request.POST["album_description_create"]
            album = Album(owner=user, name=name, description=description, firstpage=0)
            album.save()
            return redirect("view_album", album_id=album.id)
    else:
        return redirect("/")
Example #4
0
def create_album(request):
    if request.method == 'POST':
        user = request.user
        if user.is_authenticated():
            name = request.POST['album_name_create']
            description = request.POST['album_description_create']
            album = Album(owner=user,
                          name=name,
                          description=description,
                          firstpage=0)
            album.save()
            return redirect('view_album', album_id=album.id)
    else:
        return redirect('/')
Example #5
0
    def setUp(self):
        super().setUp()

        self.genre = Genre(description='test', genre_image=self._get_image())

        self.band = Band(name='test',
                         genre=self.genre,
                         band_image=self._get_image())

        self.album = Album(name='test',
                           band=self.band,
                           release_date=2020,
                           cover_image=self._get_image())

        self.genre.save()
        self.band.save()
        self.album.save()
Example #6
0
def index(request):
    user=request.user
    q=Album.objects.filter(user__exact=user)
    album=None
    if q:
        album=q[0]
    else: #create a album
        album=Album()
        album.name=u'$'+user.username
        album.user=user
        album.save()
    
    items=Document.objects.filter(album__exact=album)

    c=RequestContext(request,{'user':user,'items':items,'album':album,'static':settings.STATIC_ROOT})
    c.update(csrf(request))
    tt = loader.get_template('index.html')
    return HttpResponse(tt.render(c))
Example #7
0
def handle_upload(request):
    """
    All uploads are handled by this view. It takes the file, saves it to the
    local filesystem, then adds the S3 upload to the upload queue.
    """
    
    f = request.FILES['file']
    meta = request.POST.get('meta', None)
    album = request.POST.get('album', None)
    artist = request.POST.get('artist', None)
    date = request.POST.get('date', None)
    profile = request.POST.get('profile', None)
    
    album_obj = Album(artist=artist, profile=profile, date=date,
                      album=album, meta=meta, size=(f.size/1073741824.0))
    album_obj.save()
    
    save_location = os.path.join(settings.UPLOAD_PATH, album_obj.filename)
    destination = open(save_location, 'wb+')
    
    for chunk in f.chunks():
        destination.write(chunk)
    destination.close()
    
    if not zipfile.is_zipfile(save_location):
        album_obj.delete()
        raise RuntimeError('Not valid zip file')
    
    ua = request.META['HTTP_USER_AGENT']
    
    if not ua.startswith("The Project Command Line Client") and \
    not ua.startswith("The Project GUI Client"):
        print ua
        raise Http404
    
    if not request.POST.get('password', None) == settings.CLIENT_PASS:
        print request.POST.get('password', None)
        raise Http404
        
    upload_to_remote_storage.delay(album_obj.pk, destination.name)
    
    return HttpResponse('%s bytes recieved from client!!!' % f.size,
                        mimetype='text/plain')
Example #8
0
    def delete(self, request, pk):
        album = AlbumModel.get_album_por_id(pk=pk)

        if not album:
            raise RegistroNaoEncontradoException("Álbum não encontrado")

        album.delete()

        return Response({'message': 'Álbum removido com sucesso'},
                        content_type='application/json')
Example #9
0
    def _add_to_place_album(self):
        """
        将照片自动放入对应的地点相册,国内按市分组,国外按国家分组
        """
        if self.addr_text is not None:
            if self.addr_country == "中国":
                album_addr_key = self.addr_city
                addr_level = 3
            else:
                album_addr_key = self.addr_country
                addr_level = 1

            from album.models import Album

            place_albums = Album.objects.filter(type="A",
                                                addr_name=album_addr_key)
            if len(place_albums) == 0:
                album = Album(title=album_addr_key,
                              auto=True,
                              type="A",
                              addr_name=album_addr_key,
                              addr_level=addr_level)
                album.save()
            else:
                album = place_albums[0]
            album.photos.add(self)
            album.save()
Example #10
0
    def post(self, request, *args, **kwargs):
        form_class = self.get_form_class()
        form = self.get_form(form_class)

        album = Album()
        if form.is_valid():
            album.artist_name = form.cleaned_data['artist_name']
            album.album_name = form.cleaned_data['album_name']
            album.released_date = form.cleaned_data['released_date']
            album.length = form.cleaned_data['length']
            album.added_by = request.user
            album.save()
            for item in form.cleaned_data['genre']:
                album.genre.add(item)

            return HttpResponseRedirect(self.get_success_url())

        else:
            return render(request, self.template_name, {'form': form})
Example #11
0
    def getpid(key):
        userid = '113073984862808105932'
        try:
            print('key', key)

            emo = Photo.objects(Q(userId=userid) & Q(tag__emotion_tag=key))
            print('emotion:', emo)
            addpid(emo, key)

            main = Photo.objects(Q(userId=userid) & Q(tag__main_tag=key))
            print('main:', main)
            addpid(main, key)

            top3 = Photo.objects(Q(userId=userid) & Q(tag__top3_tag__tag=key))
            print('top3:', top3)
            addpid(top3, key)

            alltag = Photo.objects(Q(userId=userid) & Q(tag__all_tag__tag=key))
            print('alltag:', alltag)
            addpid(alltag, key)

            custom = Photo.objects(
                Q(userId=userid) & Q(tag__custom_tag__is_deleted=False)
                & Q(tag__custom_tag__tag=key))
            print('custom:', custom)
            addpid(custom, key)

            location = Photo.objects(Q(userId=userid) & Q(location=key))
            print('location:', location)
            addpid(location, key)

            album = Album.objects(
                Q(userId=userid) & Q(albumTag__isDeleted=False)
                & Q(albumTag__tag=key))
            # print('album:',album)
            for i in album:
                photos = i.albumPhoto
                # print('photos:',photos)
                for j in photos:
                    atag = []
                    isdeleted = j.isDeleted
                    if isdeleted is False:
                        pid.append(j.photoId)
                        atag.append(key)
                        atemptag = atag
                        pid_tag.append({"pid": j.photoId, "tag": atemptag})
                        print('pid_tag', pid_tag)

        except Exception as e:
            print(e)
Example #12
0
    def post(self, request):
        data = request.data

        self.valida_preenchimento(data)

        artista_id = data.get('artista')
        self.valida_artista(artista_id)

        album = AlbumModel()
        album.nome = data.get('nome')
        album.artista_id = data.get('artista')
        album.ano_lancamento = data.get('ano_lancamento')
        album.faixas = data.get('faixas')
        album.save()

        serializer = AlbumSerializer(album)

        return Response(serializer.data)
    try:
        response = urllib2.urlopen('http://lyrics.wikia.com/api.php?artist='+ band_name + '&fmt=json')
        #print 'http://lyrics.wikia.com/api.php?artist='+ band_name + '&fmt=json'
        data = json.load(response)
    except:
        
        print "errot to load " + band_name
        break

    for d in data['albums']:
        name = d['album']
        year = d['year']

        if name and year:
            album = Album()
            album.name = name
            album.album_date = year + '-01-01'
            album.create_date = datetime.now()
            album.slug = slugify(name)
            album.band = band
            album.user = user
            album.save()
            sys.stdout.write(name + " - " + year + "\n")
            sys.stdout.flush()
            i = 1

            for music in d['songs']:
                m_name = music
                music = Music()
                music.name = m_name