Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excel #31

Merged
merged 3 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 33 additions & 37 deletions GD/messages.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,43 @@

# talk and work shop
CAPACITY_IS_FULL= 'ظرفیت پر است'
USER_HAS_ALREADY_ENROLLED='شما قبلا ثبت نام کرده اید'
SUCCESSFULLY_ADDED='باموفقیت اضافه شد'
NO_ANY_SERVICES='هیچ سرویسی وجود ندارد'
INACTIVE='غیرفعال است'

CAPACITY_IS_FULL = 'ظرفیت پر است'
USER_HAS_ALREADY_ENROLLED = 'شما قبلا ثبت نام کرده اید'
SUCCESSFULLY_ADDED = 'باموفقیت اضافه شد'
NO_ANY_SERVICES = 'هیچ سرویسی وجود ندارد'
INACTIVE = 'غیرفعال است'

# user and activation
USER_DELETED_SUCCESSFULLY='یوزر باموقیت حذف شد'
LOG_OUT_FAILD='خروج ناموفق'
DUPLICATE_USER_ERROR='یوزری با این مشخصات قبلا ثبت شده است'
USER_LOGED_OUT_SUCCESSFULLY='با موفقیت خارج شدید'
USER_ACTIVED='یوزر فعال شد'
USER_NOT_FOUND='یوزری پیدا نشد'
USER_CREATED_SUCCESSFULLY='یوزر با موفقیت ثبت شد'
USER_DELETED_SUCCESSFULLY = 'یوزر باموقیت حذف شد'
LOG_OUT_FAILD = 'خروج ناموفق'
DUPLICATE_USER_ERROR = 'یوزری با این مشخصات قبلا ثبت شده است'
USER_LOGED_OUT_SUCCESSFULLY = 'با موفقیت خارج شدید'
USER_ACTIVED = 'یوزر فعال شد'
USER_NOT_FOUND = 'یوزری پیدا نشد'
USER_CREATED_SUCCESSFULLY = 'یوزر با موفقیت ثبت شد'

# payment and shopping_cart
WORKSHOP_CAPACITY_IS_FULL='\nظرفیت این کارگاه پر است \nلطفا این کارگاه را از سبد خود پاک کنید'
SHOPPING_CART_EMPTY= 'سبد خرید شما خالی است'
COUPON_FINISHED='ظرفیت این کد تخفیف تمام شده است'
COUPON_DOSE_NOT_EXIST='این کد تخفیف وجود ندارد و غیر معتبر هست'
CREATING_PAYMENT_UNSUCCESS='متاسفانه پرداخت ساخته نشد \n لطفا مجدد تلاش کنید'
INACTIVE_WORKSHOP_EXISTS= 'کارگاهی غیرفعال در سبد خرید شما وجود دارد!\n آن را حذف کنید و دوباره امتحان کنید.'
WORKSHOP_CAPACITY_IS_FULL = '\nظرفیت این کارگاه پر است \nلطفا این کارگاه را از سبد خود پاک کنید'
SHOPPING_CART_EMPTY = 'سبد خرید شما خالی است'
COUPON_FINISHED = 'ظرفیت این کد تخفیف تمام شده است'
COUPON_DOSE_NOT_EXIST = 'این کد تخفیف وجود ندارد و غیر معتبر هست'
CREATING_PAYMENT_UNSUCCESS = 'متاسفانه پرداخت ساخته نشد \n لطفا مجدد تلاش کنید'
INACTIVE_WORKSHOP_EXISTS = 'کارگاهی غیرفعال در سبد خرید شما وجود دارد!\n آن را حذف کنید و دوباره امتحان کنید.'
# competition
ADDED_TO_COMPETITION='باموفقیت به مسابقه اضافه شدید'
ALREADY_REGISTERED_IN_THE_COMPETITION='شما قبلا در مسابقه ثبت نام کرده اید'

ADDED_TO_COMPETITION = 'باموفقیت به مسابقه اضافه شدید'
ALREADY_REGISTERED_IN_THE_COMPETITION = 'شما قبلا در مسابقه ثبت نام کرده اید'

# team
REQUESTED_USER_IS_NOT_REGISTERED_OR_ALREADY_HAS_A_TEAM='کاربر درخواستی شما یا تیم دارد یا ثبت نام نکرده است'
YOU_ALREADY_HAVE_A_TEAM='شما در حال حاضر تیم دارید'
COUNT_OF_USER_MEMBERS_MUST_BE_BETWEEN='تعداد اعضای گروه باید بین ۲ تا ۵ باشد'
USER_X_HAS_TEAM=' کاربر {user} تیم دارد'
USER_ALREADY_HAS_A_TEAM='کاربر تیم دارد'
TEAM_ACTIVED='تیم فعال شد'
TEAM_NOT_FOUND='تیم پیدا نشد'
TEAM_IS_FULL='تیم پر است'
TEAM_IS_REJECTED='تیم رد شده است'
REQUESTED_USER_IS_NOT_REGISTERED_OR_ALREADY_HAS_A_TEAM = 'کاربر درخواستی شما یا تیم دارد یا ثبت نام نکرده است'
YOU_ALREADY_HAVE_A_TEAM = 'شما در حال حاضر تیم دارید'
COUNT_OF_USER_MEMBERS_MUST_BE_BETWEEN = 'تعداد اعضای گروه باید بین ۲ تا ۵ باشد'
USER_X_HAS_TEAM = ' کاربر {user} تیم دارد'
USER_ALREADY_HAS_A_TEAM = 'کاربر تیم دارد'
TEAM_ACTIVED = 'تیم فعال شد'
TEAM_NOT_FOUND = 'تیم پیدا نشد'
TEAM_IS_FULL = 'تیم پر است'
TEAM_IS_REJECTED = 'تیم رد شده است'
TEAM_NOT_ACCEPTED = 'تیم فعال نیست'

# general
CORRECT_THE_ERRORS='لطفا مشخصات را کامل و به درستی وارد کنید'
EMPTY='هیچ رکوردی وجود ندارد'
SOMETHING_IS_WRONG='مشکلی وجود دارد'


CORRECT_THE_ERRORS = 'لطفا مشخصات را کامل و به درستی وارد کنید'
EMPTY = 'هیچ رکوردی وجود ندارد'
SOMETHING_IS_WRONG = 'مشکلی وجود دارد'
3 changes: 2 additions & 1 deletion GD/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
'rest_framework_simplejwt.token_blacklist',
'corsheaders',
'tinymce',
'drf_yasg'
'drf_yasg',
'solo',
# 'anymail'
]

Expand Down
21 changes: 9 additions & 12 deletions core/admin.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
from datetime import timezone

import jdatetime
from dill import objects
from django.contrib import admin
from solo.admin import SingletonModelAdmin

from core.models import (
Assistant,
Workshop,
Presenter,
EventService,
Talk,
Payment,
Coupon,
PAYMENT_STATES
Coupon, SingletonCompetition,
)
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
from tasks.tasks import reminder_email_task

import tempfile
import zipfile
from django.http import HttpResponse, JsonResponse
import csv
from django.http import JsonResponse


class PresenterTalkInline(admin.TabularInline):
Expand Down Expand Up @@ -232,7 +225,8 @@ class EventServiceAdmin(admin.ModelAdmin):
'fields': (
'workshop',
'talk',
'payment'
'competition',
'payment',
)
}
)
Expand All @@ -250,3 +244,6 @@ class CouponAdmin(admin.ModelAdmin):
'name', 'count', 'percentage'
)
list_display = ['name', 'count', 'percentage']


admin.site.register(SingletonCompetition, SingletonModelAdmin)
54 changes: 51 additions & 3 deletions core/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from django.db import models
from rest_framework.exceptions import ValidationError
from datetime import datetime

from solo.models import SingletonModel

from GD.settings.base import AUTH_USER_MODEL, PAYWALL
from .validators import validate_file_extension
from tinymce.models import HTMLField

IDPAY_STATUS = [
Expand Down Expand Up @@ -43,6 +45,7 @@
SERVICE_TYPE = [
('WS', 'WORKSHOP'),
('TK', 'TALK'),
('CP', 'COMPETITION')
]

LEVEL = [
Expand Down Expand Up @@ -160,6 +163,44 @@ def __str__(self):
return self.title


class SingletonCompetition(SingletonModel):
title = models.CharField(max_length=100, blank=False, default="Game Craft Competition")
start = models.DateTimeField(blank=False, default=datetime(year=2024, month=1, day=1))
end = models.DateTimeField(blank=False, default=datetime(year=2024, month=1, day=1))
content = HTMLField(blank=True)
capacity = models.IntegerField(blank=False, default=60)
is_online = models.BooleanField(blank=False, default=False)
presentation_link = models.URLField(blank=True)
cost = models.FloatField(blank=False, default=0)
files = models.URLField(default=None, blank=True, null=True)
is_registration_active = models.BooleanField(blank=False, default=False)

def clean(self):
if self.cost < 0:
raise ValidationError("cost cann't be a negative number.")
if self.start > self.end:
raise ValidationError("end of the service can not be before beginning")

def get_total_services(self):
return self.services.count()

def get_is_registration_active(self):
return self.is_registration_active

def get_services(self):
return self.services.all()

def get_remain_capacity(self):
registered_user = self.services.filter(payment_state='CM').count()
return self.capacity - int(registered_user)

def registered(self):
return int(self.services.filter(payment_state='CM').count())

def __str__(self):
return self.title


class Coupon(models.Model):
name = models.CharField(max_length=50, primary_key=True, help_text="don't use / in the name!!!")
count = models.PositiveIntegerField(null=False, blank=False)
Expand Down Expand Up @@ -218,16 +259,23 @@ class EventService(models.Model):
Talk, blank=True, on_delete=models.CASCADE, related_name='services', null=True)
workshop = models.ForeignKey(
Workshop, blank=True, on_delete=models.CASCADE, related_name='services', null=True)
competition = models.ForeignKey(
SingletonCompetition, blank=True, on_delete=models.CASCADE, related_name='services', null=True)

user = models.ForeignKey(
AUTH_USER_MODEL, on_delete=models.CASCADE, blank=True, related_name='services', null=True)

def clean(self):
if self.service_type == 'WS':
if self.workshop == None or self.talk != None:
if self.workshop == None or self.talk != None or self.competition != None:
raise ValidationError(
'service type must match with selected service!!!')
if self.service_type == 'TK':
if self.talk == None or self.workshop != None:
if self.talk == None or self.workshop != None or self.competition != None:
raise ValidationError(
'service type must match with selected service!!!')
if self.service_type == 'CP':
if self.competition == None or self.workshop != None or self.talk != None:
raise ValidationError(
'service type must match with selected service!!!')

Expand Down
39 changes: 23 additions & 16 deletions core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,17 @@ def payment(self, request):
result['code'])
payment.coupon = coupon
payment.save()
if PAYWALL != 'idpay':
_code = result['code']
_status = result['status']
result = {
"link": PayPingPeymentLinkGenerator(_code),
"status": _status
}
return self.set_response(
message=None, data=result, status_code=status.HTTP_200_OK
)
# return redirect('http://gamecraft.ce.aut.ac.ir')

if PAYWALL != 'idpay':
_code = result['code']
_status = result['status']
result = {
"link": PayPingPeymentLinkGenerator(_code),
"status": _status
}
return self.set_response(
message=None, data=result, status_code=status.HTTP_200_OK
)
else:
payment.delete()
if coupon:
Expand Down Expand Up @@ -187,12 +187,15 @@ def verify(self, request):

if any(result_status == status_code for status_code in
(IDPAY_STATUS_100, IDPAY_STATUS_101, IDPAY_STATUS_200)):
services = EventService.objects.select_related(
'workshop').filter(payment=payment)
services = EventService.objects.filter(payment=payment)
for service in services:
service.payment_state = 'CM'
service.workshop.save()
if service.workshop:
service.workshop.save()
elif service.competition:
service.competition.save()
service.save()

payment.status = result_status
payment.original_data = json.dumps(result)
payment.verify_trackID = result['track_id']
Expand Down Expand Up @@ -242,11 +245,15 @@ def verify(self, request):
_payment.card_number = result['cardNumber']
_payment.hashed_card_number = result["cardHashPan"]
_payment.payment_trackID = _payment.payment_id
services = EventService.objects.select_related('workshop').filter(payment=_payment)
services = EventService.objects.filter(payment=_payment)
for service in services:
service.payment_state = 'CM'
service.workshop.save()
if service.workshop:
service.workshop.save()
elif service.competition:
service.competition.save()
service.save()

_payment.status = result['status']
_payment.original_data = json.dumps(result)
_payment.verify_trackID = _payment.payment_id
Expand Down
4 changes: 2 additions & 2 deletions game/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from user.models import SiteUser, Team
from user.serializers import UserSerializerMinimal
from django.core.validators import MaxValueValidator, MinValueValidator
from user.serializers import TeamSerialzer
from user.serializers import TeamSerializer
from rest_framework.exceptions import ValidationError
from decouple import config

Expand Down Expand Up @@ -119,7 +119,7 @@ def get_likes(self, object):


def to_representation(self, obj):
self.fields["team"] = TeamSerialzer()
self.fields["team"] = TeamSerializer()

return super(GameSerializer, self).to_representation(obj)

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ django-debug-toolbar==4.4.6
django-excel-response==2.0.5
django-extensions==3.2.3
django-filter==24.2
django-solo==2.3.0
django-tinymce==4.1.0
djangorestframework==3.15.2
djangorestframework-simplejwt==5.3.1
Expand Down
31 changes: 25 additions & 6 deletions user/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def export_selected_users(self, request, queryset):

def export_selected_services(self, request, queryset):
data = []
headers = ['Username / Email', 'Phone Number', 'Name', 'Talk / workshop']
headers = ['Email', 'Phone Number', 'Name', 'Talk / workshop']

for user in queryset:
for service in user.services.all():
Expand Down Expand Up @@ -107,6 +107,22 @@ class UserTeamInline(admin.TabularInline):

@admin.register(Team)
class TeamAdmin(admin.ModelAdmin):
def export_enrolled_teams(self, request, queryset):
data = []
headers = ['Email', 'Phone Number', 'Name', 'Team']

for team in queryset.all():
if team.get_payment_state() == "COMPLETED":
for user in team.members.all():
data.append([user.email, user.phone_number, user.first_name, team.name])

data.sort(key=lambda x: x[3])
data.insert(0, headers)
return ExcelResponse(data=data, worksheet_name="Teams", output_filename="teams")

def payment_state(self, obj):
return obj.get_payment_state()

fieldsets = (
(None, {
"fields": (
Expand All @@ -116,17 +132,20 @@ class TeamAdmin(admin.ModelAdmin):
(
'register state', {
'fields': (
'state', 'team_activation'
'state', 'team_activation', 'payment_state'
)
}
)
)
list_display = ['id', 'name', 'state', 'member_count']

actions = ['export_enrolled_teams']
export_enrolled_teams.short_description = 'Export enrolled teams'
actions_on_top = True

readonly_fields = ['payment_state', ]
list_display = ['id', 'name', 'state', 'member_count']
list_filter = ['state']
inlines = [
UserTeamInline,
]
inlines = [UserTeamInline, ]


admin.site.register(SiteUser, UserAdminConfig)
Loading
Loading