예제 #1
0
파일: ajax.py 프로젝트: qwaszx000/kinoinfo
def gender(request, id, gender):
    #try:
    access = False
    owner = False
    if request.profile.person_id == int(id):
        access = True
        owner = True
    elif request.user.is_superuser or request.is_admin:
        access = True
        
    if access:
        person = Person.objects.get(pk=id)
        
        act = None
        if person.male:
            if int(gender) != person.male:
                act = '2' if int(gender) else '3'
        else:
            if int(gender):
                act = '1'
        
        person.male = gender
        person.save()
        
        if person.kid and request.user.is_superuser:
            person_afisha = AfishaPersons.objects.using('afisha').filter(pk=person.kid).update(male=gender)
  
            actions_logger(24, id, request.profile, act) # персона Пол
  
    return simplejson.dumps({})
예제 #2
0
파일: ajax.py 프로젝트: qwaszx000/kinoinfo
def country(request, id, country):
    #try:
    if request.user.is_superuser or request.is_admin:
        country_obj = Country.objects.get(pk=country)
        person = Person.objects.get(pk=id)
        person.country = country_obj
        person.save()
        
        if person.kid and request.user.is_superuser:
            country_afisha = AfishaCountry.objects.using('afisha').get(pk=country_obj.kid)
            person_afisha = AfishaPersons.objects.using('afisha').get(pk=person.kid)
            
            act = None
            if person_afisha.country_id:
                if country_afisha.id != person_afisha.country_id:
                    act = '2'
            else:
                act = '1'
            
            actions_logger(23, id, request.profile, act) # персона Страна
            
            person_afisha.country = country_afisha
            person_afisha.save()
        
    return simplejson.dumps({})
예제 #3
0
파일: views.py 프로젝트: qwaszx000/kinoinfo
def create_person(request):
    film_editor = is_film_editor(request)
    if film_editor:
        if request.POST:
            name_ru = request.POST.get('person_new_name_ru','').strip()
            name_en = request.POST.get('person_new_name_en','').strip()
            parental = request.POST.get('person_new_parental_name','').strip()

            if name_ru or name_en:
                person_obj = person_create_func(name_ru, parental, name_en)

                profile = request.profile
                actions_logger(21, person_obj.id, profile, '1') # фильм Название
            
            return HttpResponseRedirect(reverse('get_person', kwargs={'id': person_obj.id}))
            
        ref = request.META.get('HTTP_REFERER', '/')
        return HttpResponseRedirect(ref)
    else:
        raise Http404
예제 #4
0
파일: ajax.py 프로젝트: qwaszx000/kinoinfo
def born(request, id, born):
    #try:
    if request.user.is_superuser or request.is_admin:
        if born:
            year, month, day = born.split('-')
            born = datetime.datetime(int(year), int(month), int(day))
        else:
            born = None
            day = 0
            month = 0
            year = 0

        person = Person.objects.get(pk=id)
        
        act = None
        if person.born:
            if born != person.born:
                act = '2' if born else '3'
        else:
            if born:
                act = '1'
                
        person.born = born
        person.save()

        if person.kid:
            person_afisha = AfishaPersons.objects.using('afisha').filter(pk=person.kid).update(
                birth_year = year,
                birth_mounth = month,
                birth_day = day
            )
        
            actions_logger(22, id, request.profile, act) # персона Дата рождения
        
        born = tmp_date(born, "d E Y г.") if born else ''

        return simplejson.dumps({'status': True, 'content': born})
예제 #5
0
def likes(request, take_eval, kid, email=False, quality=''):
    try:
        from user_registration.views import get_usercard

        evals = {
            u'Хочу смотреть в кинотеатре': 1,
            u'Хочу посмотреть дома': 2,
            u'Смотрел - рекомендую': 3,
            u'Не буду смотреть': 4,
            u'Смотрел - не рекомендую': 5,
        }

        eval_film = evals.get(take_eval)
        if eval_film:
            card = get_usercard(request.user)
            profile = card['profile']
            next = True
            id = None

            if eval_film in (1, 2):
                if eval_film == 1 and not card['city'] or not card['email']:
                    next = False
                elif eval_film == 2 and not card['email']:
                    next = False
            elif eval_film == 3:
                id = 1
            elif eval_film == 4:
                id = 18
            elif eval_film == 5:
                id = 17

            if email and email.strip() and not card['email']:
                email = email.strip()

                add_to_profile = add_email_to_exist_profile(email, profile)
                if add_to_profile:
                    if not profile.user.email:
                        profile.user.email = email
                        profile.user.save()
                    next = True
                else:
                    html = u'<div>Такой E-Mail уже существует в системе, <a href="/user/login/">авторизуйтесь</a> используя его.</div>'
                    return simplejson.dumps({
                        'status': False,
                        'email_block': html,
                    })

            act = None
            get_torrent = False
            try:
                like = Likes.objects.get(
                    personinterface=profile.personinterface, film=kid)
                if like.evaluation != eval_film:
                    act = '2'
                    like.evaluation = eval_film
                    like.save()
                    get_torrent = True
            except (Likes.DoesNotExist, Likes.MultipleObjectsReturned):
                Likes.objects.filter(personinterface=profile.personinterface,
                                     film=kid).delete()
                like = Likes.objects.create(evaluation=eval_film, film=kid)
                profile.personinterface.likes.add(like)
                act = '1'
                get_torrent = True

            if eval_film == 2:
                if not quality:
                    quality = '1'

                interface = request.profile.personinterface
                price = 100
                if interface.money >= price:
                    act = None

                    st, st_created = SubscriptionTopics.objects.get_or_create(
                        profile=profile,
                        kid=kid,
                        defaults={
                            'profile': profile,
                            'kid': kid,
                            'quality': quality,
                        })

                    if not st_created and not st.notified and st.quality != quality:
                        st.quality = quality
                        st.save()
                    '''
                    if get_torrent:
                        try:
                            torrent = Torrents.objects.get(film=kid)
                            TorrentsUsers.objects.get_or_create(
                                torrent = torrent,
                                profile = profile,
                                defaults = {
                                    'torrent': torrent,
                                    'profile': profile,
                                })
                        except Torrents.DoesNotExist:
                            pass
                    '''

            likes = get_film_likes(kid)
            likes['id'] = kid
            likes['cancel'] = False
            likes['status'] = True

            # если юзер выбрал "Cмотрел - рекомендую"/"Не буду смотреть"/"Не рекомендую", то удаляю подписки
            if eval_film in (3, 4, 5):
                subr = get_subscription_status(kid, profile)
                if subr:
                    subr.delete()
                SubscriptionTopics.objects.filter(profile=profile,
                                                  kid=kid).delete()
                likes['cancel'] = True

            if not next:
                html_add = u'в кинотеатре' if eval_film == 1 else u'в сети'

                html = u'''
                    <div>
                    <p id="email_likes_note">Если Вы хотите получить уведомление о выходе фильма %s на свой мейл,
                    введите его сюда</p><br />
                    <input type="text" id="email_likes" placeholder="E-Mail" />
                    <input type="button" id="email_likes_btn" value="ОК" /> <span id="email_likes_warnign"></span>
                    <input type="hidden" id="film_likes" value="%s" />
                    <input type="hidden" id="tquality" value="%s" />
                    <input type="hidden" id="eval_likes" value="%s" />
                    </div>
                    ''' % (html_add, kid, quality, take_eval)

                likes['email_block'] = html

            if id:
                actions_logger(id, kid, profile, act)

                action = ActionsPriceList.objects.get(pk=id, allow=True)
                paid = PaidActions.objects.get(action=action,
                                               profile=profile,
                                               object=kid,
                                               act=act)

                paid.number = 1
                paid.save()

                interface = profile.personinterface
                if paid.act == '1':
                    price = action.price
                elif paid.act == '2':
                    price = action.price_edit
                elif paid.act == '3':
                    price = action.price_delete

                interface.money += float(price)
                interface.save()

            return simplejson.dumps(likes)

    except Exception as e:
        open('errors.txt', 'a').write('%s * (%s)' % (dir(e), e.args))
예제 #6
0
파일: ajax.py 프로젝트: qwaszx000/kinoinfo
def names(request, id, name, par, en):
    try:
        from person.views import person_name_create

        access = False
        owner = False
        if request.profile.person_id == int(id):
            access = True
            owner = True
        elif request.user.is_superuser or request.is_admin:
            access = True
            
        if access:
            name = escape(strip_tags(name)).encode('utf-8').strip()
            par = escape(strip_tags(par)).encode('utf-8').strip()
            en = escape(strip_tags(en)).encode('utf-8').strip()

            slug_ru = low(del_separator(name))
            slug_en = low(del_separator(en))
            
            names = [
                {'name': name, 'lang': 1, 'status': 1},
                {'name': slug_ru, 'lang': 1, 'status': 2},
                {'name': en, 'lang': 2, 'status': 1},
                {'name': slug_en, 'lang': 2, 'status': 2},
                {'name': par, 'lang': 1, 'status': 3},
            ]

            person = Person.objects.get(pk=id)
            en_name = None
            new_name = None
            par_name = None
            act1 = None
            act2 = None
            
            if person.kid:
                for i in names:
                    if i['name']:
                        try:
                            person_name = person.name.get(status=i['status'], language__id=i['lang'])
                        except NamePerson.DoesNotExist:
                            person_name = None
                        except NamePerson.MultipleObjectsReturned:
                            person_name = None
                            for p in person.name.filter(status=i['status'], language__id=i['lang']):
                                if person_name:
                                    p.delete()
                                else:
                                    person_name = p

                        name_obj, created = person_name_create(i['name'], i['lang'], i['status'])
                        
                        if person_name:
                            if person_name != name_obj:
                                person.name.remove(person_name)
                                person.name.add(name_obj)
                                if not act1:
                                    act1 = '2'
                        else:
                            person.name.add(name_obj)
                            act1 = '1'

                        if i['status'] == 1 and i['lang'] in (1,2):
                            AfishaPersonsName.objects.using('afisha').filter(person_id__id=person.kid, flag=i['lang']).update(name=i['name'])
                        
                actions_logger(21, id, request.profile, act1) # персона Имя

            else:
                person.name.clear()
                act1 = '3'
                if name:
                    for i in names[0:1]:
                        if i['name']:
                            name_obj, created = person_name_create(i['name'], i['lang'], i['status'])
                            person.name.add(name_obj)
                            
                    act1 = '2'
                actions_logger(21, id, request.profile, act1) # персона Имя

            
            return simplejson.dumps({'status': owner, 'content': name})
        
    except Exception as e:
        return simplejson.dumps({'status': 'error', 'content': '%s * (%s)' % (dir(e), e.args)})
예제 #7
0
def news_delete(request, id):
    if request.POST:
        type = request.POST.get('type')
        # если спрос или предложение
        if type in ('11', '12'):
            org_id = request.POST.get('org_id')
            offer = request.POST.get('offer')
            org = get_object_or_404(Organization, pk=org_id)
            is_editor = is_editor_func(request, org)
            if request.user.is_superuser or is_editor or request.is_admin:
                autor = request.profile
                news = get_object_or_404(News, pk=id)
                if request.user.is_superuser or news.autor == autor or request.is_admin:
                    news.delete()
                    NewsTags.objects.filter(news=None).delete()

                    if type == '11' and offer:
                        return HttpResponseRedirect(reverse('organization_offers', kwargs={'id': org.uni_slug, 'offer_id': offer}))
                    elif type == '12' and offer:
                        return HttpResponseRedirect(reverse('organization_adverts', kwargs={'id': org.uni_slug, 'advert_id': offer}))
            return HttpResponseRedirect(reverse('main'))
        # если коммент, вопрос, отзыв
        elif type in ('8', '9', '10'):
            org_id = request.POST.get('org_id')
            autor = request.profile
            news = get_object_or_404(News, pk=id)
            
            if request.user.is_authenticated and news.autor == autor or request.user.is_superuser:
                news.delete()
                NewsTags.objects.filter(news=None).delete()

                if org_id:
                    if type == '8':
                        ntype = 'отзыв'
                    elif type == '9':
                        ntype = 'вопрос'
                    elif type == '10':
                        ntype = 'комментарий'
                        
                    ActionsLog.objects.create(
                        profile = request.profile,
                        object = '1',
                        action = '3',
                        object_id = org_id,
                        attributes = ntype,
                        site = request.current_site,
                    )
                
                    org = get_object_or_404(Organization, pk=org_id)
                    if type == '8':
                        return HttpResponseRedirect(reverse('organization_reviews', kwargs={'id': org.uni_slug}))
                    elif type == '9':
                        return HttpResponseRedirect(reverse('organization_questions', kwargs={'id': org.uni_slug})) 
                    elif type == '10':
                        return HttpResponseRedirect(reverse('organization_comments', kwargs={'id': org.uni_slug}))
            return HttpResponseRedirect(reverse('main'))
        # если рецензия
        elif type == '14':
            film_editor = is_film_editor(request)
            if film_editor:
                n = get_object_or_404(News, pk=id)
                
                actions_logger(4, n.extra, request.profile, '3', n.title) # рецензия
                    
                n.delete()
                News.objects.filter(reader_type='10', extra__istartswith='%s;' % id).delete()
                NewsTags.objects.filter(news=None).delete()
                ref = request.META.get('HTTP_REFERER', '/').split('?')[0]
                return HttpResponseRedirect(ref)
        # если новость
        else:
            if request.user.is_superuser or request.is_admin:
                news = get_object_or_404(News, pk=id)
                news.delete()
                NewsTags.objects.filter(news=None).delete()
            if request.current_site.domain in ('vladaalfimovdesign.com.au', 'letsgetrhythm.com.au', 'imiagroup.com.au'):
                return HttpResponseRedirect(reverse('blog'))
            else:
                return HttpResponseRedirect(reverse('main'))
    else:
        raise Http404
예제 #8
0
def news_add(request):
    
    profile = request.profile
    current_site = request.current_site

    if request.POST:
        type = request.POST.get('type')          
        # если предложение или спрос
        if type in ('11', '12'):
            id = request.POST.get('org_id')
            offer = request.POST.get('offer')
            org = get_object_or_404(Organization, pk=id)
            tag_rel = get_object_or_404(Organization_Tags, pk=offer)
            is_editor = is_editor_func(request, org)
            if request.user.is_superuser or is_editor or request.is_admin:
                name = request.POST.get('news_title')
                tag = request.POST.get('tag')
                if name and tag:
                    tags = tag.split(',')
                    if type == '11':
                        tags = tags[:6] + ['предложение']
                    elif type == '12':
                        tags = tags[:6] + ['спрос']
                    
                    news = create_news(request, tags, name, '', type)
                    
                    OrganizationNews.objects.create(organization=org, news=news, tag=tag_rel)
                if type == '11':
                    return HttpResponseRedirect(reverse('organization_offers_news', kwargs={'id': org.uni_slug, 'offer_id': offer, 'item_id': news.id}))
                else:
                    return HttpResponseRedirect(reverse('organization_adverts_news', kwargs={'id': org.uni_slug, 'advert_id': offer, 'item_id': news.id}))
        
        else:
            # если вопрос, отзыв, коммент
            if type in ('8', '9', '10'):
                id = request.POST.get('org_id')
                org = get_object_or_404(Organization, pk=id)
                text = request.POST.get('text')
                author_nick = request.POST.get('author_nick', 0)
                if request.user.is_authenticated() and text:
                    if type == '8':
                        name = 'Отзыв на %s' % org.name.encode('utf-8')
                        tag = 'отзыв'
                    elif type == '9':
                        name = 'Вопрос для %s' % org.name.encode('utf-8')
                        tag = 'вопрос'
                    elif type == '10':
                        name = 'Комментарий к %s' % org.name.encode('utf-8')
                        tag = 'комментарий'
                    
                    
                    # антиспам
                    spam = is_news_spam(request, type)
                    banned = is_banned_user(request)
                    if not spam and not banned:
                        text = xss_strip2(text)
                        text = BeautifulSoup(text, from_encoding="utf-8")
                        for t in text.find_all('a'):
                            t.extract()
                        text = str(text).replace('<html><head></head><body>','').replace('</body></html>','')
                        
                        news = create_news(request, [tag], name, text, type, author_nick)
                        OrganizationNews.objects.create(organization=org, news=news)

                        ActionsLog.objects.create(
                            profile = profile,
                            object = '1',
                            action = '1',
                            object_id = org.id,
                            attributes = tag,
                            site = current_site,
                        )
                        
                        
                    if type == '8':
                        return HttpResponseRedirect(reverse('organization_reviews', kwargs={'id': org.uni_slug}))
                    elif type == '9':
                        return HttpResponseRedirect(reverse('organization_questions', kwargs={'id': org.uni_slug}))
                    elif type == '10':
                        return HttpResponseRedirect(reverse('organization_comments', kwargs={'id': org.uni_slug}))
            # если рецензия к фильму
            elif type == '14':
                film_editor = is_film_editor(request)
                
                if film_editor:
                    id = request.POST.get('film_id')
                    rate1 = request.POST.get('eye')
                    rate2 = request.POST.get('mind')
                    rate3 = request.POST.get('heart')
                    
                    if id:
                        text = request.POST.get('note')
                        title = request.POST.get('title', 'Рецензия на фильм')
                        review_id = request.POST.get('review_id')
                        profile_id = request.POST.get('profile_id')
                        
                        act = None
                        
                        if review_id:
                            obj = News.objects.get(id=review_id)
                            obj.title = title
                            obj.text = text
                            obj.save()
                            
                            if rate1 and rate2 and rate3:
                                votes, votes_created = FilmsVotes.objects.get_or_create(
                                    kid = id,
                                    user_id = profile_id,
                                    defaults = {
                                        'kid': id,
                                        'user_id': profile_id,
                                        'rate_1': rate1,
                                        'rate_2': rate2,
                                        'rate_3': rate3,
                                })
                                if not votes_created:
                                    votes.rate_1 = rate1
                                    votes.rate_2 = rate2
                                    votes.rate_3 = rate3
                                    votes.save()
                                    
                                FilmVotes.objects.using('afisha').filter(pk=obj.kid).update(
                                    rate_1 = rate1,
                                    rate_2 = rate2,
                                    rate_3 = rate3,
                                )
                            act = '2'
                        else:
                            author_nick = request.POST.get('author_nick', 0)
                            
                            news = create_news(request, [], title, text, type, author_nick, id)

                            FilmsVotes.objects.get_or_create(
                                kid = id,
                                user = profile,
                                defaults = {
                                    'kid': id,
                                    'user': profile,
                                    'rate_1': rate1,
                                    'rate_2': rate2,
                                    'rate_3': rate3,
                            })
                            
                            act = '1'
                        
                        actions_logger(4, id, profile, act, title) # рецензия

            # коммент к рецензии
            elif type == '010':
                review_id = request.POST.get('review')
                answer = int(request.POST.get('answer', 0))
                text = request.POST.get('text')
                author_nick = request.POST.get('author_nick', 0)
                if review_id and text:
                    # антиспам
                    spam = is_news_spam(request, 10)
                    banned = is_banned_user(request)
                    if not spam and not banned:
                        text = BeautifulSoup(text, from_encoding="utf-8").text.strip()
                        extra = '%s;%s' % (review_id, answer) if answer else '%s;' % review_id
                        news = create_news(request, [], 'Комментарий к рецензии', text, '10', author_nick, extra)
            # если новость
            else:
                if request.user.is_superuser or request.is_admin:
                    name = request.POST.get('news_title')
                    tag = request.POST.get('tag')
                    author_nick = request.POST.get('author_nick', 0)
                    if name and tag:
                        tags = tag.split(',')
                        tags = tags[:6]
                        news = create_news(request, tags, name, '', None, author_nick)
                        if current_site.domain not in ('vladaalfimovdesign.com.au', 'letsgetrhythm.com.au', 'imiagroup.com.au'):
                            return HttpResponseRedirect(reverse('news', kwargs={'id': news.id}))
    
    ref = request.META.get('HTTP_REFERER', '/').split('?')[0]
        
    return HttpResponseRedirect(ref)