def mixtape_ajax_keep_track(request, tracklist_id, bundle_id, track_id): tracklist = get_object_or_404(Tracklist, pk=tracklist_id) bundleback = get_object_or_404(Bundle, pk=bundle_id) track = get_object_or_404(Track, pk=track_id) if track not in tracklist.tracks_kept.all(): bundleback.tracks_kept.add(track) tracklist.tracks_kept.add(track) event = Event(main_profile = tracklist.owner, secondary_profile=bundleback.owner, event_type = "keep_track") event.save() tracklist.latest_event = event tracklist.date_latest_edit = timezone.now() bundleback.owner.reputation += 5 bundleback.nb_tracks_kept += 1 else: bundleback.tracks_kept.remove(track) tracklist.tracks_kept.remove(track) tracklist.date_latest_edit = timezone.now() bundleback.owner.reputation -= 5 bundleback.nb_tracks_kept -= 1 tracklist.save() bundleback.owner.save() bundleback.save() return HttpResponseRedirect()
def mixtape_close(request, tracklist_id): tracklist = get_object_or_404(Tracklist, pk=tracklist_id) if tracklist.owner == request.user.get_profile(): tracklist.is_finished = True tracklist.date_latest_edit = timezone.now() event = Event(main_profile = request.user.get_profile(), event_type = "closing") event.save() tracklist.latest_event = event tracklist.save() if request.POST.get('next'): url_next = request.POST['next'] return HttpResponseRedirect(url_next) else: return HttpResponseRedirect(reverse('hip_engine.views.feed'))
def mixtape_keep_track(request, tracklist_id, bundle_id, track_id): tracklist = get_object_or_404(Tracklist, pk=tracklist_id) bundleback = get_object_or_404(Bundle, pk=bundle_id) track = get_object_or_404(Track, pk=track_id) if track not in tracklist.tracks_kept.all(): bundleback.tracks_kept.add(track) tracklist.tracks_kept.add(track) event = Event(main_profile = tracklist.owner, secondary_profile=bundleback.owner, event_type = "keep_track") event.save() tracklist.latest_event = event tracklist.date_latest_edit = timezone.now() bundleback.owner.reputation += 5 bundleback.nb_tracks_kept += 1 else: bundleback.tracks_kept.remove(track) tracklist.tracks_kept.remove(track) tracklist.date_latest_edit = timezone.now() bundleback.owner.reputation -= 5 bundleback.nb_tracks_kept -= 1 tracklist.save() bundleback.owner.save() bundleback.save() if request.POST.get('next'): url_next = request.POST['next'] return HttpResponseRedirect(url_next) else: return HttpResponseRedirect(reverse('hip_engine.views.feed'))
def mixtape_create(request): userto = request.POST.get('tracklist-userto') if not userto: profile_me = request.user.get_profile() profile_queryset = request.user.get_profile().get_following() tracklist_queryset = Tracklist.objects.filter(owner__in=profile_queryset)|Tracklist.objects.filter(userto__in=profile_queryset)|profile_me.tracklists_created.all()|profile_me.tracklists_contributed.all() tracklist_list = tracklist_queryset.distinct().order_by('-date_latest_edit')[:10] context = { 'tracklist_list':tracklist_list, 'error_message_userto': "You must select at least one contributor. Click the 'New Mixtape' button to start over.", } context.update(get_generic_context(request)) context.update(get_rankings(request)) return render_to_response('hip_engine/feed.html', context, context_instance=RequestContext(request)) tracklist_form = TracklistForm(request.POST, prefix='tracklist', username=request.user.username) if tracklist_form.is_valid(): tracklist = tracklist_form.save() for i_str in ["_1","_2","_3"]: url = request.POST.get('url'+i_str) artist = request.POST.get('artist'+i_str) name = request.POST.get('name'+i_str) if url: validate = URLValidator() try: validate(url) track = Track(url=url) if artist: track.artist = artist if name: track.name = name track.save() tracklist.tracks_initial.add(track) except ValidationError, e: tracklist_queryset = Tracklist.objects.all() tracklist_list = tracklist_queryset.distinct().order_by('-date_latest_edit')[:10] context = { 'tracklist_form':tracklist_form, 'tracklist_list':tracklist_list, 'error_message_url': "Some track urls are invalid, please check them. Click the 'New Mixtape' button to start over.", } context.update(get_nav_context()) context.update(get_rankings(request)) return render_to_response('hip_engine/feed.html', context, context_instance=RequestContext(request)) title = request.POST.get('title') if title: tracklist.title = title event = Event(main_profile = request.user.get_profile(), event_type = "creation") event.save() tracklist.latest_event = event tracklist.date_latest_edit = timezone.now() string_tags = request.POST.get('tags') if string_tags: tags = parseTags(string_tags) for tag_name in tags: if Tag.objects.filter(name=tag_name): tag = get_object_or_404(Tag, name=tag_name) tracklist.tags.add(tag) else: tag = Tag(name=tag_name) tag.save() tracklist.tags.add(tag) tracklist.save()
def populate_db(request): if request.user.username == "hipmaster": from hip_engine.hipme_db_setup_clean import INSTANCES for instance in INSTANCES: if instance["model"] == "UserProfile": username = instance["username"] email = instance["email"] password = instance["password"] user = User.objects.create_user(username, email, password) if instance["model"] == "TrackList": owner = get_object_or_404(UserProfile,user__username=instance["owner"]) title = instance["title"] # description = instance["description"] is_finished = instance["is_finished"] event = Event(main_profile = owner, event_type = "creation") event.save() tracklist = Tracklist( owner = owner, title = title, # description = description, is_finished=is_finished, latest_event=event, ) tracklist.save() bundlebacks = instance["bundlebacks"] if instance["tags"]: for tag_name in instance["tags"]: tag_name = tag_name.title() tag_name = " ".join(tag_name.split()) tag = Tag(name=tag_name) tag.save() tracklist.tags.add(tag) if instance["tracks"]: for track_dic in instance["tracks"]: url = track_dic["url"] artist = track_dic["artist"] name = track_dic["name"] track = Track(url=url, artist=artist, name=name) track.save() tracklist.tracks_initial.add(track) if instance["bundlebacks"]: for bundleback_dic in instance["bundlebacks"]: owner = get_object_or_404(UserProfile,user__username=bundleback_dic["owner"]) bundleback = Bundle(owner=owner) bundleback.save() for track_dic in bundleback_dic["tracks"]: url = track_dic["url"] artist = track_dic["artist"] name = track_dic["name"] track = Track(url=url, artist=artist, name=name) track.save() bundleback.tracks.add(track) tracklist.userto.add(owner) tracklist.bundlebacks.add(bundleback) return render_to_response('hip_engine/populate_success.html', {}, context_instance=RequestContext(request)) else: return feed(request)
context.update(get_rankings(request)) return render_to_response('hip_engine/feed.html', context, context_instance=RequestContext(request)) track = Track(url=url) if artist: track.artist = artist if name: track.name = name track.save() if request.user.get_profile() == tracklist.owner: tracklist.tracks_initial.add(track) event = Event(main_profile=tracklist.owner, event_type="add_track_owner") event.save() tracklist.latest_event = event tracklist.date_latest_edit = timezone.now() tracklist.save() else: if tracklist.bundlebacks.filter(owner=request.user.get_profile()): # bundleback = get_object_or_404(Bundle, owner=request.user.get_profile()) bundleback = tracklist.bundlebacks.filter(owner=request.user.get_profile())[:1].get() bundleback.save() else: bundleback = Bundle(owner=request.user.get_profile()) bundleback.save() tracklist.userto.add(request.user.get_profile()) tracklist.save()