コード例 #1
0
ファイル: handlers.py プロジェクト: ararteko/arartekomaps
    def create(self, request):
        username = request.POST.get("username","")
        origin = request.POST.get("origin","")
        social_id = request.POST.get("id","")
        token = request.POST.get("token","")
        text = request.POST.get("text","")
        slug = request.POST.get("slug","")
        lang = LANG_MAPPING[request.GET.get("lang","EUSKARA")]
        translation.activate(lang)

        f = open('post_saiakerak.txt','w')
        try:
            if origin in tuple(SOCIAL_ORIGIN.keys()):
                if origin == "1":
                    profile = CSSocialUser.objects.get(facebook_id=username)
                    user = profile.user
                else:
                    profile = CSSocialUser.objects.get(twitter_id=username)
                    user = profile.user
            else:
                user = User.objects.get(username=username)
                f.write('[OK] Username: '******' | Text: '+text+' | Slug: '+slug+' | Token: '+token+'\n')
        except:
            logger.error("ERROR: Invalid username")
            f.write('[ERROR] Username: '******' | Text: '+text+' | Slug: '+slug+' | Token: '+token+'\n')
            return {'action': 'post_comment', 'result': 'failed', 'value': 'invalid_username', 'msg': translation.ugettext('Erabiltzaile hori ez da sisteman existitzen. Jarri administratzailearekin kontaktuan.')}

        f.close()
        if default_token_generator.check_token(user,token):
            try:
                place = Place.objects.get(slug=slug)

                if text:
                    comment = Comment()
                    comment.author = user
                    comment.is_public = True
                    comment.public_date = datetime.today()
                    comment.parent = place
                    comment.body = text
                    comment.ip_address = request.META.get("REMOTE_ADDR", None)
                    if 'photo' in request.FILES:
                        try:
                            photo = handle_photo_file(request.FILES['photo'], user.username)
                        except Exception, e:
                            return {'action': 'post_comment', 'result': 'failed', 'value': 'decoding_error', 'msg': translation.ugettext('Irudiaren formatua ez da egokia. JPG formatuan bidali mesedez.')+str(e)}
                        comment.photo = photo
                    comment.save()
                    return {'action': 'post_comment', 'result': 'success'}
                else:
                    return {'action': 'post_comment', 'result': 'failed', 'value': 'text_not_found', 'msg': translation.ugettext('Iruzkinak ez dauka testurik. Testua beharrezkoa da.')}
コード例 #2
0
def placeview(request, slug=''):
    """ """
    template_name = 'place'
    users = []
    place = get_object_or_404(Place, slug=slug)
    if MPhoto.objects.filter(place=place, def_img=True).exists():
        def_images = MPhoto.objects.filter(place=place, def_img=True)
    images = MPhoto.objects.filter(place=place, def_img=False).order_by('user')
    username = None
    imgs = []
    for i, image in enumerate(images):
        if not users:
            username = image.user
            imgs.append(image)
        elif username == image.user:
            imgs.append(image)
        else:
            users.append({'user': username, 'images': imgs})
            imgs = image
            username = image.user
        if i == len(images) - 1:
            users.append({'user': username, 'images': imgs})

    if request.method == 'POST':
        kopia = request.POST.copy()
        kopia['author_id'] = request.user.id
        kopia['is_public'] = True
        form = CommentForm(kopia)
        if form.is_valid():
            comment = Comment()
            comment.author = request.user
            comment.is_public = True
            comment.public_date = datetime.today()
            comment.parent = place
            comment.body = form.cleaned_data['body']
            comment.ip_address = request.META.get("REMOTE_ADDR", None)
            if request.FILES.get('photo', ''):
                photo = handle_photo_file(request.FILES['photo'],
                                          request.user.username)
                comment.photo = photo
            comment.save()
    form = CommentForm()
    comments = Comment.objects.filter(parent=place,
                                      is_public=True,
                                      is_deleted=False)

    return render_to_response('place.html',
                              locals(),
                              context_instance=RequestContext(request))
コード例 #3
0
ファイル: views.py プロジェクト: ararteko/arartekomaps
def placeview(request, slug=''):
    """ """
    template_name='place'
    users = []
    place = get_object_or_404(Place, slug=slug)
    if MPhoto.objects.filter(place=place, def_img=True).exists():
        def_images = MPhoto.objects.filter(place=place, def_img=True)
    images = MPhoto.objects.filter(place=place,def_img=False).order_by('user')
    username = None
    imgs = []
    for i, image in enumerate(images):
        if not users:
            username = image.user
            imgs.append(image)
        elif username == image.user:
            imgs.append(image)
        else:
            users.append({'user': username, 'images': imgs})
            imgs = image
            username = image.user
        if i == len(images)-1:
            users.append({'user': username, 'images': imgs})

    if request.method == 'POST':
        kopia=request.POST.copy()
        kopia['author_id']=request.user.id
        kopia['is_public']=True
        form = CommentForm(kopia)
        if form.is_valid():
              comment = Comment()
              comment.author = request.user
              comment.is_public = True
              comment.public_date = datetime.today()
              comment.parent = place
              comment.body = form.cleaned_data['body']
              comment.ip_address = request.META.get("REMOTE_ADDR", None)
              if request.FILES.get('photo',''):
                 photo = handle_photo_file(request.FILES['photo'], request.user.username)
                 comment.photo= photo
              comment.save()
    form = CommentForm()
    comments = Comment.objects.filter(parent=place,is_public=True,is_deleted=False)

    return render_to_response('place.html', locals(), context_instance=RequestContext(request)
    )
コード例 #4
0
    def create(self, request):
        username = request.POST.get("username", "")
        origin = request.POST.get("origin", "")
        social_id = request.POST.get("id", "")
        token = request.POST.get("token", "")
        text = request.POST.get("text", "")
        slug = request.POST.get("slug", "")
        lang = LANG_MAPPING[request.GET.get("lang", "EUSKARA")]
        translation.activate(lang)

        f = open('post_saiakerak.txt', 'w')
        try:
            if origin in tuple(SOCIAL_ORIGIN.keys()):
                if origin == "1":
                    profile = CSSocialUser.objects.get(facebook_id=username)
                    user = profile.user
                else:
                    profile = CSSocialUser.objects.get(twitter_id=username)
                    user = profile.user
            else:
                user = User.objects.get(username=username)
                f.write('[OK] Username: '******' | Text: ' + text +
                        ' | Slug: ' + slug + ' | Token: ' + token + '\n')
        except:
            logger.error("ERROR: Invalid username")
            f.write('[ERROR] Username: '******' | Text: ' + text +
                    ' | Slug: ' + slug + ' | Token: ' + token + '\n')
            return {
                'action':
                'post_comment',
                'result':
                'failed',
                'value':
                'invalid_username',
                'msg':
                translation.ugettext(
                    'Erabiltzaile hori ez da sisteman existitzen. Jarri administratzailearekin kontaktuan.'
                )
            }

        f.close()
        if default_token_generator.check_token(user, token):
            try:
                place = Place.objects.get(slug=slug)

                if text:
                    comment = Comment()
                    comment.author = user
                    comment.is_public = True
                    comment.public_date = datetime.today()
                    comment.parent = place
                    comment.body = text
                    comment.ip_address = request.META.get("REMOTE_ADDR", None)
                    if 'photo' in request.FILES:
                        try:
                            photo = handle_photo_file(request.FILES['photo'],
                                                      user.username)
                        except Exception, e:
                            return {
                                'action':
                                'post_comment',
                                'result':
                                'failed',
                                'value':
                                'decoding_error',
                                'msg':
                                translation.ugettext(
                                    'Irudiaren formatua ez da egokia. JPG formatuan bidali mesedez.'
                                ) + str(e)
                            }
                        comment.photo = photo
                    comment.save()
                    return {'action': 'post_comment', 'result': 'success'}
                else:
                    return {
                        'action':
                        'post_comment',
                        'result':
                        'failed',
                        'value':
                        'text_not_found',
                        'msg':
                        translation.ugettext(
                            'Iruzkinak ez dauka testurik. Testua beharrezkoa da.'
                        )
                    }