def new(req, category=None, recipient_id=None): if req.method == 'POST': recipient = None recipient_owner = None if category == 'user_image': recipient = get_object_or_404(UserImage, pk=recipient_id) recipient_owner = recipient.user form = TagForm(req.POST) redirect_url = req.POST.get('next', '/') json = {} if form.is_valid(): tag, created = Tag.objects.get_or_create(**form.cleaned_data) if category == 'user_image': tagged_user_image, created = TaggedUserImage.objects.get_or_create( user_image=recipient, tag=tag, tagger=req.user) if req.is_ajax(): form = TagForm() context = { 'tag': tag, 'category': category, 'recipient_id': recipient_id, 'recipient_owner': recipient_owner, 'next': redirect_url, } tag_html = render_to_string( 'tag/tag.html', context, context_instance=RequestContext(req)) json['success'] = created json['tag_html'] = tag_html else: if req.is_ajax(): json['success'] = False else: store_session_form(req.session, TagForm, req.POST) if req.is_ajax(): context = { 'tag_form': form, 'category': category, 'recipient_id': recipient_id, 'recipient_owner': recipient_owner, 'next': redirect_url, } form_html = render_to_string('tag/form.html', context, context_instance=RequestContext(req)) json['form_html'] = form_html response = simplejson.dumps(json) return HttpResponse(response, content_type='application/javascript') else: return redirect(redirect_url)
def new(req, category=None, recipient_id=None): if req.method == 'POST': recipient = None recipient_owner = None if category == 'user_image': recipient = get_object_or_404(UserImage, pk=recipient_id) recipient_owner = recipient.user form = TagForm(req.POST) redirect_url = req.POST.get('next','/') json = {} if form.is_valid(): tag,created = Tag.objects.get_or_create(**form.cleaned_data) if category == 'user_image': tagged_user_image,created = TaggedUserImage.objects.get_or_create( user_image=recipient, tag=tag, tagger=req.user ) if req.is_ajax(): form = TagForm() context = { 'tag': tag, 'category': category, 'recipient_id': recipient_id, 'recipient_owner': recipient_owner, 'next': redirect_url, } tag_html = render_to_string('tag/tag.html', context, context_instance=RequestContext(req)) json['success'] = created json['tag_html'] = tag_html else: if req.is_ajax(): json['success'] = False else: store_session_form(req.session, TagForm, req.POST) if req.is_ajax(): context = { 'tag_form': form, 'category': category, 'recipient_id': recipient_id, 'recipient_owner': recipient_owner, 'next': redirect_url, } form_html = render_to_string('tag/form.html', context, context_instance=RequestContext(req)) json['form_html'] = form_html response = simplejson.dumps(json) return HttpResponse(response, content_type='application/javascript') else: return redirect(redirect_url)
def new(req, category=None, recipient_id=None): recipient = get_object_or_404(CommentReceiver, pk=recipient_id) if req.method == 'POST': form = PartialCommentForm(req.POST) redirect_url = req.POST.get('next', '/') json = {} if form.is_valid(): comment = form.save(commit=False) comment.recipient = recipient comment.author = req.user comment.save() if req.is_ajax(): form = PartialCommentForm() context = { 'comment': comment, 'next': redirect_url, } comment_html = render_to_string( 'comment/comment.html', context, context_instance=RequestContext(req)) json['success'] = True json['comment_html'] = comment_html else: if req.is_ajax(): json['success'] = False else: store_session_form(req.session, PartialCommentForm, req.POST) if req.is_ajax(): context = { 'comment_form': form, 'recipient_id': recipient.id, 'category': category, 'next': redirect_url, } form_html = render_to_string('comment/form.html', context, context_instance=RequestContext(req)) json['form_html'] = form_html response = simplejson.dumps(json) return HttpResponse(response, content_type='application/javascript') else: return redirect(redirect_url) else: # show a generic comment form pass
def new(req): if req.method == 'POST': album = Album(user=req.user) form = AlbumForm(req.POST, instance=album) if form.is_valid(): form.save(commit=False) album.comment_receiver=CommentReceiver.objects.create() album.save() messages.success(req, "Album '%s' successfully created." % album.title) return redirect(album) else: store_session_form(req.session, AlbumForm, req.POST) messages.error(req, 'Please fix the following errors:') return redirect(req.POST.get('from','/')) else: pass
def new(req, category=None, recipient_id=None): recipient = get_object_or_404(CommentReceiver, pk=recipient_id) if req.method == 'POST': form = PartialCommentForm(req.POST) redirect_url = req.POST.get('next', '/') json = {} if form.is_valid(): comment = form.save(commit=False) comment.recipient = recipient comment.author = req.user comment.save() if req.is_ajax(): form = PartialCommentForm() context = { 'comment': comment, 'next': redirect_url, } comment_html = render_to_string('comment/comment.html', context, context_instance=RequestContext(req)) json['success'] = True json['comment_html'] = comment_html else: if req.is_ajax(): json['success'] = False else: store_session_form(req.session, PartialCommentForm, req.POST) if req.is_ajax(): context = { 'comment_form': form, 'recipient_id': recipient.id, 'category': category, 'next': redirect_url, } form_html = render_to_string('comment/form.html', context, context_instance=RequestContext(req)) json['form_html'] = form_html response = simplejson.dumps(json) return HttpResponse(response, content_type='application/javascript') else: return redirect(redirect_url) else: # show a generic comment form pass
def save_profile(req): if req.method == 'POST': profile = get_user_profile(req.user) profile_form = ProfileForm(req.POST, instance=profile) license_form = LicenseForm(req.POST, instance=profile.default_license) if profile_form.is_valid() and license_form.is_valid(): profile_form.save() license,created = License.objects.get_or_create( default_license=License.get_default(), allow_commercial_use=license_form.cleaned_data['allow_commercial_use'], allow_modifications=license_form.cleaned_data['allow_modifications'], ) profile.default_license = license profile.save() messages.success(req, 'Profile successfully updated.') else: store_session_form(req.session, ProfileForm, req.POST) store_session_form(req.session, LicenseForm, req.POST) messages.error(req, 'Please fix the following errors:') return redirect('astrometry.net.views.user.dashboard_profile')