Skip to content

Commit

Permalink
Merge pull request #1411 from gtech-mulearn/dev-server
Browse files Browse the repository at this point in the history
onboarding flow
  • Loading branch information
adnankattekaden authored Oct 23, 2023
2 parents f8b7d24 + 72eae39 commit 3c40995
Show file tree
Hide file tree
Showing 46 changed files with 2,179 additions and 1,861 deletions.
23 changes: 8 additions & 15 deletions api/dashboard/campus/campus_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,21 +212,14 @@ class WeeklyKarmaAPI(APIView):

@role_required([RoleType.CAMPUS_LEAD.value, RoleType.ENABLER.value])
def get(self, request):
try:
user_id = JWTUtils.fetch_user_id(request)

user_org_link = get_user_college_link(user_id)
user_id = JWTUtils.fetch_user_id(request)

if user_org_link.org is None:
return CustomResponse(
general_message="Campus lead has no college"
).get_failure_response()
user_org_link = get_user_college_link(user_id)

serializer = serializers.WeeklyKarmaSerializer(user_org_link)
return CustomResponse(response=serializer.data).get_success_response()
if user_org_link.org is None:
return CustomResponse(
general_message="Campus lead has no college"
).get_failure_response()

except Exception as e:
raise CustomException(
detail='somthing went wrong',
status_code=403
)
serializer = serializers.WeeklyKarmaSerializer(user_org_link)
return CustomResponse(response=serializer.data).get_success_response()
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from utils.utils import DateTimeUtils
from utils.types import ManagementType


class DynamicRoleCreateSerializer(serializers.ModelSerializer):
type = serializers.CharField(required=True, error_messages={
'required': 'type field must not be left blank.'
Expand Down Expand Up @@ -43,7 +44,8 @@ def validate_type(self, value):
if value not in [type for type in ManagementType.get_all_values()]:
raise serializers.ValidationError("Enter a valid type")
return value



class DynamicRoleListSerializer(serializers.ModelSerializer):
roles = serializers.SerializerMethodField()

Expand All @@ -56,6 +58,7 @@ class Meta:
model = DynamicRole
fields = ["type", "roles"]


class DynamicRoleUpdateSerializer(serializers.ModelSerializer):
new_role = serializers.CharField(required=True, error_messages={
'required': 'new_role field must not be left blank.'
Expand Down Expand Up @@ -83,6 +86,7 @@ def validate_new_role(self, value):
def destroy(self, obj):
obj.delete()


class DynamicUserCreateSerializer(serializers.ModelSerializer):
type = serializers.CharField(required=True, error_messages={
'required': 'type field must not be left blank.'
Expand Down Expand Up @@ -119,7 +123,8 @@ def validate_type(self, value):
if value not in [type for type in ManagementType.get_all_values()]:
raise serializers.ValidationError("Enter a valid type")
return value



class DynamicUserListSerializer(serializers.ModelSerializer):
users = serializers.SerializerMethodField()

Expand All @@ -137,6 +142,7 @@ class Meta:
model = DynamicUser
fields = ["type", "users"]


class DynamicUserUpdateSerializer(serializers.ModelSerializer):
new_user = serializers.CharField(required=True, error_messages={
'required': 'new_user field must not be left blank.'
Expand Down Expand Up @@ -165,6 +171,7 @@ def validate_new_user(self, value):
def destroy(self, obj):
obj.delete()


class RoleDropDownSerializer(serializers.ModelSerializer):
class Meta:
model = Role
Expand Down
42 changes: 30 additions & 12 deletions api/dashboard/error_log/error_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,61 @@
class DownloadErrorLogAPI(APIView):
authentication_classes = [CustomizePermission]

@role_required([RoleType.ADMIN.value, RoleType.FELLOW.value, RoleType.TECH_TEAM.value])
@role_required(
[RoleType.ADMIN.value, RoleType.FELLOW.value, RoleType.TECH_TEAM.value]
)
def get(self, request, log_name):
error_log = f"{log_path}/{log_name}.log"
if os.path.exists(error_log):
response = FileResponse(open(error_log, 'rb'), content_type='application/octet-stream')
response['Content-Disposition'] = f'attachment; filename="{log_name}"'
response = FileResponse(
open(error_log, "rb"), content_type="application/octet-stream"
)
response["Content-Disposition"] = f'attachment; filename="{log_name}"'
return response
return CustomResponse(general_message=f"{log_name} Not Found").get_failure_response()
return CustomResponse(
general_message=f"{log_name} Not Found"
).get_failure_response()


class ViewErrorLogAPI(APIView):
authentication_classes = [CustomizePermission]

@role_required([RoleType.ADMIN.value, RoleType.FELLOW.value, RoleType.TECH_TEAM.value])
@role_required(
[RoleType.ADMIN.value, RoleType.FELLOW.value, RoleType.TECH_TEAM.value]
)
def get(self, request, log_name):
error_log = f"{log_path}/{log_name}.log"
if os.path.exists(error_log):
try:
with open(error_log, 'r') as log_file:
with open(error_log, "r") as log_file:
log_content = log_file.read()
return CustomResponse(response=log_content).get_success_response()
except Exception as e:
return CustomResponse(general_message=f'Error reading log file').get_failure_response()
return CustomResponse(
general_message="Error reading log file"
).get_failure_response()

return CustomResponse(general_message=f"{log_name} Not Found").get_failure_response()
return CustomResponse(
general_message=f"{log_name} Not Found"
).get_failure_response()


class ClearErrorLogAPI(APIView):
def get(self, request, log_name):
error_log = f"{log_path}/{log_name}.log"
if os.path.exists(error_log):
try:
with open(error_log, 'w') as log_file:
with open(error_log, "w") as log_file:
log_file.truncate(0)
return CustomResponse(general_message=f'{log_name} log cleared successfully').get_success_response()
return CustomResponse(
general_message=f"{log_name} log cleared successfully"
).get_success_response()
except Exception as e:
print(e)
return CustomResponse(general_message=f'Error reading log file').get_failure_response()
return CustomResponse(
general_message="Error reading log file"
).get_failure_response()

return CustomResponse(general_message=f"{log_name} Not Found").get_failure_response()
return CustomResponse(
general_message=f"{log_name} Not Found"
).get_failure_response()
54 changes: 6 additions & 48 deletions api/dashboard/ig/dash_ig_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,59 +28,17 @@ class Meta:
]

def get_user_ig_link_ig(self, obj):
return len(obj.user_ig_link_ig.all())
return obj.user_ig_link_ig.all().count()


class InterestGroupCreateSerializer(serializers.ModelSerializer):
class InterestGroupCreateUpdateSerializer(serializers.ModelSerializer):

name = serializers.CharField(
required=True,
error_messages={
'required': 'code field must not be left blank.'
}
)
icon = serializers.CharField(
required=True,
error_messages={
'required': 'icon field must not be left blank.'
}
)

class Meta:
model = InterestGroup
fields = [
"name",
"code",
"icon"
]

def create(self, validated_data):
user_id = self.context.get('user_id')
return InterestGroup.objects.create(
name=validated_data.get('name'),
code=validated_data.get('code'),
icon=validated_data.get('icon'),
updated_by_id=user_id,
created_by_id=user_id,
)


class InterestGroupUpdateSerializer(serializers.ModelSerializer):
class Meta:
model = InterestGroup
fields = [
"name",
"code",
"icon"
]

def update(self, instance, validated_data):
user_id = self.context.get('user_id')
user = User.objects.filter(id=user_id).first()
instance.name = validated_data.get('name')
instance.code = validated_data.get('code')
instance.icon = validated_data.get('icon')
instance.updated_by = user
instance.updated_at = DateTimeUtils.get_current_utc_time()
instance.save()
return instance
"icon",
"created_by",
"updated_by"
]
Loading

0 comments on commit 3c40995

Please sign in to comment.