Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ramibch committed Jan 3, 2024
1 parent 8d90305 commit 1d3401e
Show file tree
Hide file tree
Showing 22 changed files with 136 additions and 50 deletions.
2 changes: 1 addition & 1 deletion cms/models/flex.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@


class FlexPage(Page):
template = "cms/page.html"
template = "cms/flexpage.html"

body = FullStreamBlock()
2 changes: 1 addition & 1 deletion cms/models/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class HomePage(Page):
template = "cms/page.html"
template = "cms/flexpage.html"

subpage_types = [
"cms.BlogIndexPage",
Expand Down
18 changes: 3 additions & 15 deletions cms/models/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,14 @@
from wagtail.models import Page

from ..streams import TextStreamBlock
from django.conf import settings


class TextPage(Page):
template = "cms/page.html"
template = "cms/textpage.html"

body = StreamField(
TextStreamBlock(
features=[
"h1",
"h2",
"h3",
"h4",
"italic",
"bold",
"ul",
"ol",
"link",
"document-link",
]
),
TextStreamBlock(features=settings.CMS_RICHTEXT_FEATURES),
verbose_name="Home content block",
null=True,
blank=True,
Expand Down
12 changes: 2 additions & 10 deletions core/forms/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,10 @@
class CustomUserCreationForm(UserCreationForm):
class Meta:
model = User
fields = (
"email",
"username",
)
fields = ("email", "username")


class CustomUserChangeForm(UserChangeForm):
class Meta:
model = get_user_model()
fields = (
# "email",
"username",
"first_name",
"last_name",
)
fields = ("username", "first_name", "last_name")
17 changes: 17 additions & 0 deletions core/migrations/0023_user_asked_to_verify_email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.5 on 2024-01-03 21:36

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("core", "0022_remove_userpremiumplan_customer"),
]

operations = [
migrations.AddField(
model_name="user",
name="asked_to_verify_email",
field=models.BooleanField(default=False),
),
]
10 changes: 10 additions & 0 deletions core/models/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
from django.contrib.auth.models import AbstractUser
from django.db import models
from django.utils.functional import cached_property
from django.urls import reverse

from .plans import FreePlan
from .plans import PremiumPlan


class User(AbstractUser):
avatar_url = models.URLField(null=True, blank=True)
asked_to_verify_email = models.BooleanField(default=False)

@cached_property
def plan(self):
Expand All @@ -23,6 +25,14 @@ def plan(self):
return premiumplan.plan
return FreePlan.get()

@cached_property
def last_user_plan(self):
return self.user_premium_plans.last()

@cached_property
def delete_account_url(self):
return reverse("account_delete", kwargs={"id": self.id})

@cached_property
def fullname(self):
return self.first_name + " " + self.last_name
Expand Down
51 changes: 45 additions & 6 deletions core/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@


from .models.profiles import Profile
from .models.users import User


@db_periodic_task(crontab(hour="0", minute="5"))
Expand Down Expand Up @@ -43,14 +44,14 @@ def notify_to_complete_profile():
if p.fullname is not None:
body += " " + p.fullname
body += ",\n\n"
body += _(
"This is Rami from nicecv.online. I am glad that you have started to take steps to improve the structure and aesthetics of your CV."
)
body += _("This is Rami from nicecv.online.")
body += "\n\n"
body += _("I am glad you want to improve the aesthetics of your CV.")
body += "\n\n"
body += _(
"Unfortunately, your profile is incomplete. It seems that you have decided to abandon the process of creating a CV that will impress recruiters."
"I writing to you because it seems that you decided to abandon the process of creating a CV that will impress recruiters."
)
body += "\n\n"
body += " "
body += _(
"But if you want to complete your profile and download CV templates, visit the site:"
)
Expand All @@ -63,6 +64,44 @@ def notify_to_complete_profile():
m.send(fail_silently=False)


@db_periodic_task(crontab(hour="8", minute="15"))
def ask_to_verify_email():
from allauth.account.models import EmailAddress

users = User.objects.none()
qs = EmailAddress.objects.filter(verified=False, user__asked_to_verify_email=False)

# qs = asked_to_verify_email
for obj in qs:
last_profile = obj.user.profile_set.last()
if last_profile is not None:
try:
activate(last_profile.language)
except:
pass
subject = "Nice CV | " + _("Verify your Email")
body = _("Hi ") + obj.user.fullname
body += "\n\n"
body += _("This is Rami from nicecv.online.")
body += "\n\n"
body += _("Please consider to verify your email:")
body += "\n\n"
body += _("1. Just visit this page: https://nicecv.online/email/")
body += "\n\n"
body += _("2. Click on Re-send Verification")
body += "\n\n"
body += _("3. Go to you Email inbox and confirm your Email Address.")
body += "\n\n"
body += "Thanks."
body += "\n\n"
body += _("Best wishes, Rami.")
m = EmailMessage(subject, body, settings.DEFAULT_FROM_EMAIL, [obj.email])
m.send(fail_silently=False)
users = users.union(obj.user)

users.update(asked_to_verify_email=True)


@db_periodic_task(crontab(hour="0", minute="15"))
def remove_temporal_profiles():
# Delete all temporal profiles
Expand All @@ -80,4 +119,4 @@ def remove_temporal_profiles():

@db_periodic_task(crontab(hour="0", minute="20"))
def remove_expired_sessions():
call_command("clearsessions")
call_command("clearsessions", verbosity=0)
10 changes: 7 additions & 3 deletions core/urls/users.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from django.urls import path

from ..views.users import account_dashboard
from ..views.users import account_edit
from ..views.users import redirect_change_password
from ..views.users import (
account_dashboard,
account_edit,
redirect_change_password,
account_delete,
)


urlpatterns = [
path("account/", account_dashboard, name="account_dashboard"),
path("account/edit/", account_edit, name="account_edit"),
path("account/delete/<int:id>/", account_delete, name="account_delete"),
path("<int:id>/password/", redirect_change_password),
]
16 changes: 16 additions & 0 deletions core/views/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
from django.shortcuts import render
from django.utils.translation import gettext_lazy as _


from django_htmx.http import HttpResponseClientRedirect

from ..forms.users import CustomUserChangeForm
from ..models.users import User

Expand Down Expand Up @@ -40,3 +43,16 @@ def redirect_change_password(request, id):

messages.error(request, _("An error occurred"))
return redirect("/")


@login_required
def account_delete(request, id):
user = User.objects.get(id=id)
if request.user == user:
user.delete()
messages.info(request, _("Account deleted"))
else:
messages.error(
request, _("You are not allowed to delete someone else's account.")
)
return HttpResponseClientRedirect("/")
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ pylint-django==2.5.3
# via -r requirements.in
pylint-plugin-utils==0.8.2
# via pylint-django
pympler==1.0.1
# via -r requirements.in
python-dateutil==2.8.2
# via
# botocore
Expand Down
4 changes: 2 additions & 2 deletions templates/404.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% extends "base.html" %}
{% load static i18n %}
{% block title %}
{% block head_title %}
{% translate "Page not found" %}
{% endblock title %}
{% endblock head_title %}
{% block content %}
<main class="mx-auto flex w-full max-w-7xl flex-auto flex-col justify-center px-6 py-24 sm:py-64 lg:px-8 mt-2">
<p class="text-base font-semibold leading-8 text-indigo-600">404</p>
Expand Down
10 changes: 10 additions & 0 deletions templates/account/account_dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
<h1 class="mt-10 mb-10 text-center text-2xl font-bold leading-9 tracking-tight text-gray-900">
{% translate "Account" %}
</h1>
<p class="mt-2 text-lg leading-8 text-gray-600">
<strong>{{ user.plan.name }}</strong>
{% if user.last_user_plan.expires %}({{ user.last_user_plan.starts }} - {{ user.last_user_plan.expires }}){% endif %}
</p>
<ul>
<li>
<a href="{% url 'account_edit' %}"
Expand All @@ -20,6 +24,12 @@ <h1 class="mt-10 mb-10 text-center text-2xl font-bold leading-9 tracking-tight t
class="mt-5 flex w-full justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">
{% translate "Change E-mail" %}</a>
</li>
<li>
<a hx-delete="{{ request.user.delete_account_url }}"
hx-confirm='{% trans "Are you sure you want to delete your account?" %}'
class="mt-5 flex w-full justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">
{% translate "Delete account" %}</a>
</li>
<li>
<a href="{% url 'account_change_password' %}"
class="mt-5 flex w-full justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">
Expand Down
4 changes: 2 additions & 2 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
{% block css %}
{% endblock css %}
<title>
{% block title %}
{% endblock title %}
{% block head_title %}
{% endblock head_title %}
</title>
</head>
<body hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}' class="h-full">
Expand Down
2 changes: 1 addition & 1 deletion templates/cms/blog/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% load wagtailimages_tags wagtailcore_tags humanize i18n %}
{% block content %}
<!-- header and page.description-->
{% include "cms/blog/_header.html" %}
{% include "cms/partials/header.html" %}
<!-- blog posts -->
<div class="mx-auto mt-2 grid max-w-2xl grid-cols-1 gap-x-8 gap-y-16 pt-10 sm:mt-16 sm:pt-16 lg:mx-0 lg:max-w-none lg:grid-cols-3">
{% for post in posts %}
Expand Down
2 changes: 1 addition & 1 deletion templates/cms/blog/post.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'base.html' %}
{% load wagtailimages_tags wagtailcore_tags humanize i18n %}
{% block content %}
{% include "cms/blog/_header.html" %}
{% include "cms/partials/header.html" %}
<div class=" py-5 sm:px-6">
<div class="-ml-4 -mt-4 flex flex-wrap items-center justify-between sm:flex-nowrap">
{% for author in page.authors %}
Expand Down
4 changes: 2 additions & 2 deletions templates/cms/page.html → templates/cms/flexpage.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'base.html' %}
{% block title %}
{% block head_title %}
{{ page.title }}
{% endblock title %}
{% endblock head_title %}
{% block content %}
{% if page.body %}{{ page.body }}{% endif %}
{% endblock content %}
File renamed without changes.
8 changes: 8 additions & 0 deletions templates/cms/textpage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends 'base.html' %}
{% block head_title %}
{{ page.title }}
{% endblock head_title %}
{% block content %}
{% include "cms/partials/header.html" %}
{% if page.body %}{{ page.body }}{% endif %}
{% endblock content %}
2 changes: 1 addition & 1 deletion templates/plans/detail.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "base.html" %}
{% load i18n l10n djmoney %}
{% block title %}
{% block head_title %}
{% translate "Plan" %} | {{ plan.name }}
{% endblock %}
{% block content %}
Expand Down
2 changes: 1 addition & 1 deletion templates/plans/plan_list.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "base.html" %}
{% load i18n l10n djmoney %}
{% block title %}
{% block head_title %}
{% translate "Pricing" %}
{% endblock %}
{% block content %}
Expand Down
4 changes: 2 additions & 2 deletions templates/profiles/profile_list.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% extends "base.html" %}
{% load i18n humanize %}
{% block title %}
{% block head_title %}
{% translate "Profiles" %}
{% endblock title %}
{% endblock head_title %}
{% block content %}
<h1 class="my-5 text-3xl text-center font-bold tracking-tight text-gray-900 sm:text-4xl">
{% translate "Profiles" %}
Expand Down
4 changes: 2 additions & 2 deletions templates/profiles/profile_update.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{% extends "base.html" %}
{% load static i18n %}
{% block title %}
{% block head_title %}
{% if profile.fullname %}
{{ profile.fullname }}
{% else %}
{% translate "My profile" %}
{% endif %}
{% endblock title %}
{% endblock head_title %}
{% block css %}
<!-- cropper -->
<link rel="stylesheet" href="{% static 'css/cropper.css' %}" />
Expand Down

0 comments on commit 1d3401e

Please sign in to comment.