Minor update on data populator
This commit is contained in:
parent
36b18b2674
commit
bdcdbddebe
@ -1,8 +0,0 @@
|
||||
from rest_framework import serializers
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
|
||||
class UserSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = get_user_model()
|
||||
fields = "__all__"
|
||||
@ -1,8 +0,0 @@
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
app_name = "accounts-api"
|
||||
|
||||
urlpatterns = [
|
||||
path("", views.UserListAPIView.as_view(), name="users-api"),
|
||||
]
|
||||
@ -1,23 +0,0 @@
|
||||
from rest_framework import generics
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
from .serializers import UserSerializer
|
||||
|
||||
|
||||
class UserListAPIView(generics.ListAPIView):
|
||||
lookup_field = "id"
|
||||
serializer_class = UserSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = get_user_model().objects.all()
|
||||
query = self.request.GET.get("q")
|
||||
if query is not None:
|
||||
queryset = queryset.filter(username__iexact=q)
|
||||
return queryset
|
||||
|
||||
|
||||
class UserDetailView(generics.RetrieveAPIView):
|
||||
User = get_user_model()
|
||||
lookup_field = "id"
|
||||
queryset = User.objects.all()
|
||||
model = User
|
||||
@ -26,7 +26,6 @@ urlpatterns += i18n_patterns(
|
||||
path("search/", include("search.urls")),
|
||||
path("quiz/", include("quiz.urls")),
|
||||
path("payments/", include("payments.urls")),
|
||||
path("accounts/api/", include("accounts.api.urls", namespace="accounts-api")),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@ -1,10 +0,0 @@
|
||||
# from rest_framework import serializers
|
||||
# from django.contrib.auth.views import get_user_model
|
||||
#
|
||||
# User = get_user_model()
|
||||
#
|
||||
#
|
||||
# class UserSerializer(serializers.ModelSerializer):
|
||||
# class Meta:
|
||||
# model = User
|
||||
# fields = '__all__'
|
||||
@ -1,97 +0,0 @@
|
||||
# #! /usr/bin/env python3.6
|
||||
|
||||
# """
|
||||
# server.py
|
||||
# Stripe Sample.
|
||||
# Python 3.6 or newer required.
|
||||
# """
|
||||
|
||||
# import stripe
|
||||
# import json
|
||||
# import os
|
||||
|
||||
# from flask import Flask, render_template, jsonify, request, send_from_directory
|
||||
# from dotenv import load_dotenv, find_dotenv
|
||||
|
||||
# # Set your secret key. Remember to switch to your live secret key in production.
|
||||
# # See your keys here: https://dashboard.stripe.com/account/apikeys
|
||||
# stripe.api_key = "sk_test_51IcEVZHbzY4cUA9T3BZdDayN4gmbJyXuaLCzpLT15HZoOmC17G7CxeEdXeIHSWyhYfxpljsclzzjsFukYNqJTbrW00tv3qIbN2"
|
||||
|
||||
# intent = stripe.PaymentIntent.create(
|
||||
# amount=1099,
|
||||
# currency='usd',
|
||||
# )
|
||||
|
||||
# # Setup Stripe python client library
|
||||
# load_dotenv(find_dotenv())
|
||||
# stripe.api_key = os.getenv('STRIPE_SECRET_KEY')
|
||||
# stripe.api_version = os.getenv('STRIPE_API_VERSION')
|
||||
|
||||
# static_dir = str(os.path.abspath(os.path.join(__file__ , "..", os.getenv("STATIC_DIR"))))
|
||||
# app = Flask(__name__, static_folder=static_dir,
|
||||
# static_url_path="", template_folder=static_dir)
|
||||
|
||||
|
||||
# @app.route('/checkout', methods=['GET'])
|
||||
# def get_checkout_page():
|
||||
# # Display checkout page
|
||||
# return render_template('index.html')
|
||||
|
||||
|
||||
# def calculate_order_amount(items):
|
||||
# # Replace this constant with a calculation of the order's amount
|
||||
# # Calculate the order total on the server to prevent
|
||||
# # people from directly manipulating the amount on the client
|
||||
# return 1400
|
||||
|
||||
|
||||
# @app.route('/create-payment-intent', methods=['POST'])
|
||||
# def create_payment():
|
||||
# data = json.loads(request.data)
|
||||
# # Create a PaymentIntent with the order amount and currency
|
||||
# intent = stripe.PaymentIntent.create(
|
||||
# amount=calculate_order_amount(data['items']),
|
||||
# currency=data['currency']
|
||||
# )
|
||||
|
||||
# try:
|
||||
# # Send publishable key and PaymentIntent details to client
|
||||
# return jsonify({'publishableKey': os.getenv('STRIPE_PUBLISHABLE_KEY'), 'clientSecret': intent.client_secret})
|
||||
# except Exception as e:
|
||||
# return jsonify(error=str(e)), 403
|
||||
|
||||
|
||||
# @app.route('/webhook', methods=['POST'])
|
||||
# def webhook_received():
|
||||
# # You can use webhooks to receive information about asynchronous payment events.
|
||||
# # For more about our webhook events check out https://stripe.com/docs/webhooks.
|
||||
# webhook_secret = os.getenv('STRIPE_WEBHOOK_SECRET')
|
||||
# request_data = json.loads(request.data)
|
||||
|
||||
# if webhook_secret:
|
||||
# # Retrieve the event by verifying the signature using the raw body and secret if webhook signing is configured.
|
||||
# signature = request.headers.get('stripe-signature')
|
||||
# try:
|
||||
# event = stripe.Webhook.construct_event(
|
||||
# payload=request.data, sig_header=signature, secret=webhook_secret)
|
||||
# data = event['data']
|
||||
# except Exception as e:
|
||||
# return e
|
||||
# # Get the type of webhook event sent - used to check the status of PaymentIntents.
|
||||
# event_type = event['type']
|
||||
# else:
|
||||
# data = request_data['data']
|
||||
# event_type = request_data['type']
|
||||
# data_object = data['object']
|
||||
|
||||
# if event_type == 'payment_intent.succeeded':
|
||||
# print('💰 Payment received!')
|
||||
# # Fulfill any orders, e-mail receipts, etc
|
||||
# # To cancel the payment you will need to issue a Refund (https://stripe.com/docs/api/refunds)
|
||||
# elif event_type == 'payment_intent.payment_failed':
|
||||
# print('❌ Payment failed.')
|
||||
# return jsonify({'status': 'success'})
|
||||
|
||||
|
||||
# if __name__ == '__main__':
|
||||
# app.run()
|
||||
@ -2,4 +2,6 @@
|
||||
|
||||
# Code quality
|
||||
# ------------------------------------------------------------------------------
|
||||
black==22.12.0 # https://github.com/psf/black
|
||||
black==22.12.0 # https://github.com/psf/black
|
||||
factory-boy==3.3.1
|
||||
django-extensions==3.2.3
|
||||
@ -2,7 +2,7 @@ from typing import Type
|
||||
from factory.django import DjangoModelFactory
|
||||
from factory import SubFactory, LazyAttribute, Iterator
|
||||
from faker import Faker
|
||||
|
||||
from django.conf import settings
|
||||
from course.models import (
|
||||
Program,
|
||||
Course,
|
||||
@ -10,7 +10,6 @@ from course.models import (
|
||||
Upload,
|
||||
UploadVideo,
|
||||
CourseOffer,
|
||||
SEMESTER,
|
||||
)
|
||||
from accounts.models import User, DepartmentHead
|
||||
from core.models import Session
|
||||
@ -73,7 +72,7 @@ class CourseFactory(DjangoModelFactory):
|
||||
program: Type[Program] = SubFactory(ProgramFactory)
|
||||
level: str = Iterator(["Beginner", "Intermediate", "Advanced"])
|
||||
year: int = LazyAttribute(lambda x: fake.random_int(min=1, max=4))
|
||||
semester: str = Iterator([choice[0] for choice in SEMESTER])
|
||||
semester: str = Iterator([choice[0] for choice in settings.SEMESTER_CHOICES])
|
||||
is_elective: bool = LazyAttribute(lambda x: fake.boolean())
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user