Ejemplo n.º 1
0
 def setUp(self):
     self.user = CustomUser(username="******", password="******").save()
     self.id_user = CustomUser.objects.get(username="******").id
     self.research_user_url = reverse("research_user", args=['test'])
     self.create_subscribed_url = reverse("create_subscribed", args=['testuser'])
     self.all_info_user = reverse("all_info_user", args=[self.id_user])
     self.data_post_subscribe = {"id_receiving": self.id_user}
Ejemplo n.º 2
0
 def setUp(self):
     self.user = CustomUser(username="******", password="******")
     self.user.save()
     self.create_like_article_url = reverse("create_like_article", args=[1, 'testuser'])
     self.data_like_article = {
         "reaction": 1
     }
Ejemplo n.º 3
0
def register(request):
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid() and not request.user.is_authenticated():
            data = form.cleaned_data
            new_user = User.objects.create_user(username=data['nickname'],
                                                password=data['password'])
            new = CustomUser(user=new_user,
                             sex=data.get('sex'),
                             phone=data.get('phone'))
            new.save()
            login(
                request,
                authenticate(username=new_user.username,
                             password=data.get('password2')))
            _return = {'message': '感谢您的注册'}
            _return.update(get_header(request))
            return render(request, 'redirect.html', _return)
        else:
            return render(request, 'register.html', {'form': form})
    elif request.method == 'GET':
        if request.user.is_authenticated():
            return render(request, 'redirect.html', {'message': '您已登陆'})
        form = RegisterForm()
        _return = {'form': form}
        _return.update(get_header(request))
        return render(request, 'register.html', _return)
Ejemplo n.º 4
0
 def setUp(self):
     self.list_categories = ['boisson', 'tartine', 'sandwich', 'viande']
     self.list_products = ['coca', 'tartine nutella', 'club', 'entrecote']
     self.command = Command()
     self.login = CustomUser(username='******',
                             email='*****@*****.**',
                             password='******')
     self.login.save()
Ejemplo n.º 5
0
    def test_get_myaccount_with_bad_id(self):
        self.client.force_login(CustomUser.objects.get_or_create(username='******')[0])
        CustomUser(username="******").save()
        myaccount_url = reverse('myaccount', args=[CustomUser.objects.all()[1].id])
        account_url = reverse('account', args=[CustomUser.objects.all()[1].id])
        response = self.client.get(myaccount_url)

        self.assertRedirects(response, account_url, status_code=302)
Ejemplo n.º 6
0
 def setUp(self):
     self.user = CustomUser(username="******", password="******")
     self.user.save()
     self.create_article_url = reverse("create_article")
     self.categories = Categories.objects.get_or_create(id=64)
     self.data_article = {
         "title": "testTile",
         "content_article": "test content",
         "id_category": 64
     }
Ejemplo n.º 7
0
 def post(self, request):
     serializer = self.serializer_class(data=request.data)
     if serializer.is_valid():
         logger.info("Valid incoming data")
         username = serializer.data['username']
         password1 = serializer.data['password1']
         password2 = serializer.data['password2']
         email = serializer.data['email']
         user = CustomUser(username=username,
                           password=password1,
                           email=email)
         user.save()
         return Response(status=201)
     else:
         return Response(status=400)
Ejemplo n.º 8
0
 def setUp(self):
     CustomUser(username="******").save()
     Categories(name_category="TestCategory").save()
     Article(
         title="TestTitle",
         content_article="Test Content",
         id_category=Categories.objects.all()[0],
         id_user=CustomUser.objects.all()[0],
     ).save()
     Comment(
         id_article=Article.objects.all()[0],
         id_user=CustomUser.objects.all()[0],
         content_comment="test comment",
     ).save()
     self.all_data_article = AllDataArticle()
     self.all_data_comment = AllDataComment()
     self.obj_article = Article.objects.all()
     self.obj_comment = Comment.objects.all()
Ejemplo n.º 9
0
 def setUp(self):
     self.user = CustomUser(username="******", password="******")
     self.user.save()
     self.category = Categories(name_category="TestCategory")
     self.category.save()
     self.article = Article(
         title="TestTitle",
         content_article="Test Content",
         id_category=self.category,
         id_user=self.user,
     ).save()
     self.get_all_url = reverse("getAll",
                                args=[Article.objects.all()[0].id, 1])
     self.create_like_comment_url = reverse("create_like_comment",
                                            args=[0, 'testuser'])
     self.create_comment_url = reverse("Create_comment",
                                       args=[0, 'testuser'])
     self.data_like_comment = {"recation_comment": 1}
     self.data_comment = {"content_comment": "test comment"}
Ejemplo n.º 10
0
 def setUp(self):
     self.user = CustomUser(username="******", password="******")
     self.user.save()
Ejemplo n.º 11
0
    def post(self, request, format=None):

        requested_data = json.loads(request.body)
        print(requested_data)
        # print(request.data["image"])
        """ insert into base user """
        username = requested_data["org_id"]
        email = requested_data["org_id"]
        password = requested_data["org_password"]
        base_user = CustomUser(username=username,
                               email=email,
                               is_normaluser=False)
        base_user.set_password(password)
        # base_user.save()

        get_org = CustomUser.objects.get(username=username)
        print("get organization", get_org.id)

        try:
            """ getting request data """
            org_type = requested_data['type']
            org_category = requested_data["org_category"]
            org_name = requested_data["name"]
            org_address = requested_data["address"]
            org_image = requested_data["image"]
            org_description = requested_data["description"]
            website = requested_data["website"]
            main_coordinator_name = requested_data["main_coordinator_name"]
            main_coordinator_phone = requested_data["main_coordinator_phone"]
            main_coordinator_email = requested_data["main_coordinator_email"]
            sub_coordinator_name = requested_data["sub_coordinator_name"]
            sub_coordinator_phone = requested_data["sub_coordinator_phone"]
            sub_coordinator_email = requested_data["sub_coordinator_email"]
            event_team = requested_data["team"]
            event_manager_name = requested_data["manager_name"]
            event_manager_phone = requested_data["manager_phone"]
            """ update & saving into organization table """
            Organization.objects.filter(user=get_org.id).update(
                type=org_type,
                org_category=org_category,
                name=org_name,
                address=org_address,
                image=org_image,
                description=org_description,
                website=website,
                main_coordinator_name=main_coordinator_name,
                main_coordinator_phone=main_coordinator_phone,
                main_coordinator_email=main_coordinator_email,
                sub_coordinator_name=sub_coordinator_name,
                sub_coordinator_phone=sub_coordinator_phone,
                sub_coordinator_email=sub_coordinator_email,
                team=event_team,
                manager_name=event_manager_name,
                manager_phone=event_manager_phone,
            )

            return Response({"msg": "adding organisation data successfully"},
                            status=status.HTTP_201_CREATED)

        except Exception as e:
            print(e)
            return Response({"msg": "failed"},
                            status=status.HTTP_404_NOT_FOUND)
Ejemplo n.º 12
0
    def post(self, request, format=None):

        requested_data = json.loads(request.body)

        """ insert into base user """
        username = requested_data["org_id"]
        email = requested_data["org_id"]
        password = requested_data["org_password"]
        # CustomUser.objects.filter(username=username,email=email, is_normaluser=False).update_or_create(password=password)
        try:
            base_user = CustomUser(username=username,
                                                  email=email, is_normaluser=False)
            base_user.set_password(password)
            base_user.save()
        except:
            return Response({"msg": "failed", "error": "username " + username + " already exists"},
                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)

        get_org = CustomUser.objects.get(username=username)
        print("get organization", get_org.id)

        try:
            """ getting request data """
            org_type = requested_data['type']
            org_category = requested_data["org_category"]
            org_name = requested_data["name"]
            org_address = requested_data["address"]
            org_image = utils.save_to_file(requested_data["image"], utils.replace_str_with_us(org_name))
            org_description = requested_data["description"]
            website = requested_data["website"]
            main_coordinator_name = requested_data["main_coordinator_name"]
            main_coordinator_phone = requested_data["main_coordinator_phone"]
            main_coordinator_email = requested_data["main_coordinator_email"]
            sub_coordinator_name = requested_data["sub_coordinator_name"]
            sub_coordinator_phone = requested_data["sub_coordinator_phone"]
            sub_coordinator_email = requested_data["sub_coordinator_email"]
            # event_team = requested_data["team"]
            # event_manager_name = requested_data["manager_name"]
            # event_manager_phone = requested_data["manager_phone"]

            """ update & saving into organization table """
            Organization.objects.filter(user=get_org.id).update(
                type = org_type,
                org_category = org_category,
                name = org_name,
                address = org_address,
                image = org_image,
                description = org_description,
                website = website,
                main_coordinator_name = main_coordinator_name,
                main_coordinator_phone = main_coordinator_phone,
                main_coordinator_email = main_coordinator_email,
                sub_coordinator_name = sub_coordinator_name,
                sub_coordinator_phone = sub_coordinator_phone,
                sub_coordinator_email = sub_coordinator_email,
                # team = event_team,
                # manager_name = event_manager_name,
                # manager_phone = event_manager_phone,
            )

            return Response({"msg": "adding organisation data successfully"},
                            status=status.HTTP_201_CREATED)

        except Exception as e:
            print(e)
            return Response({"msg": "failed"},
                            status=status.HTTP_404_NOT_FOUND)