Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit079d793

Browse files
committed
Add mailing list form to homepage
1 parent02a4815 commit079d793

File tree

13 files changed

+121
-12
lines changed

13 files changed

+121
-12
lines changed

‎backend/book/settings.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
importbirdseye
1717
importdj_database_url
1818
importsnoop
19+
fromdjango.contrib.messagesimportconstantsasmessages
1920

2021
BASE_DIR=Path(__file__).parent.parent
2122

@@ -56,8 +57,19 @@
5657
'allauth.socialaccount',
5758
# 'allauth.socialaccount.providers.facebook',
5859
'django_user_agents',
60+
'crispy_forms',
5961
]
6062

63+
CRISPY_TEMPLATE_PACK='bootstrap4'
64+
65+
MESSAGE_TAGS= {
66+
messages.DEBUG:'alert-info',
67+
messages.INFO:'alert-info',
68+
messages.SUCCESS:'alert-success',
69+
messages.WARNING:'alert-warning',
70+
messages.ERROR:'alert-danger',
71+
}
72+
6173
MIDDLEWARE= [
6274
'django.middleware.security.SecurityMiddleware',
6375
'whitenoise.middleware.WhiteNoiseMiddleware',
@@ -154,6 +166,7 @@
154166
ACCOUNT_SESSION_REMEMBER=True
155167
ACCOUNT_AUTHENTICATION_METHOD='email'
156168
ACCOUNT_UNIQUE_EMAIL=True
169+
ACCOUNT_EMAIL_VERIFICATION='none'
157170

158171
AUTHENTICATION_BACKENDS= (
159172
'django.contrib.auth.backends.ModelBackend',
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Generated by Django 2.2.11 on 2020-03-21 10:57
2+
3+
fromdjango.dbimportmigrations,models
4+
5+
6+
classMigration(migrations.Migration):
7+
8+
dependencies= [
9+
('main','0006_user_developer_mode'),
10+
]
11+
12+
operations= [
13+
migrations.CreateModel(
14+
name='ListEmail',
15+
fields=[
16+
('id',models.AutoField(auto_created=True,primary_key=True,serialize=False,verbose_name='ID')),
17+
('email',models.EmailField(max_length=254)),
18+
],
19+
),
20+
]

‎backend/main/models.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ def step(self):
1818
returngetattr(self.page,self.step_name)
1919

2020

21+
classListEmail(models.Model):
22+
email=models.EmailField()
23+
24+
2125
classCodeEntry(models.Model):
2226
timestamp=models.DateTimeField(auto_now=True)
2327
input=models.TextField()

‎backend/main/templates/account/login.html‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
{% block head_title %}{% trans "Sign In" %}{% endblock %}
77

88
{% block content %}
9+
10+
{% include "messages.html" %}
911

1012
<h1>{% trans "Sign In" %}</h1>
1113

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
{% load account %}
2-
{% load i18n %}
3-
{% user_display user as name %}
4-
{% blocktrans %}Successfully signed in as {{name}}.{% endblocktrans %}

‎backend/main/templates/home.html‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,25 @@ <h1>Welcome to <code>python_init</code>!</h1>
1010
</p>
1111

1212
<p>
13-
This site isintended for demonstration, not large scale usage.
13+
This site iscurrently only ready for demonstration, not large scale usage.
1414
So don't start sharing it with everyone who wants to learn to code.
1515
It's hosted on free, minimal infrastructure that can't handle a lot of load.
1616
</p>
1717

1818
<p>
19+
If you'd like to be updated when the site is ready, enter your email below:
20+
</p>
21+
22+
{% load crispy_forms_tags %}
23+
24+
<formmethod="post">
25+
{% crispy form %}
26+
<buttontype="submit"class="btn btn-success">Submit</button>
27+
</form>
28+
29+
{% include "messages.html" %}
30+
31+
<pstyle="margin-top: 2em">
1932
But please share this with people who are interested in providing free education
2033
and contributing to open source software!
2134
Learn more about the project in the
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{% for message in messages %}
2+
<divclass="alert {{ message.tags }}"role="alert">
3+
{{ message }}
4+
</div>
5+
{% endfor %}

‎backend/main/urls.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
fromdjango.views.genericimportTemplateView
1919

2020
frommain.textimportchapters
21-
frommain.viewsimportapi_view,FrontendAppView
21+
frommain.viewsimportapi_view,FrontendAppView,HomePageView
2222

23-
home_view=TemplateView.as_view(template_name="home.html")
23+
home_view=HomePageView.as_view()
2424
urlpatterns= [
2525
path('api/<method_name>/',api_view),
2626
path('home/',home_view),

‎backend/main/utils.py‎renamed to ‎backend/main/utils/__init__.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
importfunctools
2+
importre
3+
importsys
24
importthreading
35
importtraceback
46
fromfunctoolsimportlru_cache
57
fromioimportStringIO
6-
importre
7-
importsys
88

99
fromlittleutilsimportwithattrs,strip_required_prefix,strip_required_suffix
1010
frommarkdownimportmarkdown

‎backend/main/utils/django.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
fromcrispy_forms.helperimportFormHelper
2+
fromcrispy_forms.layoutimportLayout,Field
3+
fromdjangoimportforms
4+
fromlittleutilsimportsetattrs
5+
6+
7+
classCrispyForm(forms.Form):
8+
helper_attrs= {}
9+
10+
def__init__(self,*args,**kwargs):
11+
super().__init__(*args,**kwargs)
12+
self.helper=FormHelper(self)
13+
setattrs(self.helper,**self.helper_attrs)
14+
15+
16+
classPlaceHolderForm(CrispyForm):
17+
def__init__(self,*args,**kwargs):
18+
super().__init__(*args,**kwargs)
19+
20+
layout=self.helper.layout=Layout()
21+
forfield_name,fieldinself.fields.items():
22+
layout.append(Field(field_name,placeholder=field.label))
23+
self.helper.form_show_labels=False

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp