def create_release(payload): try: name = request.get_json()['name'] artist_id = request.get_json()['artist_id'] price = request.get_json()['price'] new_release = Release( name=name, artist_id=artist_id, price=price ) new_release.insert() return jsonify({ 'success': True, 'name': new_release.name, 'artist_id': new_release.artist_id, 'price': new_release.price }) except: abort(422)
def create_or_update_numu_release(mb_release): """Parse an MB release and turn it into a release object. Returns (unsaved) release object.""" numu_date = get_numu_date(mb_release.get('first-release-date')) if numu_date is None or mb_release.get('artist-credit') is None: return None release = get_numu_release(mb_release.get('id')) if release is None: release = Release() release.mbid = mb_release.get('id') release.title = mb_release.get('title') release.type = get_numu_type(mb_release) release.date_release = numu_date release.artists_string = mb_release.get('artist-credit-phrase') release.date_updated = func.now() db.session.add(release) db.session.commit() for mb_artist in mb_release.get('artist-credit'): if type(mb_artist) == dict and mb_artist['artist']: artist = get_numu_artist_by_mbid(mb_artist['artist']['id']) if artist is None: artist = add_numu_artist_from_mb( artist_mbid=mb_artist['artist']['id']) if artist and artist not in release.artists: release.artists.append(artist) db.session.add(release) db.session.commit() return release
def record_artists_and_releases(): """Create skeleton records in artists and releases tables from given directory. Assume that directory structure is artist/albums/tracks a la itunes library. """ total_artists = 0 total_releases = 0 session = Session() artists = [] for artist_dir in glob.glob(DIRECTORY + '*'): artist = Artist(name=os.path.basename(artist_dir)) total_artists += 1 for release_dir in glob.glob(artist_dir + '/*'): release = Release(title=os.path.basename(release_dir)) artist.releases.append(release) total_releases += 1 artists.append(artist) logger.info('Adding {} artists with {} releases'.format( total_artists, total_releases)) session.add_all(artists) session.commit()
def rawPost(self, ballotID, voteID): vote = self.getVote(ballotID, voteID) id = self.request.get('release.id', default_value=None) mbid = self.request.get('release.mbid', default_value=None) if id: vote.release = db.Key.from_path(Release.kind(), int(id)) elif mbid: vote.release = Release.get(mbid) else: id = self.request.get('artist.id', default_value=None) mbid = self.request.get('artist.mbid', default_value=None) if id: artist = db.Key.from_path(Artist.kind(), int(id)) elif mbid: artist = Artist.get(mbid) else: artist = Artist(name=self.request.get('artist'), sortname=self.request.get('sortname')) artisturl = self.request.get('artisturl', default_value=None) if artisturl: artist.url = artisturl artist.put() release = Release(artist=artist, title=self.request.get('title')) releaseurl = self.request.get('releaseurl', default_value=None) if releaseurl: release.url = releaseurl release.put() vote.release = release vote.put() next = Vote.gql('WHERE release = :1 ORDER BY artist', None).get() if next: key = next.key() self.redirect('../%d/%d' % (key.parent().id(), key.id())) else: self.redirect('../..')
def post(self, year, id): release = Release.get_by_id(int(id)) if not release: self.response.out.write('No such release: ' + id) return rr = RankedRelease.gql('WHERE year = :1 AND release = :2', int(year), release).get() if not rr: self.response.out.write('No such ranked release: ' + year + '/' + id) return rr.cache() self.response.out.write('Cached.')
def release(): if request.method == 'GET': return render_template('release.html') else: title = request.form.get('title') content = request.form.get('content') Release(title=title, content=content) user_id = session.get('user_id') user = User.query.filter(User.id == user_id).first() release.author = user db.session(release) db.session.commit() return redirect(url_for('index'))
def rawGet(self, ballotID, voteID): vote = self.getVote(ballotID, voteID) if not vote: self.response.out.write('No such vote: ' + ballotID + '/' + voteID) return render = dict(v=vote) title = self.request.get('title', default_value=vote.title) render['title'] = title mbArtistid = self.request.get('artist.mbid', default_value=None) artistid = self.request.get('artist.id', default_value=None) name = self.request.get('name', default_value=vote.artist) artist = None if artistid: artist = Artist.get_by_id(int(artistid)) elif mbArtistid: artist = Artist.gql('WHERE mbid = :1', mbArtistid).get() if artist: if artist.mbid: mbArtistid = artist.mbid name = artist.name render['artist'] = artist render['releases'] = [r for r in artist.release_set if not vote.release or r.key() != vote.release.key()] else: if mbArtistid: artist = mb.Artist(mbArtistid) render['mbArtist'] = artist render['artists'] = [a for a in Artist.gql('WHERE name = :1', name)] render['releases'] = [r for r in Release.gql('WHERE title = :1', title) if not vote.release or r.key() != vote.release.key()] render['name'] = name search = dict(title=title) if mbArtistid: search['artistid'] = mbArtistid else: search['artist'] = name rgs = mb.ReleaseGroup.search(**search) if rgs: render['rgs'] = rgs elif mbArtistid: render['rgs'] = mb.ReleaseGroup.search(artistid=mbArtistid) else: render['mbArtists'] = mb.Artist.search(name=name) self.render('canon.html', **render)
def create_or_edit_release(request, project_slug, release_slug=None): project = get_object_or_404(Project, slug=project_slug) if release_slug: action = "Edit release" release = get_object_or_404(Release, project=project, slug=release_slug) if not project.get_perms(request.user).get("has_member_perm", False): request.user.message_set.create(message=NEED_MEMBER_PERM) return HttpResponseRedirect(release.version.get_absolute_url()) form_class = forms.ReleaseEditForm else: action = "Release a new version" release = Release(project=project, creator=request.user) form_class = forms.ReleaseCreationForm if request.method == 'POST': form = form_class(data=request.POST, files=request.FILES, instance=release) if form.is_valid(): release = form.save(commit=False) # if not release_slug: # release.creator = request.user release.last_editor = request.user # release.project = project if "submit" in request.POST: release.save() if hasattr(form, 'save_m2m'): form.save_m2m() return HttpResponseRedirect(reverse('view_release', args=[project.slug, release.slug])) else: release.render_markup() preview = True else: form = form_class(instance=release) return render_to_response('projects/create_or_edit_release.html', locals(), context_instance=RequestContext(request))
def release(questionnaire_id): def get_security(): def to_int(string): try: return int(string) except ValueError: return None security = {} if 'is_allow_anonymous' not in request.form: is_allow_anonymous = False else: is_allow_anonymous = True if 'limit_num_participants' not in request.form: limit_num_participants = None elif not request.form['limit_num_participants']: limit_num_participants = None else: limit_num_participants = to_int( request.form['limit_num_participants']) if 'limit_num_ip' not in request.form: limit_num_ip = None elif not request.form['limit_num_ip']: limit_num_ip = None else: limit_num_ip = to_int(request.form['limit_num_ip']) if 'special_participants' not in request.form: special_participants = None else: data = request.form['special_participants'] if not data: special_participants = None else: special_participants = data.split(',') for i in special_participants: i = i.strip() security['anonymous'] = is_allow_anonymous security['limit_per_user'] = limit_num_participants security['limit_per_ip'] = limit_num_ip security['limit_participants'] = special_participants return security if request.method == 'POST': start_time = request.form['start_time'] end_time = request.form['end_time'] if start_time < end_time: security = get_security() dumped_security = pickle.dumps(security, protocol=2) release = Release( ques_id=questionnaire_id, start_time=datetime.strptime(start_time, '%Y-%m-%d %H:%M:%S'), end_time=datetime.strptime(end_time, '%Y-%m-%d %H:%M:%S'), security=dumped_security, is_closed=False) db.session.add(release) db.session.commit() return render_template('release_success.html', g=g, q_id=questionnaire_id, message='Release successfully') else: flash("Start time is later then end time", 'error') return render_template('release.html')
def populate(): session = DBSession() root = Root(name=u'PyPI') session.add(root) client = xmlrpclib.ServerProxy('http://pypi.python.org/pypi') packages = client.list_packages() # Do it in parallel to go faster results = pool.map(ingest_package, packages) for i, result in enumerate(results): package = result['name'] print "Populating DB with:", i, package # Query for it first... if Package.query.filter_by(name=package).count() > 0: print "Package '%s' is already in the DB. Skipping." % package continue p = Package(name=package, root=root) session.add(p) for release_data in result['releases']: release = release_data['name'] data = release_data['data'] r = Release( name=release, package=p, summary=data.get('summary', '') ) for classifier in data['classifiers']: query = Classifier.query.filter_by(name=classifier) if query.count() == 0: k = Classifier(name=classifier) session.add(k) k = Classifier.query.filter_by(name=classifier).one() r.classifiers.append(k) for keyword in (data['keywords'] or '').split(): query = Keyword.query.filter_by(name=keyword) if query.count() == 0: k = Keyword(name=keyword) session.add(k) k = Keyword.query.filter_by(name=keyword).one() r.keywords.append(k) if 'maintainer' in data: query = Maintainer.query.filter_by(name=data['maintainer']) if query.count() == 0: a = Maintainer(name=data['maintainer'], email=data.get('maintainer_email')) session.add(a) a = Maintainer.query.filter_by(name=data['maintainer']).one() r.maintainer = a if 'author' in data: query = Author.query.filter_by(name=data['author']) if query.count() == 0: a = Author(name=data['author'], email=data.get('author_email')) session.add(a) a = Author.query.filter_by(name=data['author']).one() r.author = a if 'license' in data: query = License.query.filter_by(name=data['license']) if query.count() == 0: l = License(name=data['license']) session.add(l) l = License.query.filter_by(name=data['license']).one() r.license = l session.add(r) session.commit()