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()
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
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("/")
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('/')
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))
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)
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')
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})
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 music.slug = slugify(m_name) music.number = str(i) music.user = user music.date = datetime.now() music.album = Album.objects.latest('id') music.save() sys.stdout.write(str(i) + " - " + m_name + "\n")