def race_photo_add(request, race_id, template_name="team/race/add_photo.html"): """ Add photo page. """ race = get_object_or_404(Race, pk=race_id) form_class=PhotoUploadForm photo_form = form_class() if request.method == 'POST': if request.POST.get("action") == "upload": photo_form = form_class(request.user, request.POST, request.FILES) if photo_form.is_valid(): photo = photo_form.save(commit=False) photo.member = request.user photo.save() # in group context we create a Pool object for it if race: pool = Pool() pool.photo = photo # aggiunge gara al pool race.associate(pool) pool.save() request.user.message_set.create(message=_( "Successfully uploaded photo '%s'") % photo.title) include_kwargs = {"id": photo.id} redirect_to = reverse("photo_details", kwargs=include_kwargs) return HttpResponseRedirect(redirect_to) return render_to_response( template_name, { "race": race, "photo_form": photo_form, }, context_instance=RequestContext(request) )
def upload(request, form_class=PhotoUploadForm, template_name="photos/upload.html", group_slug=None, bridge=None): """ upload form for photos """ if bridge: try: group = bridge.get_group(group_slug) except ObjectDoesNotExist: raise Http404 else: group = None photo_form = form_class() if request.method == 'POST': if request.POST.get("action") == "upload": photo_form = form_class(request.user, request.POST, request.FILES) if photo_form.is_valid(): photo = photo_form.save(commit=False) photo.member = request.user photo.save() # in group context we create a Pool object for it if group: pool = Pool() pool.photo = photo group.associate(pool) pool.save() request.user.message_set.create( message=_("Successfully uploaded photo '%s'") % photo.title) include_kwargs = {"id": photo.id} if group: redirect_to = bridge.reverse("photo_details", group, kwargs=include_kwargs) else: redirect_to = reverse("photo_details", kwargs=include_kwargs) return HttpResponseRedirect(redirect_to) return render_to_response(template_name, { "group": group, "photo_form": photo_form, }, context_instance=RequestContext(request))
def upload(request, form_class=PhotoUploadForm, template_name="photos/upload.html", group_slug=None, bridge=None): """ upload form for photos """ if bridge: try: group = bridge.get_group(group_slug) except ObjectDoesNotExist: raise Http404 else: group = None photo_form = form_class() if request.method == "POST": if request.POST.get("action") == "upload": photo_form = form_class(request.user, request.POST, request.FILES) if photo_form.is_valid(): photo = photo_form.save(commit=False) photo.member = request.user photo.save() # in group context we create a Pool object for it if group: pool = Pool() pool.photo = photo group.associate(pool) pool.save() messages.add_message(request, messages.SUCCESS, ugettext("Successfully uploaded photo '%s'") % photo.title ) include_kwargs = {"id": photo.id} if group: redirect_to = bridge.reverse("photo_details", group, kwargs=include_kwargs) else: redirect_to = reverse("photo_details", kwargs=include_kwargs) return HttpResponseRedirect(redirect_to) return render_to_response(template_name, { "group": group, "photo_form": photo_form, }, context_instance=RequestContext(request))
def upload(request, form_class=PhotoUploadForm, template_name="photos/upload.html"): """ upload form for photos """ group, bridge = group_and_bridge(request) photo_form = form_class() if request.method == "POST": if request.POST.get("action") == "upload": photo_form = form_class(request.user, request.POST, request.FILES) if photo_form.is_valid(): photo = photo_form.save(commit=False) photo.member = request.user photo.save() # in group context we create a Pool object for it if group: pool = Pool() pool.photo = photo group.associate(pool, gfk_field="content_object") pool.save() messages.add_message( request, messages.SUCCESS, ugettext("Successfully uploaded photo '%s'") % photo.title) include_kwargs = {"id": photo.id} if group: redirect_to = bridge.reverse("photo_details", group, kwargs=include_kwargs) else: redirect_to = reverse("photo_details", kwargs=include_kwargs) return HttpResponseRedirect(redirect_to) ctx = group_context(group, bridge) ctx.update({ "photo_form": photo_form, }) return render_to_response(template_name, RequestContext(request, ctx))
def upload(request, form_class=PhotoUploadForm, template_name="photos/upload.html"): """ upload form for photos """ group, bridge = group_and_bridge(request) photo_form = form_class() if request.method == "POST": if request.POST.get("action") == "upload": photo_form = form_class(request.user, request.POST, request.FILES) if photo_form.is_valid(): photo = photo_form.save(commit=False) photo.member = request.user photo.save(force_insert=True) # in group context we create a Pool object for it if group: pool = Pool() pool.photo = photo group.associate(pool, gfk_field="content_object") pool.save() messages.add_message(request, messages.SUCCESS, ugettext("Successfully uploaded photo '%s'") % photo.title ) include_kwargs = {"id": photo.id} if group: redirect_to = bridge.reverse("photo_details", group, kwargs=include_kwargs) else: redirect_to = reverse("photo_details", kwargs=include_kwargs) return HttpResponseRedirect(redirect_to) ctx = group_context(group, bridge) ctx.update({ "photo_form": photo_form, }) return render(request, template_name, ctx)
def add_photo(self, photo): p = Pool(content_object=self, image=photo) p.save()