Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Merge branch 'master' into feature/ingredient-images

Roland Geidere82a2e2a02f8
diff --cc .gitignore
index 798a1778d,1b369483a..1dd432d07
--- a/.gitignore
+++ b/.gitignore
@@@ -65,14 -65,12 +65,12 @@@ node_module
# Virtual envs
venv
- venv-wget
+ venv-wger
-# Will need to copy this file to react repo though
+# Dummy translation files to copy to react or flutter repo
/wger/i18n.tsx
+
+ # Will need to copy these files to the flutter repo
/wger/i18n.dart
/wger/app_en.arb
-
-
-
- # Local images folder
- /media
+ /coverage.lcov
diff --cc AUTHORS.rst
index 86e505f44,a3c9fae0c..fa03da90c
--- a/AUTHORS.rst
+++ b/AUTHORS.rst
@@@ -64,8 -66,9 +66,10 @@@ Developer
* absolutely-not-bot - https://github.com/absolutely-not-bot
* Jaspreet Dhillon - https://github.com/jaspreetsd902
* Sofiko Alaverdashvili - https://github.com/sophiamartelli
+* Oebele Lijzenga - https://github.com/olijzenga
+ * Kade - https://github.com/kp5431/
* Tom Bowyer - https://github.com/ImTheTom
+ * Rohan Karan - https://github.com/RohanKaran
Translators
-----------
diff --cc wger/exercises/management/commands/download-exercise-images.py
index 20de3dcbc,e84a258b8..1a4cca68b
--- a/wger/exercises/management/commands/download-exercise-images.py
+++ b/wger/exercises/management/commands/download-exercise-images.py
@@@ -114,9 -114,28 +114,24 @@@ class Command(BaseCommand)
continue
except ExerciseImage.DoesNotExist:
self.stdout.write(' Image not found in local DB, creating now...')
- image = ExerciseImage()
- image.uuid = image_uuid
-
- # Save the downloaded image
- # http://stackoverflow.com/questions/1308386/programmatically-saving-image-to-
- retrieved_image = requests.get(image_data['image'], headers=headers)
+ retrieved_image = requests.get(image_data['image'], headers=headers)
- ExerciseImage.from_json(exercise_base, retrieved_image, image_data, headers)
-
++ image = ExerciseImage.from_json(exercise_base, retrieved_image, image_data, headers)
+
+ # Temporary files on windows don't support the delete attribute
+ if os.name == 'nt':
+ img_temp = NamedTemporaryFile()
+ else:
+ img_temp = NamedTemporaryFile(delete=True)
+ img_temp.write(retrieved_image.content)
+ img_temp.flush()
+
+ image.exercise_base = exercise_base
+ image.is_main = image_data['is_main']
+ image.image.save(
+ os.path.basename(os.path.basename(image_data['image'])),
+ File(img_temp),
+ )
+ image.save()
self.stdout.write(self.style.SUCCESS(' successfully saved'))
if result['next']:
diff --cc wger/exercises/models/image.py
index a4056cde2,ec18d851e..4fa26dec6
--- a/wger/exercises/models/image.py
+++ b/wger/exercises/models/image.py
@@@ -40,10 -38,10 +38,10 @@@ def exercise_image_upload_dir(instance
Returns the upload target for exercise images
"""
ext = pathlib.Path(filename).suffix
- return "exercise-images/{0}/{1}{2}".format(instance.exercise_base.id, instance.uuid, ext)
+ return f"exercise-images/{instance.exercise_base.id}/{instance.uuid}{ext}"
- class ExerciseImage(AbstractSubmissionModel, AbstractLicenseModel, models.Model, BaseImage):
-class ExerciseImage(AbstractLicenseModel, AbstractHistoryMixin, models.Model):
++class ExerciseImage(AbstractLicenseModel, AbstractHistoryMixin, models.Model, BaseImage):
"""
Model for an exercise image
"""
@@@ -168,47 -157,3 +157,24 @@@
Image has no owner information
"""
return False
+
- def set_author(self, request):
- """
- Set author and status
- This is only used when creating images (via web or API)
- """
- if request.user.has_perm('exercises.add_exerciseimage'):
- self.status = self.STATUS_ACCEPTED
- if not self.license_author:
- self.license_author = request.get_host().split(':')[0]
-
- else:
- if not self.license_author:
- self.license_author = request.user.username
-
- subject = _('New user submitted image')
- message = _('The user {0} submitted a new image "{1}" for exercise {2}.'
- ).format(request.user.username, self.name, self.exercise)
- mail.mail_admins(
- str(subject),
- str(message),
- fail_silently=True,
- )
-
+ @classmethod
+ def from_json(
+ cls,
+ connect_to: ExerciseBase,
+ retrieved_image,
+ json_data: dict,
+ headers,
+ generate_uuid: bool = False
+ ):
+ image: cls = super().from_json(
+ connect_to, retrieved_image, json_data, headers, generate_uuid
+ )
+ image.exercise_base = connect_to
+ image.is_main = json_data['is_main']
+ image.status = json_data['status']
+
+ image.save_image(retrieved_image, json_data)
+
+ image.save()
+ return image
diff --cc wger/settings_global.py
index f4c78315e,892a20ac8..57dfc9973
--- a/wger/settings_global.py
+++ b/wger/settings_global.py
@@@ -18,7 -18,7 +18,8 @@@
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
import re
+import sys
+ from datetime import timedelta
"""
@@@ -434,5 -487,27 +488,31 @@@ WGER_SETTINGS =
'USE_RECAPTCHA': False
}
+
+ #
+ # Django email verification
+ #
+ def email_verified_callback(user):
+ user.userprofile.email_verified = True
+ user.userprofile.save()
+
+
+ EMAIL_VERIFIED_CALLBACK = email_verified_callback
+ EMAIL_FROM_ADDRESS = WGER_SETTINGS['EMAIL_FROM']
+ EMAIL_MAIL_SUBJECT = 'Confirm your email'
+ EMAIL_MAIL_HTML = 'email_verification/email_body_html.tpl'
+ EMAIL_MAIL_PLAIN = 'email_verification/email_body_txt.tpl'
+ EMAIL_MAIL_TOKEN_LIFE = 60 * 60
+ EMAIL_MAIL_PAGE_TEMPLATE = 'email_verification/confirm_template.html'
+ EMAIL_PAGE_DOMAIN = 'http://localhost:8000/'
+
+ #
+ # Django activity stream
+ #
+ ACTSTREAM_SETTINGS = {
+ 'USE_JSONFIELD': True,
+ }
++
++
+# Whether the application is being run regularly or during tests
+TESTING = len(sys.argv) > 1 and sys.argv[1] == 'test'