Last active
February 26, 2020 14:42
-
-
Save volgoweb/5d1782a914f29981358de771aac30289 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###################################################### | |
# To Do: How can we refactor code to make that faster? | |
###################################################### | |
def func(user, moderator_ids): | |
for post in Post.objects.all().order('?'): | |
if user.pk in moderator_ids: | |
post.updated_at = timezone.now() | |
post.save() | |
# | |
###################################################### | |
###################################################### | |
# To Do: What problems can we encounter with? How can you impove the code? | |
###################################################### | |
def withdraw(user_id, amount): | |
balance = UserBalance.objects.get(user_id=user_id) | |
balance.amount -= amount | |
balance.save() | |
send_request_to_paypal(balance.paypal_id, amount) | |
# | |
###################################################### | |
###################################################### | |
# To Do: | |
# 1. Write a code of model `Webinar`, that contains the fields: | |
# - title | |
# - is_published | |
# - starts_at | |
# | |
# 2. Please, write a code of the function `get_nearest_webinar`. The function returns a published webinar that starts in the near future. | |
# 3. Write a code of the function `count_published_webinars`. That returns a number of published webinars. | |
# 4. How you could change the code if the count of published webinars is displayed on the really visited page? | |
# | |
# P.S.: If you need use additional classes you are welcome. | |
###################################################### | |
def get_nearest_webinar(): | |
pass | |
def count_published_webinars(): | |
pass | |
# | |
###################################################### | |
###################################################### | |
# Please, add the processing of probably exceptions and logging: | |
###################################################### | |
# | |
@login_required() | |
def disable_subscription(request): | |
account = Account.objects.get(user=request.user) | |
if request.method == 'POST': | |
if 'do_disable' in request.POST: | |
account.switch_to_free() | |
return HttpResponseRedirect(reverse('app:my_account')) | |
return render(request, 'theme/disable_subscription.html') | |
# | |
###################################################### | |
###################################################### | |
# There is a really visited site. Many uWSGI workers. What problem will you probably encounter? | |
# What changes may you suggest? | |
###################################################### | |
# | |
def increment_views(webinar_id): | |
# ... | |
w = Webinar.objects.get(pk=webinar_id) | |
w.views_count += 1 | |
w.save() | |
#... | |
# | |
###################################################### | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment