コード例 #1
0
ファイル: favorites.py プロジェクト: KateKate/aceplace
def favorite_folder(request, pk=None):
  wish_list = None
  locations = []
  sorting = 'category'
  if request.is_ajax():
    template = 'favorites/inner/folder_location_list.html'
  else:
    template = 'favorites/favorite_folder.html'
  folder = None if not pk else get_object_or_404(models.FavoriteFolder, pk=pk)
  if request.GET.get('sorting'):
    sorting = request.GET.get('sorting')
  if request.user.is_authenticated():
    locations = models.Locations.objects.filter(locatfavoritedescrip__user=request.user,
                                                locatfavoritedescrip__folder=folder).order_by(sorting)
    for item in locations:
      fav = item.locatfavoritedescrip_set.filter(user=request.user).last()
      item.fav_pk = fav.pk
      item.form = forms.FavoriteDescriptionAuthen(instance=fav)
  elif 'wish_list' in request.session:
    wish_list = request.session['wish_list']
    for pk in wish_list:
      location = get_object_or_404(models.Locations, id=pk)
      location.fav_pk = location.pk
      location.form = forms.FavoriteAdd(None, initial={'description': get_description(request, pk)})
      locations.append(location)
  return render(
    request,
    template,
    {'locations_fav': locations, 'folder': folder, 'sorting': sorting})
コード例 #2
0
ファイル: favorites.py プロジェクト: KateKate/aceplace
def from_favorite_cookie(request, user, *args, **kwargs):
  if 'wish_list' in request.session:
    wish_list = request.session['wish_list']
    for pk in wish_list:
      location = get_object_or_404(models.Locations, id=pk)
      if not models.LocatFavoriteDescrip.objects.filter(location=location, user=user):
        models.LocatFavoriteDescrip.objects.create(location=location,
                                                   user=request.user,
                                                   description=get_description(request, pk))
    request.session['wish_list'] = []