我们从Python开源项目中,提取了以下14个代码示例,用于说明如何使用werkzeug.datastructures.CombinedMultiDict()。
def configure(): """ The configure page is used to add/remove teams/services. """ if app.config['ALLOW_CONFIG']: forms = {} forms['addTeamForm'] = AddTeamForm(request.form, csrf_enabled=False) choices = [(team['team_id'], team['team_name']) for team in db.execute_db_query('select team_id, team_name from team')] forms['addDNSServiceForm'] = AddDNSServiceForm(request.form, csrf_enabled=False) forms['addWebServiceForm'] = AddWebServiceForm(CombinedMultiDict((request.files, request.form))) forms['addMailServiceForm'] = AddMailServiceForm(request.form, csrf_enabled=False) forms['addWebServiceForm'].team_name.choices = choices forms['addDNSServiceForm'].team_name.choices = choices forms['addMailServiceForm'].team_name.choices = choices return render_template('configure.html', forms=forms, active_page='configure') else: return redirect(url_for('scoreboard'))
def event_detail(event_id): event = Event.query.filter(Event.id == event_id).first() form = PhotoForm(CombinedMultiDict((request.files, request.form))) user_photo = next((p for p in event.photos if p.user_id == current_user.id), None) if not current_user.is_anonymous else None if request.method == 'POST': if user_photo != None: flash('You have already uploaded a photo to this event.') return redirect(url_for('events.event_detail', event_id=event.id)) return event_upload(request, event, form) winner = Photo.query.filter( Photo.id == event.winner_id).first() if event.winner_id else None print(winner) return render_template('event_detail.html', event=event, form=form, photo=user_photo, winner=winner)
def wrap_formdata(self, form, formdata): if formdata is _Auto: if _is_submitted(): if request.files: return CombinedMultiDict(( request.files, request.form )) elif request.form: return request.form elif request.get_json(): return ImmutableMultiDict(request.get_json()) return None return formdata
def test_iterables(self): a = datastructures.MultiDict((("key_a", "value_a"),)) b = datastructures.MultiDict((("key_b", "value_b"),)) ab = datastructures.CombinedMultiDict((a,b)) self.assert_equal(sorted(ab.lists()), [('key_a', ['value_a']), ('key_b', ['value_b'])]) self.assert_equal(sorted(ab.listvalues()), [['value_a'], ['value_b']]) self.assert_equal(sorted(ab.keys()), ["key_a", "key_b"]) self.assert_equal(sorted(iterlists(ab)), [('key_a', ['value_a']), ('key_b', ['value_b'])]) self.assert_equal(sorted(iterlistvalues(ab)), [['value_a'], ['value_b']]) self.assert_equal(sorted(iterkeys(ab)), ["key_a", "key_b"])
def post(): form = PhotoForm(CombinedMultiDict((request.files, request.form))) if request.method == 'POST' and form.validate(): with tempfile.NamedTemporaryFile() as temp: form.input_photo.data.save(temp) temp.flush() result = detect_objects(temp.name) photo_form = PhotoForm(request.form) return render_template('upload.html', photo_form=photo_form, result=result) else: return redirect(url_for('upload'))
def post(): form = PhotoForm(CombinedMultiDict((request.files, request.form))) if request.method == 'POST' and form.validate(): filename = '%s.%s' % (str(uuid.uuid4()), secure_filename(form.input_photo.data.filename)) content_type = content_types[filename.split('.')[-1]] write_retry_params = gcs.RetryParams(backoff_factor=1.1) gcs_file = gcs.open('/%s/%s' % (bucket_name, filename), 'w', retry_params=write_retry_params, content_type=content_type, options={'x-goog-acl': 'authenticated-read'}) for _ in form.input_photo.data.stream: gcs_file.write(_) gcs_file.close() labels = get_labels(filename) tags = [translate_text(label.description) for label in labels] entity = Photo(id=filename, tags=tags, parent=ndb.Key('User', 'default')) entity.put() for tag in tags: entity = ndb.Key('User', 'default', 'Tags', tag).get() if entity: entity.count += 1 else: entity = Tags(count=1, id=tag, parent=ndb.Key('User', 'default')) entity.put() return render_template('post.html', storage_path=storage_path, filename=filename, tags=tags) else: return redirect(url_for('photos'))
def upload(): upload_form = forms.UploadForm(CombinedMultiDict((flask.request.files, flask.request.form))) upload_form.category.choices = _create_upload_category_choices() show_ratelimit = False next_upload_time = None ratelimit_count = 0 # Anonymous uploaders and non-trusted uploaders no_or_new_account = (not flask.g.user or (flask.g.user.age < app.config['RATELIMIT_ACCOUNT_AGE'] and not flask.g.user.is_trusted)) if app.config['RATELIMIT_UPLOADS'] and no_or_new_account: now, ratelimit_count, next_upload_time = backend.check_uploader_ratelimit(flask.g.user) show_ratelimit = ratelimit_count >= app.config['MAX_UPLOAD_BURST'] next_upload_time = next_upload_time if next_upload_time > now else None if flask.request.method == 'POST' and upload_form.validate(): try: torrent = backend.handle_torrent_upload(upload_form, flask.g.user) return flask.redirect(flask.url_for('torrents.view', torrent_id=torrent.id)) except backend.TorrentExtraValidationException: pass # If we get here with a POST, it means the form data was invalid: return a non-okay status status_code = 400 if flask.request.method == 'POST' else 200 return flask.render_template('upload.html', upload_form=upload_form, show_ratelimit=show_ratelimit, ratelimit_count=ratelimit_count, next_upload_time=next_upload_time), status_code