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

Initial development #1

Merged
merged 65 commits into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
584727d
WIP: Initial commit
KalobTaulien Apr 22, 2020
a795153
Package support
KalobTaulien Apr 22, 2020
aaeee4a
Minor adjustments
KalobTaulien Apr 30, 2020
389fdeb
Adding debug statements for easier local development
KalobTaulien Apr 30, 2020
04d368e
Documentation updates
KalobTaulien Apr 30, 2020
b39d5e7
Local debugging support
KalobTaulien Apr 30, 2020
04c70f1
Example integrations
KalobTaulien Apr 30, 2020
0fd2315
Better mapping support
KalobTaulien Apr 30, 2020
780b199
Dev notes
KalobTaulien Apr 30, 2020
3685865
Page dictionary support for unique column_name to field_name mapping
KalobTaulien May 1, 2020
d4ee236
Moved logic to outside method
KalobTaulien May 1, 2020
9091280
Moved private method down as setup method is more important
KalobTaulien May 1, 2020
5fe5370
Added docs around the EXTRA_SUPPORTED_MODELS setting
KalobTaulien May 1, 2020
6352d19
Cleanup & Airtable best practices doc
KalobTaulien May 4, 2020
7ca0098
Added a known issue
KalobTaulien May 4, 2020
8c918f4
Somewhat handle multiple returned records
KalobTaulien May 4, 2020
69c4ebf
Auto-register airtable import admin url
KalobTaulien May 4, 2020
0fc0ccb
Support additional model import in the template
KalobTaulien May 4, 2020
b045538
ctrl+z; undoing last commit as it was a bad idea
KalobTaulien May 4, 2020
3303508
Optional setting: disable airtable importing on pecific models
KalobTaulien May 4, 2020
22b04ed
Adding api response memoization
KalobTaulien May 4, 2020
e88aa38
Docs and extra model support
KalobTaulien May 4, 2020
a415f22
Resets all airtable record ids from management command
KalobTaulien May 5, 2020
6e5f043
Small fixes
KalobTaulien May 5, 2020
b3c7e57
Moved testing const to mixin file
KalobTaulien May 5, 2020
36416e3
Try/catch a failed Airtable request
KalobTaulien May 6, 2020
f726dbb
Remove cache purge line
KalobTaulien May 6, 2020
4e3ab70
Add Airtable record to object when creating a new record
KalobTaulien May 6, 2020
d89ec15
Auto increment model pks when creating new model from an import
KalobTaulien May 6, 2020
33ffc17
Better json to dict evaluation
KalobTaulien May 7, 2020
57973dd
Properly create new models from Airtable withour throwing an Integrit…
KalobTaulien May 7, 2020
a641d80
Use POST instead of GET requests
KalobTaulien May 7, 2020
93e996f
Default message when no models are configured
KalobTaulien May 12, 2020
ce28580
Hide Import menu option when disabled
KalobTaulien May 12, 2020
d11bf42
Django messages when page is saved w/ or w/o airtable record update
KalobTaulien May 12, 2020
4a6e32a
Future Snippet hook support
KalobTaulien May 12, 2020
34be856
Mock Airtable Client
KalobTaulien May 14, 2020
57ab574
Ignore common files and dirs
KalobTaulien May 14, 2020
b1b118b
View, Model and Mixin tests
KalobTaulien May 14, 2020
c34b157
Refactoring import command as separate class; writing tests for the n…
KalobTaulien May 15, 2020
5bf118c
Import management command tests
KalobTaulien May 18, 2020
bbc16a4
Cleanup + Black formatting
KalobTaulien May 18, 2020
30cbb4e
Flake8 formatting (sans E501's from Black formatting)
KalobTaulien May 18, 2020
73f9362
Check is Mixin is enabled before creating ERROR/SUCCESS messages
KalobTaulien May 18, 2020
5332460
Animated preview and test docs
KalobTaulien May 18, 2020
a6fac29
API key documentation line
KalobTaulien May 19, 2020
d1f6f67
Reusable test dictionaries; fixed a test
KalobTaulien May 19, 2020
ed94594
Misc. updates from code review
KalobTaulien May 20, 2020
b434f79
Removed EXTRA_SUPPORTED_MODELS in favour of re-using dictionaries
KalobTaulien May 20, 2020
5a1d340
Moving common logic into util functions
KalobTaulien May 20, 2020
26286ce
Better way to save models
KalobTaulien May 20, 2020
7d710ef
Use Importer and util functions instead of the call call_command
KalobTaulien May 20, 2020
8223804
Util tests
KalobTaulien May 20, 2020
b1aacb8
ImproperlyConfigured exception
KalobTaulien May 20, 2020
0787f8a
'None' => None
KalobTaulien May 20, 2020
6b6f647
m2m support; renamed obj to instance
KalobTaulien May 20, 2020
6bde27d
Wording update
KalobTaulien May 20, 2020
57d52b4
Removed single record testing condition
KalobTaulien May 20, 2020
46b2dc6
Using empty str helps prevent default IntegrityErrors on non null tex…
KalobTaulien May 21, 2020
e8253d4
Default to False
KalobTaulien May 21, 2020
0d30697
Default AIRTABLE to False in hooks
KalobTaulien May 21, 2020
6b1ca24
fixup! Default AIRTABLE to False in hooks
KalobTaulien May 21, 2020
149859d
Group models with the same settings together
KalobTaulien May 21, 2020
ca98b9b
Review touchups and flake8
KalobTaulien May 22, 2020
9a795c4
Black formatting
KalobTaulien May 22, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@

<div class="nice-padding">
<h2>Models you can import from Airtable</h2>
{% for model_name, model_path, model in models %}
{% for model_name, model_path, is_airtable_enabled, grouped_models in models %}
<h3>{{ model_name }}</h3>
{{ model }}
{% if model.is_airtable_enabled %}
{% if grouped_models %}
<div class="help-block help-info">
<p>When you import {{ model_name }} you'll also be importing these ({{ grouped_models|length }}) as well: {% for model_name in grouped_models %}{{ model_name }}{% if not forloop.last %}, {% endif %} {% endfor %}</p>
</div>
{% endif %}
{% if is_airtable_enabled %}
<form method="POST" action="{% url 'airtable_import_listing' %}">
{% csrf_token %}
<input type="hidden" name="model" value="{{ model_path }}" />
Expand Down
52 changes: 41 additions & 11 deletions wagtail_airtable/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,60 @@ def get_validated_models(self):
]
"""
airtable_settings = getattr(settings, "AIRTABLE_IMPORT_SETTINGS", {})
validated_models = []

# Loop through all the models in the settings and create a new dict
# of the unique settings for each model label.
# If settings were used more than once the second (3rd, 4th, etc) common settings
# will be bulked into a "grouped_models" list.
tracked_settings = []
KalobTaulien marked this conversation as resolved.
Show resolved Hide resolved
models = {}
for label, model_settings in airtable_settings.items():
if model_settings not in tracked_settings:
tracked_settings.append(model_settings)
models[label] = model_settings
models[label]['grouped_models'] = []
else:
for label2, model_settings2 in models.items():
if model_settings is model_settings2:
models[label2]['grouped_models'].append(label)

# Validated models are models that actually exist.
# This way fake models can't be added.
validated_models = []
for label, model_settings in models.items():
# If this model is allowed to be imported. Default is True.
if model_settings.get("AIRTABLE_IMPORT_ALLOWED", True):
# A temporary variable for holding grouped model names.
# This is added to the validated_models item later.
# This is only used for displaying model names in the import template
_grouped_models = []
# Loop through the grouped_models list in each setting, validate each model,
# then add it to the larger grouped_models
if model_settings.get("grouped_models"):
for grouped_model_label in model_settings.get("grouped_models"):
if "." in grouped_model_label:
try:
model = get_model_for_path(grouped_model_label)
_grouped_models.append(model._meta.verbose_name_plural)
except ObjectDoesNotExist:
raise ImproperlyConfigured(
"%r is not recognised as a model name." % label
)

if "." in label:
KalobTaulien marked this conversation as resolved.
Show resolved Hide resolved
try:
model = get_model_for_path(label)
# Append a triple-tuple to the validated_models with the:
# (1. Models verbose name, 2. Model label, 3. is_airtable_enabled from the model, and 4. List of grouped models)
validated_models.append(
(model._meta.verbose_name.title(), label, model)
(model._meta.verbose_name_plural, label, model.is_airtable_enabled, _grouped_models)
)
except ObjectDoesNotExist:
raise ImproperlyConfigured(
"%r is not recognised as a model name." % label
)
models = validated_models[:]
for title, label, model in validated_models:
airtable_settings = settings.AIRTABLE_IMPORT_SETTINGS.get(
model._meta.label, {}
)
# Remove this model the the `models` list so it doesn't hit the Airtable API.
if not airtable_settings.get("AIRTABLE_IMPORT_ALLOWED", True):
models.remove(model)

return models
return validated_models

def get_context_data(self, **kwargs):
"""Add validated models from the AIRTABLE_IMPORT_SETTINGS to the context."""
Expand Down