How to Integrate Idios with django-filetransfers for a music-based website -- question on setting Idios profile fields by hand

39 views
Skip to first unread message

Jonathan of Cambridge

unread,
Jul 29, 2011, 12:28:06 AM7/29/11
to Pinax Users
Subject: How to Integrate Idios with django-filetransfers for a music-
based website

I'm building a music based website on top of Pinax.

I have already integrated an mp3 player with Idios. I pull the
relevant fields from the profile and integrate them into the jquery.

My application requires the user have ability to upload files. I
thought to use idios for editing and tracking the profile information.

I currently have one of the fields of idios as mp3uploadlink.

How can I set that link programatically from outside idios? (I want
it to be updated when I upload a file.)

I tried using get_profile(). It enables me to read the idios field,
but I didn't figure out how to save() it.

Please let me know your thoughts.

Thank you in advance,

Jonathan
------------------------------------------------------------------------------------
django-filetransfers
====================
def upload_handler(request):
myprofile = get_object_or_404(User, username='testaccount') # hack
assuming this is our user name need to check this (see idios/views.py)
print "firstname", myprofile.get_profile().firstname #testing
myprofile.get_profile().firstname = 'Frank' #trying to change a
field
myprofile.save() #trying to save it
view_url = reverse('upload.views.upload_handler')
if request.method == 'POST':
form = UploadForm(request.POST, request.FILES)
if form.is_valid():
form.save()
return HttpResponseRedirect(view_url)

upload_url, upload_data = prepare_upload(request, view_url)
form = UploadForm()
return direct_to_template(request, 'upload/upload.html',
{'form': form, 'upload_url': upload_url, 'upload_data':
upload_data,
'uploads': UploadModel.objects.all()})

def download_handler(request, pk):
upload = get_object_or_404(UploadModel, pk=pk)
return serve_file(request, upload.file, save_as=True)

def delete_handler(request, pk):
if request.method == 'POST':
upload = get_object_or_404(UploadModel, pk=pk)
upload.file.delete()
upload.delete()
return
HttpResponseRedirect(reverse('upload.views.upload_handler'))

idios
=====
def profile(request, username, **kwargs):
"""
profile
"""
template_name = kwargs.pop("template_name", "idios/profile.html")

group, bridge = group_and_bridge(kwargs)

# @@@ not group-aware (need to look at moving to profile model)
other_user = get_object_or_404(User, username=username)

if request.user.is_authenticated():
if request.user == other_user:
is_me = True
else:
is_me = False
else:
is_me = False

ctx = group_context(group, bridge)
ctx.update({
"is_me": is_me,
"other_user": other_user,
})

return render_to_response(template_name, RequestContext(request,
ctx))

Patrick Altman

unread,
Jul 29, 2011, 5:12:10 PM7/29/11
to pinax...@googlegroups.com
Why not:

# Get the profile object
profile = request.user.get_profile()

# Set the value
profile.firstname = <some value>

# Save it
profile.save()

> --
> You received this message because you are subscribed to the Google Groups "Pinax Users" group.
> To post to this group, send email to pinax...@googlegroups.com.
> To unsubscribe from this group, send email to pinax-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/pinax-users?hl=en.
>

Reply all
Reply to author
Forward
0 new messages