def _comp_photo(self, user): photo_title = self.request.get('photo-title') comp_id = int(self.request.get('comp-id')) comp = Competition.get_by_id(comp_id) usercomp = UserComp(user=user.key, comp=comp.key) usercomp.put() return {'competition': comp.key, 'title': photo_title}
def _upload_photos(self, users, comps): d = os.getcwd() d = os.path.join(d, 'test', '*.jpg') photos = glob(d) titles = ('Mars', 'Finnish Flag', 'Hospital in the distance', '', '', '') comp1 = comps[0] # collect Photo instances here p = [] all_data = zip(product(users, comps), photos, titles) for (user, comp), photo_path, title in all_data: file_name = files.blobstore.create(mime_type='image/jpeg') with files.open(file_name, 'a') as f: f.write(open(photo_path, 'rb').read()) files.finalize(file_name) blob_key = files.blobstore.get_blob_key(file_name) photo = Photo( user=user.key, competition=comp.key, blob=blob_key, title=title ) photo.put() p.append(photo) user_comp = UserComp(user=user.key, comp=comp.key) if comp == comp1: user_comp.submitted_scores = True user_comp.put() return p