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

随意填写 #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

DimLight1998
Copy link

No description provided.


# Create your views here.

# 登录
class adminLogin(APIView):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class name should use PascalCase.

def get(self):
# if self.request.user.is_authenticated():
activity_List = []
activites = Activity.objects.all()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use built-in objects filtering functions of django?

ticket_List = Ticket.objects.filter(activity=activity)
bookedTickets = 0
usedTickets = 0
for t in ticket_List:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use built-in counting functions of django?

raise ValidateError('Not found')
activity = activity_list[0]
if(activity.status != Activity.STATUS_PUBLISHED):
raise ValidateError("活动已截止")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a ValidateError?

for index in image.chunks():
f.write(index)
f.close()
return SITE_DOMAIN + '/img/activityImage/' + image.name
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use os.path.join.


allActs = Activity.objects.all()
for a in allActs:
if a not in acts:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use built-in functions.

unique_id = uuid.uuid5(uuid.NAMESPACE_DNS,self.user.student_id + activity.name + str(currentTime))
Ticket.objects.create(student_id = self.user.student_id, unique_id = unique_id,
activity = activity, status = Ticket.STATUS_VALID)
activity.remain_tickets -= 1
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use lock.

@@ -52,10 +82,10 @@ def reply_text(self, content):
))

def reply_news(self, articles):
if len(articles) > 10:
self.logger.warn('Reply with %d articles, keep only 10', len(articles))
if len(articles) > 8:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move 8 to a variable.

Copy link
Author

@DimLight1998 DimLight1998 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • No authenticating for admin.
  • Use unified naming convention.
  • Add to_json and create_from_json method to models to reduce meaningless code when get information of create object.
  • Don't comment code when committing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant