forked from qgis/QGIS-Certification-Website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_site_and_social_apps.py
More file actions
66 lines (52 loc) · 2.63 KB
/
update_site_and_social_apps.py
File metadata and controls
66 lines (52 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from django.core.management.base import BaseCommand
from django.contrib.sites.models import Site
from allauth.socialaccount.models import SocialApp
import getpass
class Command(BaseCommand):
help = 'Updates default Site and Social Application configurations'
def handle(self, *args, **options):
self.stdout.write(self.style.HTTP_INFO("\n=== Site Configuration Update ==="))
self.update_site()
self.stdout.write(self.style.HTTP_INFO("\n=== Social Applications Update ==="))
self.update_social_apps()
def update_site(self):
"""Update the default Site domain and display name"""
try:
site = Site.objects.get_current()
self.stdout.write(self.style.HTTP_INFO("\nCurrent Site Configuration:"))
self.stdout.write(f"Domain: {site.domain}")
self.stdout.write(f"Display Name: {site.name}\n")
new_domain = input("Enter new domain (e.g., example.com): ").strip()
new_name = input("Enter new display name: ").strip()
if new_domain:
site.domain = new_domain
if new_name:
site.name = new_name
site.save()
self.stdout.write(self.style.SUCCESS("Site updated successfully!"))
except Exception as e:
self.stdout.write(self.style.ERROR(f"Error updating site: {str(e)}"))
def update_social_apps(self):
"""Update all Social Applications"""
social_apps = SocialApp.objects.all()
if not social_apps.exists():
self.stdout.write(self.style.WARNING("No social applications found."))
return
for app in social_apps:
self.stdout.write(self.style.HTTP_INFO(f"\nUpdating {app.provider} application:"))
# Get new values with current values as placeholders
new_name = input(f"Application name [{app.name}]: ").strip() or app.name
new_client_id = input(f"Client ID [{app.client_id}]: ").strip() or app.client_id
# For secret key, don't show current value for security
self.stdout.write("Current secret key: [hidden]")
new_secret = getpass.getpass("New Secret Key (leave blank to keep current): ").strip()
# Update fields
app.name = new_name
app.client_id = new_client_id
if new_secret:
app.secret = new_secret
try:
app.save()
self.stdout.write(self.style.SUCCESS(f"{app.provider} application updated!"))
except Exception as e:
self.stdout.write(self.style.ERROR(f"Error updating {app.provider}: {str(e)}"))