Exemplo n.º 1
0
def editEmail(request):
    if request.method == 'POST':
        if request.POST['email'] != request.user.email:
            if UserManager().email_not_exist(request.POST['email']):
                if BlackListManager().email_exist_in_blacklist(
                        request.POST['email']) != True:
                    user = get_user_model().objects.get(pk=request.user.pk)
                    save_email = UserManager().save_email(
                        user, request.POST['email'])
                    if save_email['success']:
                        return HttpResponse(
                            Collect(response='success').get_json(),
                            content_type='application/json')
                    return HttpResponse(Collect(
                        response='filure',
                        message=str(MessageManager().getMessage(
                            save_email['message']))).get_json(),
                                        content_type='application/json')
                return HttpResponse(Collect(
                    response='filure',
                    message=str(MessageManager().getMessage(
                        'email_is_in_black_list'))).get_json(),
                                    content_type='application/json')
            return HttpResponse(Collect(
                response='filure',
                message=str(
                    MessageManager().getMessage('email_exist'))).get_json(),
                                content_type='application/json')
        return HttpResponse('0')
    return HttpResponse('501')
Exemplo n.º 2
0
def collectUsers(users):
    collect_user = {}
    iterate_user = 0
    for user in users:
        collect_user[iterate_user] = Collect(pk=user.pk).obj
        date_joined = str(user.date_joined.date()) + ' ' + str(
            user.date_joined.hour) + ':' + str(user.date_joined.hour)
        collect_user[iterate_user]['fields'] = Collect(
            first_name=user.first_name,
            last_name=user.last_name,
            email=user.email,
            email_confirmed=user.email_confirmed,
            avatar=str(user.avatar),
            is_superuser=user.is_superuser,
            is_staff=user.is_staff,
            is_active=user.is_active,
            date_joined=str(date_joined),
            groups={}).obj
        iterate_group = 0
        for group in user.groups.all():
            collect_user[iterate_user]['fields']['groups'][
                iterate_group] = Collect(name=group.name, pk=group.pk).obj
            iterate_group += 1
        iterate_user += 1
    return collect_user
def removeArticle(request, *args, **kwargs):
    if request.method == 'POST':
        article = Article.objects.get_article(keywords=kwargs['keywords'],
                                              language=kwargs['language'])
        if Article.objects.article_owner_is_requester(request, article):
            article.delete()
            return HttpResponse(Collect(success=True).get_json(),
                                content_type='application/json')
        return HttpResponse(Collect(
            success=False,
            message=MessageManager().getMessage(
                message='no_privileg_to_reach_this_page')).get_json(),
                            content_type='application/json')
    return HttpResponse('501')
Exemplo n.º 4
0
def getArticlePartHTML(request, *args, **kwargs):
    if request.method == 'GET':
        article = Article.objects.get_article(kwargs['keywords'],
                                              language=kwargs['language'])
        return render(request, 'article/article_card.html',
                      {'article': article})
    return HttpResponse(Collect(
        response='filure',
        message=str(MessageManager().getMessage('bad_request'))).get_json(),
                        content_type='application/json')
Exemplo n.º 5
0
def editAvatar(request):
    if request.method == 'POST':
        try:
            if request.FILES:
                UserManager().save_image(request.user, request.FILES['avatar'])
                return HttpResponse(Collect(response='success').get_json(),
                                    content_type='application/json')
            return HttpResponse(Collect(
                response='failure',
                message=str(MessageManager().getMessage(
                    'problem_with_save'))).get_json,
                                content_type='application/json')
        except:
            return HttpResponse(Collect(
                response='failure',
                message=str(MessageManager().getMessage(
                    'problem_with_save'))).get_json,
                                content_type='application/json')
    return HttpResponse('501')
Exemplo n.º 6
0
def get_possible_languages(self):
    articles = Article.objects.filter(initial=self)
    existed_languages = copy.deepcopy(languages_dict)
    for article in articles:
        if Article.objects.language_exist(self.keywords, article.language):
            del existed_languages[article.language]
    collect_languages = []
    for LANGUAGE in LANGUAGES:
        if LANGUAGE[0] in existed_languages != True:
            collect_languages.append(
                Collect(code=LANGUAGE[0], label=LANGUAGE[1]).obj)
    return collect_languages
Exemplo n.º 7
0
def editLastName(request):
    if request.method == 'POST':
        try:
            user = get_user_model().objects.get(pk=request.user.pk)
            changed = UserManager().save_last_name(user,
                                                   request.POST['last_name'])
            if changed['success']:
                return HttpResponse(Collect(response='success').get_json(),
                                    content_type='application/json')
            return HttpResponse(Collect(
                response='failure',
                message=str(MessageManager().getMessage(
                    changed['message']))).get_json(),
                                content_type='application/json')
        except:
            return HttpResponse(Collect(
                response='failure',
                message=str(MessageManager().getMessage(
                    'problem_with_save'))).get_json(),
                                content_type='application/json')
    return HttpResponse('501')
Exemplo n.º 8
0
def getArticleCategories(request, *args, **kwargs):
    if request.method == 'GET':
        article_categories = ArticleCategoryManager().get_article_categories(
            request)
        #        article_categories = serialize('json', article_categories)
        collect_article_categories = {}
        index = 0
        for article_category in article_categories:
            collect_article_categories[index] = Collect(
                name=article_category.name, value=article_category.pk).obj
            index += 1
        collect_article_categories = json.dumps(collect_article_categories)
        return HttpResponse(collect_article_categories,
                            content_type='application/json')
    return HttpResponse('501')