Пример #1
0
 def update(self, request, id):
     """Update the position (i.e. "flag") the specified tag.
     """
     try:
         tag = Tag.objects.get(pk=base62_decode(id))
     except Tag.DoesNotExist:
         return rc.NOT_FOUND
     # Create position
     position = Position.objects.create(
         latitude=request.form.cleaned_data['latitude'],
         logitude=request.form.cleaned_data['longitude'],
         accuracy=request.form.cleaned_data['accuracy'],
         geolocation_support=request.form.cleaned_data['geolocation_support'],
         sensor=request.form.cleaned_data['sensor'])
     # Create flag
     # Hide this if the flagger or the tag owner wants it hidden
     visibility = 'pub' if (request.form.cleaned_data['visibility'] == 'pub' 
                            and tag.visbility == 'pub')\
                        else 'prv'
     tag.flag_set.create(
         user=request.user,
         position=position,
         note=request.form.cleaned_data['note'],
         visibility=visibility,
         img=request.form.cleaned_data['img'])
     # Return 200 OK
     return rc.ALL_OK
Пример #2
0
def mobile_update_tag(request):
    """Handles update tag requests from the mobile index page
    
    (Web index page does this asynchronously.)
    """
    if 'code' not in request.GET:
        return HttpResponseRedirect(index)
    code = request.GET['code']
    # If user gave hostname too, strip it
    pattern = r'\/(\w{6,})\/?$';
    result = re.search(pattern, code)
    if result is not None:
        code = result.groups()[0]
    
    tag = get_object_or_404(Tag, pk=base62_decode(code.upper()))
    if tag.is_deleted:
        raise Http404
    flag_form = FlagForm()
    position_form = PositionForm()
    authform = PrettyAuthenticationForm(request)
    next = reverse(update_tag, kwargs={'code': code})
    return render_to_response('mobile/tag_update.html', 
                              {'tag': tag,
                               'authform': authform,
                               'flagform': flag_form,
                               'positionform': position_form,
                               'next': next}, 
                              context_instance=RequestContext(request))
Пример #3
0
 def delete(self, request, id):
     """Delete the specified tag.
     """
     try:
         tag = Tag.objects.get(pk=base62_decode(id))
     except Tag.DoesNotExist:
         return rc.NOT_FOUND
     if not tag.user == request.user:
         return rc.FORBIDDEN
     tag.delete()
     return rc.DELETED
Пример #4
0
def update_tag(request, code):
    """Flag a tag
    """
    tag = get_object_or_404(Tag, pk=base62_decode(code.upper()))
    if tag.is_deleted:
        raise Http404
    if request.method == 'POST':
        flag_form = FlagForm(request.POST, request.FILES)
        position_form = PositionForm(request.POST)
        if flag_form.is_valid() and position_form.is_valid():
            # Save position
            position = position_form.save()
            # Save flag
            flag = flag_form.save(commit=False)
            flag.tag = tag
            flag.position = position
            if request.user.is_authenticated():
                flag.user = request.user
            else:
                # Flags of unauthenticated users are always public
                flag.visibility = 'pub'
            flag.points = flag.calc_points()
            flag.save()
            # Get hashtags from flag.note or from POST['hashtags']
            hashtags = flag.get_hashtags('note', request.POST['hashtags'])
            Hashtag.objects.update_tags(flag, hashtags)
            if request.user.is_authenticated():
                if flag.points > 0:
                    profile = request.user.get_profile()
                    profile.points = profile.points + flag.points
                    profile.save()
                # If logged in, redirect to the user's profile, or to the tag's redirect URL
                url = tag.redirect_url if tag.redirect_url else reverse(view_user,
                                                                        kwargs={'username': request.user.username})
                return HttpResponseRedirect(url)
            # Otherwise view the tag (or go to its redirect URL)
            url = tag.redirect_url if tag.redirect_url else reverse(view_tag, kwargs={'id': tag.id})
            return HttpResponseRedirect(url)
    else:
        flag_form = FlagForm()
        position_form = PositionForm()

    authform = PrettyAuthenticationForm(request)
    regform = RegistrationForm()
    next = reverse('trc_me.web.views.update_tag', kwargs={'code': code})
    template = 'web/tag_update.html' if not is_mobile_browser(request) else 'mobile/tag_update.html'
    return render_to_response(template, 
                              {'tag': tag,
                               'authform': authform,
                               'regform': regform,
                               'flagform': flag_form,
                               'positionform': position_form,
                               'next': next}, 
                              context_instance=RequestContext(request))
Пример #5
0
def ajax_update_tag(request, id):
    """Return HTML for the Update Tag dialog
    """
    tag = get_object_or_404(Tag, pk=base62_decode(id.upper()))
    flag_form = FlagForm()
    authform = AuthenticationForm()
    position_form = PositionForm()
    return render_to_response('web/tag_update_dialog.html', 
                              {'tag': tag,
                               'flagform': flag_form,
                               'authform': authform,
                               'positionform': position_form}, 
                              context_instance=RequestContext(request))
Пример #6
0
 def read(self, request, id=None):
     """Anonymous users can get info about public tags. 
     """
     if id:
         # Specific tag requested
         try:
             tag = Tag.objects.get(pk=base62_decode(id))
         except Tag.DoesNotExist:
             return rc.NOT_FOUND
         if not tag.visibility == 'pub':
             return rc.FORBIDDEN
         # Include the 5 most-recent public flags
         kwargs = {'incl_flags': True,
                   'incl_flags_public': True,
                   'incl_flags_end': 5}
         return tag._api_dict(**kwargs)
     # Return last five public tags
     return [tag._api_dict() for tag in Tag.objects.filter(visibility='pub')[:5]]
Пример #7
0
 def update(self, request, id):
     """Anonymous users can flag any tags, but flags are always hidden
     """
     try:
         tag = Tag.objects.get(pk=base62_decode(id))
     except Tag.DoesNotExist:
         return rc.NOT_FOUND
     # Create position
     position = Position.objects.create(
         latitude=request.form.cleaned_data['latitude'],
         logitude=request.form.cleaned_data['longitude'],
         accuracy=request.form.cleaned_data['accuracy'],
         geolocation_support=request.form.cleaned_data['geolocation_support'],
         sensor=request.form.cleaned_data['sensor'])
     # Create flag
     tag.flag_set.create(
         user=None,
         position=position,
         note=request.form.cleaned_data['note'],
         visibility='prv',
         img=request.form.cleaned_data['img'])
     return rc.ALL_OK
Пример #8
0
 def read(self, request, id=None):
     """Return a specific tag, or a list of tags if no tag ID is given.
     """
     if id:
         # Specific tag requested
         try:
             tag = Tag.objects.get(pk=base62_decode(id))
         except Tag.DoesNotExist:
             return rc.NOT_FOUND
         if not tag.visibility == 'pub' and not tag.user == request.user:
             return rc.FORBIDDEN
         kwargs = {'incl_flags': True,
                   'incl_flags_end': 5}
         if tag.user == request.user:
             # The tag belongs to the user. Give them all flags
             kwargs['incl_flags_all'] = True
         else:
             # Give the user their and public flags
             kwargs['incl_flags_user'] = request.user
             kwargs['incl_flags_public'] = True
         return tag._api_dict(**kwargs)
     # Return user's last five tags
     return [tag._api_dict() for tag in Tag.objects.filter(user=request.user)[:5]]