Skip to content

Commit

Permalink
merged with master
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandravaphilips committed Jul 5, 2024
1 parent 7c118c9 commit 2d5fbb5
Show file tree
Hide file tree
Showing 19 changed files with 4,514 additions and 12 deletions.
10 changes: 10 additions & 0 deletions peachjam/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from django import forms
from django.conf import settings
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
from django.core.files import File
from django.core.mail import send_mail
from django.http import QueryDict
Expand Down Expand Up @@ -231,3 +233,11 @@ def send_email(self):
html_message=html,
fail_silently=False,
)


class SignUpForm(UserCreationForm):
email = forms.EmailField()

class Meta:
model = User
fields = ["username", "email", "password1", "password2"]
2 changes: 1 addition & 1 deletion peachjam/js/components/DocumentProblemModal.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="modal-dialog">
<div class="modal-content">
<div id="documentDetailModal" class="modal-content">
<div class="modal-header">
<h5 id="documentProblemModalTitle" class="modal-title">
{{ $t('Is there something wrong with this document?') }}
Expand Down
106 changes: 106 additions & 0 deletions peachjam/js/components/SaveDocumentModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<template>
<p>hello</p>
<!-- <div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 id="SaveDocumentModalTitle" class="modal-title">
{{ $t('Where do you want to save your document?') }}
</h5>
<button
type="button"
class="btn-close"
data-bs-dismiss="modal"
aria-label="Close"
/>
</div>
<div class="modal-body">
<form
id="save-document-form"
ref="form"
method="post"
>
<div v-if="collections.length">
<div v-for="collection in collections" :key="collection" class="form-check">
<input
:id="collection"
class="form-check-input"
type="radio"
:v-model="saveTo"
:value="collection"
>
<label class="form-check-label" :for="collection">
{{ collection }}
</label>
</div>
</div>
<div>
<div class="form-check">
<input
id="noCollection"
class="form-check-input"
type="radio"
:v-model="saveTo"
value="noCollection"
>
<label class="form-check-label" for="noCollection">
{% trans "Don't save to a collection" %}
</label>
</div>
<div class="form-check">
<input
id="newCollection"
class="form-check-input"
type="radio"
:v-model="saveTo"
value="newCollection"
>
<label class="form-check-label" for="newCollection">
Create new collection
</label>
</div>
</div>
</form>
</div>
</div>
</div> -->
</template>

<script>
import { authHeaders } from '../api';
export default {
name: 'SaveDocumentModal',
props: {
collections: {
type: Array,
default: () => []
}
},
data () {
return {
saveTo: ''
};
},
methods: {
onShow () {
this.saveTo = '';
},
async onSubmit () {
const form = new FormData(this.$refs.form);
fetch('/document-problem/', {
method: 'post',
body: form,
headers: await authHeaders()
})
.then((response) => {
this.submitted = true;
this.success = response.ok;
})
.catch((error) => {
console.log(error);
});
}
}
};
</script>
2 changes: 2 additions & 0 deletions peachjam/js/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import DocumentProblemModal from './DocumentProblemModal.vue';
import FindDocuments from './FindDocuments/index.vue';
import LegislationTable from './LegislationTable/index.vue';
import PocketLawDownload from './PocketLawDownload.vue';
import SaveDocumentModal from './SaveDocumentModal.vue';

const components: Record<string, any> = {
// Data components
Expand All @@ -24,6 +25,7 @@ const components: Record<string, any> = {
TermsOfUse,

// Vue components
SaveDocumentModal,
DocumentProblemModal,
FindDocuments,
LegislationTable,
Expand Down
1 change: 1 addition & 0 deletions peachjam/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .article import *
from .author import *
from .citations import *
from .collection import *
from .core_document_model import *
from .external_document import *
from .gazette import *
Expand Down
55 changes: 55 additions & 0 deletions peachjam/models/collection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import os

from django.contrib.auth import get_user_model
from django.db import models
from django.utils.translation import gettext_lazy as _

from .core_document_model import CoreDocument

User = get_user_model()


def file_location(instance, filename):
filename = os.path.basename(filename)
return f"{instance.SAVE_FOLDER}/{instance.pk}/{filename}"


class Collection(models.Model):
name = models.CharField(_("name"), max_length=1024, unique=True)
user_profile = models.ForeignKey(
"peachjam.UserProfile",
on_delete=models.CASCADE,
verbose_name=_("user_profile"),
related_name="collections",
)

class Meta:
ordering = ("name",)
verbose_name = _("collection")
verbose_name_plural = _("collections")

def __str__(self):
return f"{self.name}"


class SavedDocument(models.Model):
document = models.ForeignKey(CoreDocument, on_delete=models.CASCADE)
user_profile = models.ForeignKey(
"peachjam.UserProfile",
on_delete=models.CASCADE,
verbose_name=_("user_profile"),
related_name="saved_documents",
)
collection = models.ForeignKey(
Collection,
on_delete=models.CASCADE,
verbose_name=_("collection"),
)

class Meta:
ordering = ("document__title",)
verbose_name = _("saved document")
verbose_name_plural = _("saved documents")

def __str__(self):
return f"{self.document.title}"
3 changes: 1 addition & 2 deletions peachjam/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@
]
# admins must create accounts
ACCOUNT_SIGNUP_ENABLED = False
# sign in with email addresses
ACCOUNT_AUTHENTICATION_METHOD = "email"
# email addresses are required for new accounts
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_PRESERVE_USERNAME_CASING = False
Expand All @@ -156,6 +154,7 @@
ACCOUNT_DEFAULT_HTTP_PROTOCOL = "https"
LOGIN_URL = "account_login"
LOGIN_REDIRECT_URL = "home_page"
ACCOUNT_EMAIL_VERIFICATION = "mandatory"

# social logins
SOCIALACCOUNT_PROVIDERS = {
Expand Down
4,129 changes: 4,127 additions & 2 deletions peachjam/static/js/app-prod.js

Large diffs are not rendered by default.

68 changes: 66 additions & 2 deletions peachjam/static/js/pdf.worker-prod.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions peachjam/templates/account/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ <h1 class="mb-3">{% trans 'Log in' %}</h1>
</div>
{% endif %}
<div class="form-group">
<label for="{{ form.login.id_for_label }}">{% trans 'Email address' %}</label>
<input type="email"
<label for="{{ form.login.id_for_label }}">{% trans 'Email address or username' %}</label>
<input type="text"
class="form-control"
name="{{ form.login.name }}"
id="{{ form.login.id_for_label }}"
Expand All @@ -47,6 +47,7 @@ <h1 class="mb-3">{% trans 'Log in' %}</h1>
required/>
<div class="my-2">
<a href="{% url 'account_reset_password' %}">{% trans 'Forgot your password?' %}</a>
<a href="{% url 'account_signup' %}">{% trans 'Sign up' %}</a>
</div>
{% if form.password.errors %}
<div class="text-danger">
Expand Down
79 changes: 79 additions & 0 deletions peachjam/templates/account/signup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{% extends "allauth/layouts/base.html" %}
{% load account socialaccount static %}
{% load i18n %}
{% block title %}
{% trans 'Sign Up' %}
{% endblock %}
{% block head-css %}
{{ block.super }}
<link href="https://fonts.googleapis.com/css?family=Roboto"
rel="stylesheet"/>
{% endblock %}
{% block content %}
<h1 class="mb-3">{% trans 'Sign up' %}</h1>
<form method="post">
{% csrf_token %}
{% if form.non_field_errors %}
<div class="text-danger">
{% for error in form.non_field_errors %}<p>{{ error }}</p>{% endfor %}
</div>
{% endif %}
<div class="form-group">
<label for="{{ form.username.id_for_label }}">{% trans 'Username' %}</label>
<input type="text"
class="form-control"
name="{{ form.username.name }}"
id="{{ form.username.id_for_label }}"
required
autofocus/>
{% if form.username.errors %}
<div class="text-danger">
{% for error in form.username.errors %}<p>{{ error }}</p>{% endfor %}
</div>
{% endif %}
</div>
<div class="form-group">
<label for="{{ form.email.id_for_label }}">{% trans 'Email address' %}</label>
<input type="email"
class="form-control"
name="{{ form.email.name }}"
id="{{ form.email.id_for_label }}"
required
placeholder="[email protected]"/>
{% if form.email.errors %}
<div class="text-danger">
{% for error in form.email.errors %}<p>{{ error }}</p>{% endfor %}
</div>
{% endif %}
</div>
<div class="form-group">
<label for="{{ form.password1.id_for_label }}">{% trans 'Password' %}</label>
<input type="password"
class="form-control"
name="{{ form.password1.name }}"
id="{{ form.password1.id_for_label }}"
required/>
{% if form.password1.errors %}
<div class="text-danger">
{% for error in form.password1.errors %}<p>{{ error }}</p>{% endfor %}
</div>
{% endif %}
</div>
<div class="form-group">
<label for="{{ form.password2.id_for_label }}">{% trans 'Confirm Password' %}</label>
<input type="password"
class="form-control"
name="{{ form.password2.name }}"
id="{{ form.password2.id_for_label }}"
required/>
{% if form.password2.errors %}
<div class="text-danger">
{% for error in form.password2.errors %}<p>{{ error }}</p>{% endfor %}
</div>
{% endif %}
</div>
<div class="my-2">
<button class="btn btn-success btn-block mb-3" type="submit">{% trans 'Sign up' %}</button>
</div>
</form>
{% endblock %}
8 changes: 8 additions & 0 deletions peachjam/templates/peachjam/_document_detail_toolbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
{% endif %}
{% endblock %}
{% block download-btn %}
<button class="btn btn-outline-primary btn-shrink-sm ms-2"
data-bs-toggle="modal"
data-bs-target="#documentProblemModal"
hx-get="/collections/"
hx-target="#documentDetailModal"
hx-trigger="click">
Save document
</button>
{% if document.source_file %}
<div class="btn-group dropdown-center ms-2">
<a href="{% url 'document_source' document.expression_frbr_uri|strip_first_character %}"
Expand Down
6 changes: 5 additions & 1 deletion peachjam/templates/peachjam/_header.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@
</a>
<ul class="dropdown-menu">
<li>
<a class="dropdown-item" href="{% url 'admin:index' %}">{% trans 'Admin' %}</a>
{% if user.is_superuser %}
<a class="dropdown-item" href="{% url 'admin:index' %}">{% trans 'Admin' %}</a>
{% endif %}
<a class="dropdown-item" href="{% url 'account_logout' %}">{% trans 'Logout' %}</a>
</li>
</ul>
</li>
{% endblock %}
</ul>
{% else %}
<a class="btn btn-primary ms-3" href="{% url 'account_login' %}">Log in</a>
{% endif %}
{% include 'peachjam/_set_language.html' %}
</div>
Expand Down
11 changes: 11 additions & 0 deletions peachjam/templates/peachjam/collections_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% load static i18n %}
<div class="modal-header">
<h5 id="SaveDocumentModalTitle" class="modal-title">{% trans 'Where do you want to save your document?' %}</h5>
<button type="button"
class="btn-close"
data-bs-dismiss="modal"
aria-label="Close"/>
</div>
<div class="modal-body">
<div id="SaveDocumentModal" data-vue-component="SaveDocumentModal"></div>
</div>
4 changes: 3 additions & 1 deletion peachjam/templates/peachjam/layouts/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@
{% block head-css %}{% endblock %}
{% block head-js %}{% endblock %}
</head>
<body class="{% block body-class %}{% endblock %}">
<body hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
class="{% block body-class %}{% endblock %}">
{% block header %}{% endblock %}
{% block body-content %}{% endblock %}
{% block footer %}{% endblock %}
<script src="https://unpkg.com/[email protected]"></script>
</body>
</html>
Loading

0 comments on commit 2d5fbb5

Please sign in to comment.