kaputtnik has proposed merging lp:~widelands-dev/widelands-website/mv_main_files into lp:widelands-website.
Commit message: Moved main files into folder mainpage Requested reviews: Widelands Developers (widelands-dev) Related bugs: Bug #1762164 in Widelands Website: "Update website code to use python 3.x" https://bugs.launchpad.net/widelands-website/+bug/1762164 For more details, see: https://code.launchpad.net/~widelands-dev/widelands-website/mv_main_files/+merge/365634 Python3 is more restrictive with relative imports. Moving the mainfiles into the directory 'mainpage' is made to perform this. In python terms: The folder widelands (containing manage.py) will no longer be a 'package'. Running manage.py will call anything inside the package 'mainpage' and thus relative imports will work again. This reflects also the initial structure of a django project, like shown here: https://docs.djangoproject.com/en/2.2/intro/reusable-apps/#your-project-and-your-reusable-app Running the 2to3 script (for porting python2 to python3 code) produces less faulty code in regard to imports after this change. I have also moved the privacy template to his origin (privacy_policy). Should be tested on alpha. -- Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands-website/mv_main_files into lp:widelands-website.
=== modified file 'README.txt' --- README.txt 2018-12-30 11:45:03 +0000 +++ README.txt 2019-04-07 09:29:16 +0000 @@ -57,6 +57,7 @@ This will take a while. If no errors are shown we should be fine. + Setting up the website ====================== @@ -68,8 +69,8 @@ those files and modify them to your needs - most likely everything works directly, but you might want to edit the bd variable in local_settings.py:: - $ ln -s local_urls.py.sample local_urls.py - $ ln -s local_settings.py.sample local_settings.py + $ ln -s local_urls.py.sample mainpage/local_urls.py + $ ln -s local_settings.py.sample mainpage/local_settings.py Setting up the database ----------------------- @@ -125,60 +126,63 @@ See also https://docs.djangoproject.com/en/dev/ref/django-admin/#examples-of-using-different-ports-and-addresses for further details. + Dependencies between website and widelands source code ====================================================== -Some parts of the website need access to the source code of widelands: - -* Online help/Encyclopedia -* Possibility to upload a map onto the local website -* Source code documentation - -You will need the widelands source code for this, see +Some parts of the website need access to the source code of widelands, other +parts need some widelands executables. + +Source code only +---------------- + +The documentation is made out of the source code. To get a copy, see: https://wl.widelands.org/wiki/BzrPrimer/ After the source code is downloaded, adjust the path of -WIDELANDS_SVN_DIR - -in local_settings.py to the path where the widelands source code is found. - -Setting up the online help / encyclopedia ------------------------------------------ - -You will need graphviz to generate the graphs for the online help. On Ubuntu run: +WIDELANDS_SVN_DIR = '/path/to/widelands/trunk' + +in mainpage/local_settings.py to the path where the widelands source code can be +found. Then run: + + $ ./manage.py create_docs + +After finishing without errors, type localhost:8000/documentation/index.html +in your browsers addressbar or click on "Development -> Documentation". + +Widelands executables +--------------------- + +Widelands executables are needed to: + +* Upload maps to the website +* Create the Encylopdia + +Either install widelands as a program to your operating system, or create the +binarys by compiling the source code. If you want to compile, run: + + $ ./compile.sh -r + +inside of the WIDELANDS_SVN_DIR to create a release build. + +Uploading maps should work now. + +Creating the encyclopdia needs graphviz to generate the graphs. On Ubuntu run: $ sudo apt-get install graphviz -To generate the online help database switch to your local environment and run: +To generate the online help switch to your local environment and run: $ ./manage.py update_help -After that you can create the overview pdf files with +Now you can create the economy graphs: $ ./manage.py update_help_pdf -Setting up widelands source code documentation ----------------------------------------------- - -There is a small helper script to get the documenation. Be sure -you have set WIDELANDS_SVN_DIR set in local_settings.py. Run: - - $ ./manage.py create_docs - -After finishing without errors, type localhost:8000/documentation/index.html -in your browsers addressbar or click on "Development -> Documentation". - - -Uploading a map to the local website ------------------------------------- - -Compile the widelands binaries by using the compile.sh script - - $ ./compile.sh - -Now you should be able to upload a map onto your local website. +You can access the encyclopdia by clicking on 'The Game -> Encyclopedia' now. + Contact ======= === removed file '__init__.py' === renamed file 'mainpage/urls.py' => 'mainpage/mainpage_urls.py' === renamed file 'online_users_middleware.py' => 'mainpage/online_users_middleware.py' === renamed file 'settings.py' => 'mainpage/settings.py' --- settings.py 2019-03-04 17:53:53 +0000 +++ mainpage/settings.py 2019-04-07 09:29:16 +0000 @@ -3,7 +3,7 @@ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os -BASE_DIR = os.path.dirname(os.path.abspath(__file__)) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) DEBUG = True ADMINS = ( @@ -39,6 +39,7 @@ SITE_ID = 1 +#LOGIN_URL = '/registration/login/' # Where should logged in user go by default? LOGIN_REDIRECT_URL = '/' @@ -68,7 +69,7 @@ # Make this unique, and don't share it with anybody. SECRET_KEY = '#*bc7*q0-br42fc&6l^x@zzk&(=-#gr!)fn@t30n54n05jkqcu' -ROOT_URLCONF = 'urls' +ROOT_URLCONF = 'mainpage.urls' # List of finder classes that know how to find static files in # various locations. @@ -132,7 +133,7 @@ # Foreign middleware 'dj_pagination.middleware.PaginationMiddleware', - 'online_users_middleware.OnlineNowMiddleware', + 'mainpage.online_users_middleware.OnlineNowMiddleware', ] TEMPLATES = [ === renamed file 'sitemap_urls.py' => 'mainpage/sitemap_urls.py' --- sitemap_urls.py 2018-03-21 21:10:46 +0000 +++ mainpage/sitemap_urls.py 2019-04-07 09:29:16 +0000 @@ -1,6 +1,5 @@ -from django.conf.urls import * +from django.conf.urls import url -from mainpage.views import mainpage from django.contrib.sitemaps.views import sitemap from static_sitemap import StaticViewSitemap from wiki.sitemap import * === renamed file 'static_sitemap.py' => 'mainpage/static_sitemap.py' === modified file 'mainpage/templatetags/wl_markdown.py' --- mainpage/templatetags/wl_markdown.py 2018-11-30 14:31:47 +0000 +++ mainpage/templatetags/wl_markdown.py 2019-04-07 09:29:16 +0000 @@ -13,7 +13,7 @@ from django.conf import settings from django.utils.encoding import smart_str, force_unicode from django.utils.safestring import mark_safe -from settings import BLEACH_ALLOWED_TAGS, BLEACH_ALLOWED_ATTRIBUTES +from django.conf import settings from markdownextensions.semanticwikilinks.mdx_semanticwikilinks import SemanticWikiLinkExtension # Try to get a not so fully broken markdown module @@ -38,17 +38,17 @@ # We will also need the site domain from django.contrib.sites.models import Site -from settings import SITE_ID, SMILEYS, SMILEY_DIR +from django.conf import settings try: - _domain = Site.objects.get(pk=SITE_ID).domain + _domain = Site.objects.get(pk=settings.SITE_ID).domain except: _domain = '' # Getting local domain lists try: - from settings import LOCAL_DOMAINS as _LOCAL_DOMAINS - LOCAL_DOMAINS = [_domain] + _LOCAL_DOMAINS + from django.conf import settings + LOCAL_DOMAINS = [_domain] + settings.LOCAL_DOMAINS except ImportError: LOCAL_DOMAINS = [_domain] @@ -76,12 +76,12 @@ for i, word in enumerate(words): smiley = '' - for sc, img in SMILEYS: + for sc, img in settings.SMILEYS: if word == sc: smiley = img if smiley: img_tag = BeautifulSoup(features='lxml').new_tag('img') - img_tag['src'] = '{}{}'.format(SMILEY_DIR, smiley) + img_tag['src'] = '{}{}'.format(settings.SMILEY_DIR, smiley) img_tag['alt'] = smiley tmp_content.append(img_tag) # apply a space after the smiley @@ -204,7 +204,7 @@ if bs4_string.parent.name.lower() == 'code': return False - for sc in SMILEYS: + for sc in settings.SMILEYS: if sc[0] in bs4_string: return True return False @@ -223,7 +223,7 @@ # Sanitize posts from potencial untrusted users (Forum/Wiki/Maps) if 'bleachit' in args: html = mark_safe(bleach.clean( - html, tags=BLEACH_ALLOWED_TAGS, attributes=BLEACH_ALLOWED_ATTRIBUTES)) + html, tags=settings.BLEACH_ALLOWED_TAGS, attributes=settings.BLEACH_ALLOWED_ATTRIBUTES)) # Prepare the html and apply smileys and classes. # BeautifulSoup objects are all references, so changing a variable === renamed file 'urls.py' => 'mainpage/urls.py' --- urls.py 2019-03-16 10:11:05 +0000 +++ mainpage/urls.py 2019-04-07 09:29:16 +0000 @@ -13,7 +13,7 @@ urlpatterns = [ # Creating a sitemap.xml - url(r'^sitemap\.xml/', include('sitemap_urls')), + url(r'^sitemap\.xml/', include('mainpage.sitemap_urls')), # Static view of robots.txt url(r'^robots\.txt/', TemplateView.as_view(template_name='robots.txt', content_type="text/plain")), @@ -45,7 +45,7 @@ url(r'^forum/', include('pybb.urls')), # WL specific: - url(r'^', include('mainpage.urls')), + url(r'^', include('mainpage.mainpage_urls')), url(r'^help/(?P<path>.*)', RedirectView.as_view(url='/encyclopedia/%(path)s', permanent=True)), # to not break old links url(r'^encyclopedia/', include('wlhelp.urls')), === modified file 'mainpage/utest/test_wl_markdown.py' --- mainpage/utest/test_wl_markdown.py 2016-12-13 18:28:51 +0000 +++ mainpage/utest/test_wl_markdown.py 2019-04-07 09:29:16 +0000 @@ -17,9 +17,9 @@ import unittest from wiki.models import Article from django.contrib.sites.models import Site -from settings import SITE_ID +from django.conf import settings from django.test import TestCase as DBTestCase -_domain = Site.objects.get(pk=SITE_ID).domain +_domain = Site.objects.get(pk=settings.SITE_ID).domain from templatetags.wl_markdown import do_wl_markdown === modified file 'mainpage/views.py' --- mainpage/views.py 2019-02-09 14:50:47 +0000 +++ mainpage/views.py 2019-04-07 09:29:16 +0000 @@ -1,4 +1,4 @@ -from settings import WIDELANDS_SVN_DIR, INQUIRY_RECIPIENTS +from django.conf import settings from templatetags.wl_markdown import do_wl_markdown from operator import itemgetter from django.core.mail import send_mail @@ -33,7 +33,7 @@ # get email addresses which are in form of ('name','email'), recipients = [] - for recipient in INQUIRY_RECIPIENTS: + for recipient in settings.INQUIRY_RECIPIENTS: recipients.append(recipient[1]) send_mail(subject, message, sender, @@ -46,7 +46,7 @@ return render(request, 'mainpage/legal_notice.html', { 'form': form, - 'inquiry_recipients': INQUIRY_RECIPIENTS, + 'inquiry_recipients': settings.INQUIRY_RECIPIENTS, }) @@ -67,7 +67,7 @@ txt = '[TOC]\n\n' transl_files = [] transl_list = [] - path = os.path.normpath(WIDELANDS_SVN_DIR + 'data/i18n/locales/') + path = os.path.normpath(settings.WIDELANDS_SVN_DIR + 'data/i18n/locales/') try: transl_files = os.listdir(path) if transl_files: @@ -100,7 +100,7 @@ # Get other developers, put in the translators list # at given position and prepare all for wl_markdown try: - with open(WIDELANDS_SVN_DIR + 'data/txts/developers.json', 'r') as f: + with open(settings.WIDELANDS_SVN_DIR + 'data/txts/developers.json', 'r') as f: json_data = json.load(f)['developers'] for head in json_data: @@ -145,7 +145,7 @@ This replaces the wiki changelog """ - data = codecs.open(WIDELANDS_SVN_DIR + 'ChangeLog', encoding='utf-8', mode='r').read() + data = codecs.open(settings.WIDELANDS_SVN_DIR + 'ChangeLog', encoding='utf-8', mode='r').read() return render(request, 'mainpage/changelog.html', {'changelog': data}, ) === renamed file 'wl_utils.py' => 'mainpage/wl_utils.py' === renamed file 'wlwebsite_wsgi.py' => 'mainpage/wlwebsite_wsgi.py' --- wlwebsite_wsgi.py 2016-12-13 18:28:51 +0000 +++ mainpage/wlwebsite_wsgi.py 2019-04-07 09:29:16 +0000 @@ -22,7 +22,7 @@ sys.path.append(code_directory) sys.path.append(os.path.join(code_directory, 'widelands')) -os.environ['DJANGO_SETTINGS_MODULE'] = 'widelands.settings' +os.environ['DJANGO_SETTINGS_MODULE'] = 'mainpage.settings' if os.path.exists('/usr/games'): os.environ['PATH'] += ':/usr/games' === modified file 'manage.py' --- manage.py 2016-12-13 18:28:51 +0000 +++ manage.py 2019-04-07 09:29:16 +0000 @@ -3,7 +3,7 @@ import sys if __name__ == '__main__': - os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings') + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mainpage.settings') from django.core.management import execute_from_command_line === modified file 'news/models.py' --- news/models.py 2018-04-08 14:40:17 +0000 +++ news/models.py 2019-04-07 09:29:16 +0000 @@ -6,7 +6,6 @@ from news.managers import PublicManager from django.urls import reverse import datetime -import settings import tagging === added directory 'privacy_policy/templates' === added directory 'privacy_policy/templates/privacy_policy' === renamed file 'mainpage/templates/mainpage/privacy_policy.html' => 'privacy_policy/templates/privacy_policy/privacy_policy.html' === modified file 'privacy_policy/views.py' --- privacy_policy/views.py 2019-02-09 19:57:06 +0000 +++ privacy_policy/views.py 2019-04-07 09:29:16 +0000 @@ -43,4 +43,4 @@ 'cur_lang': current_lang, } - return render(request, 'mainpage/privacy_policy.html', context) + return render(request, 'privacy_policy/privacy_policy.html', context) === modified file 'threadedcomments/views.py' --- threadedcomments/views.py 2018-10-10 18:02:55 +0000 +++ threadedcomments/views.py 2019-04-07 09:29:16 +0000 @@ -8,7 +8,7 @@ from threadedcomments.forms import ThreadedCommentForm from threadedcomments.models import ThreadedComment, DEFAULT_MAX_COMMENT_LENGTH from threadedcomments.utils import JSONResponse, XMLResponse -from wl_utils import get_real_ip +from mainpage.wl_utils import get_real_ip def _adjust_max_comment_length(form, field_name='comment'): === modified file 'widelandslib/make_flow_diagram.py' --- widelandslib/make_flow_diagram.py 2016-12-13 18:28:51 +0000 +++ widelandslib/make_flow_diagram.py 2019-04-07 09:29:16 +0000 @@ -3,7 +3,7 @@ import pydot as d -from settings import MEDIA_ROOT +from django.conf import settings from widelandslib.tribe import * from os import makedirs, path @@ -182,7 +182,7 @@ global tdir tdir = mkdtemp(prefix='widelands-help') - json_directory = path.normpath(MEDIA_ROOT + '/map_object_info') + json_directory = path.normpath(settings.MEDIA_ROOT + '/map_object_info') tribeinfo_file = open(path.normpath( json_directory + '/tribe_' + tribe_name + '.json'), 'r') tribeinfo = json.load(tribeinfo_file) === modified file 'widelandslib/tribe.py' --- widelandslib/tribe.py 2016-12-13 18:28:51 +0000 +++ widelandslib/tribe.py 2019-04-07 09:29:16 +0000 @@ -4,8 +4,8 @@ import os.path as p import json try: - from settings import WIDELANDS_SVN_DIR - basedir = WIDELANDS_SVN_DIR + from django.conf import settings + basedir = settings.WIDELANDS_SVN_DIR except: basedir = p.join(p.dirname(__file__), p.pardir, p.pardir) @@ -20,7 +20,7 @@ @property def image(self): - return p.abspath(p.join(WIDELANDS_SVN_DIR, 'data', self._json['icon'])) + return p.abspath(p.join(settings.WIDELANDS_SVN_DIR, 'data', self._json['icon'])) class Ware(BaseDescr): === renamed file 'diff_match_patch.py' => 'wiki/diff_match_patch.py' === modified file 'wiki/forms.py' --- wiki/forms.py 2018-09-18 06:42:18 +0000 +++ wiki/forms.py 2019-04-07 09:29:16 +0000 @@ -7,14 +7,15 @@ from wiki.models import Article from wiki.models import ChangeSet -from settings import WIKI_WORD_RE +from django.conf import settings + try: from notification import models as notification except: notification = None -wikiword_pattern = re.compile('^' + WIKI_WORD_RE + '$') +wikiword_pattern = re.compile('^' + settings.WIKI_WORD_RE + '$') class ArticleForm(forms.ModelForm): === modified file 'wiki/urls.py' --- wiki/urls.py 2017-02-24 20:12:28 +0000 +++ wiki/urls.py 2019-04-07 09:29:16 +0000 @@ -3,7 +3,7 @@ from django.conf.urls import * from django.http import HttpResponseRedirect from wiki import views, models -from settings import WIKI_URL_RE +from django.conf import settings from django.views.generic import RedirectView from wiki.feeds import RssHistoryFeed, AtomHistoryFeed, RssArticleHistoryFeed, AtomArticleHistoryFeed @@ -25,38 +25,38 @@ # Feeds url(r'^feeds/rss/$', RssHistoryFeed(), name='wiki_history_feed_rss'), url(r'^feeds/atom/$', AtomHistoryFeed(), name='wiki_history_feed_atom'), - url(r'^(?P<title>' + WIKI_URL_RE + r')/feeds/rss/$', RssArticleHistoryFeed(), + url(r'^(?P<title>' + settings.WIKI_URL_RE + r')/feeds/rss/$', RssArticleHistoryFeed(), name='wiki_article_history_feed_rss'), - url(r'^(?P<title>' + WIKI_URL_RE + r')/feeds/atom/$', AtomArticleHistoryFeed(), + url(r'^(?P<title>' + settings.WIKI_URL_RE + r')/feeds/atom/$', AtomArticleHistoryFeed(), name='wiki_article_history_feed_atom'), - url(r'^(?P<title>' + WIKI_URL_RE + r')/$', + url(r'^(?P<title>' + settings.WIKI_URL_RE + r')/$', views.view_article, name='wiki_article'), - url(r'^(?P<title>' + WIKI_URL_RE + r')/(?P<revision>\d+)/$', + url(r'^(?P<title>' + settings.WIKI_URL_RE + r')/(?P<revision>\d+)/$', views.view_article, name='wiki_article_revision'), - url(r'^edit/(?P<title>' + WIKI_URL_RE + r')/$', + url(r'^edit/(?P<title>' + settings.WIKI_URL_RE + r')/$', views.edit_article, name='wiki_edit'), - url(r'observe/(?P<title>' + WIKI_URL_RE + r')/$', + url(r'observe/(?P<title>' + settings.WIKI_URL_RE + r')/$', views.observe_article, name='wiki_observe'), - url(r'observe/(?P<title>' + WIKI_URL_RE + r')/stop/$', views.stop_observing_article, + url(r'observe/(?P<title>' + settings.WIKI_URL_RE + r')/stop/$', views.stop_observing_article, name='wiki_stop_observing'), - url(r'^history/(?P<title>' + WIKI_URL_RE + r')/$', + url(r'^history/(?P<title>' + settings.WIKI_URL_RE + r')/$', views.article_history, name='wiki_article_history'), - url(r'^history/(?P<title>' + WIKI_URL_RE + r')/changeset/(?P<revision>\d+)/$', views.view_changeset, + url(r'^history/(?P<title>' + settings.WIKI_URL_RE + r')/changeset/(?P<revision>\d+)/$', views.view_changeset, name='wiki_changeset',), - url(r'^history/(?P<title>' + WIKI_URL_RE + r')/changeset/(?P<revision_from>\d+)/(?P<revision>\d+)/$', views.view_changeset, + url(r'^history/(?P<title>' + settings.WIKI_URL_RE + r')/changeset/(?P<revision_from>\d+)/(?P<revision>\d+)/$', views.view_changeset, name='wiki_changeset_compare',), - url(r'^history/(?P<title>' + WIKI_URL_RE + r')/revert/$', views.revert_to_revision, + url(r'^history/(?P<title>' + settings.WIKI_URL_RE + r')/revert/$', views.revert_to_revision, name='wiki_revert_to_revision'), - url(r'^backlinks/(?P<title>' + WIKI_URL_RE + r')/$', views.backlinks, + url(r'^backlinks/(?P<title>' + settings.WIKI_URL_RE + r')/$', views.backlinks, name='backlinks'), ] === modified file 'wiki/views.py' --- wiki/views.py 2018-12-31 10:36:13 +0000 +++ wiki/views.py 2019-04-07 09:29:16 +0000 @@ -20,8 +20,8 @@ from mainpage.templatetags.wl_markdown import do_wl_markdown from markdownextensions.semanticwikilinks.mdx_semanticwikilinks import WIKILINK_RE -from wl_utils import get_real_ip -from wl_utils import get_valid_cache_key +from mainpage.wl_utils import get_real_ip +from mainpage.wl_utils import get_valid_cache_key import re import urllib === modified file 'wlggz/migrations/0001_initial.py' --- wlggz/migrations/0001_initial.py 2016-12-13 18:28:51 +0000 +++ wlggz/migrations/0001_initial.py 2019-04-07 09:29:16 +0000 @@ -3,7 +3,7 @@ from django.db import models, migrations from django.conf import settings -import wl_utils +import mainpage.wl_utils as wl_utils class Migration(migrations.Migration): === modified file 'wlggz/models.py' --- wlggz/models.py 2016-12-13 18:28:51 +0000 +++ wlggz/models.py 2019-04-07 09:29:16 +0000 @@ -9,12 +9,10 @@ from django.db import models from django.contrib.auth.models import User -from wl_utils import AutoOneToOneField +from mainpage.wl_utils import AutoOneToOneField from django.utils.translation import ugettext_lazy as _ from pybb.models import Post -import settings - class GGZAuth(models.Model): user = AutoOneToOneField( === modified file 'wlhelp/management/commands/update_help.py' --- wlhelp/management/commands/update_help.py 2018-03-24 09:22:11 +0000 +++ wlhelp/management/commands/update_help.py 2019-04-07 09:29:16 +0000 @@ -26,7 +26,7 @@ import subprocess import collections -from settings import MEDIA_ROOT, WIDELANDS_SVN_DIR, MEDIA_URL +from django.conf import settings from widelandslib.tribe import * from widelandslib.make_flow_diagram import make_all_subgraphs @@ -45,8 +45,8 @@ self._delete_old_media_dir( name) # You can deactivate this line if you don't need to clean house. - base_directory = os.path.normpath(WIDELANDS_SVN_DIR + '/data') - json_directory = os.path.normpath(MEDIA_ROOT + '/map_object_info') + base_directory = os.path.normpath(settings.WIDELANDS_SVN_DIR + '/data') + json_directory = os.path.normpath(settings.MEDIA_ROOT + '/map_object_info') tribeinfo_file = open(os.path.normpath( json_directory + '/tribe_' + name + '.json'), 'r') @@ -59,7 +59,7 @@ self._to.descr = tribeinfo['tooltip'] # copy icon dn = os.path.normpath('%s/wlhelp/img/%s/' % - (MEDIA_ROOT, tribeinfo['name'])) + (settings.MEDIA_ROOT, tribeinfo['name'])) try: os.makedirs(dn) except OSError, o: @@ -69,7 +69,7 @@ file = os.path.normpath(base_directory + '/' + tribeinfo['icon']) shutil.copy(file, new_name) self._to.icon_url = path.normpath( - '%s/%s' % (MEDIA_URL, new_name[len(MEDIA_ROOT):])) + '%s/%s' % (settings.MEDIA_URL, new_name[len(settings.MEDIA_ROOT):])) self._to.save() def parse(self, tribename, base_directory, json_directory): @@ -117,7 +117,7 @@ print('Deleting old media files...') sdir = os.path.normpath(os.path.join( - MEDIA_ROOT, 'wlhelp/img', tribename)) + settings.MEDIA_ROOT, 'wlhelp/img', tribename)) if os.path.exists(sdir): shutil.rmtree(sdir) @@ -144,7 +144,7 @@ """ dn = os.path.normpath('%s/wlhelp/img/%s/%s/' % - (MEDIA_ROOT, self._to.name, name)) + (settings.MEDIA_ROOT, self._to.name, name)) try: os.makedirs(dn) except OSError, o: @@ -153,7 +153,7 @@ new_name = path.join(dn, fname) shutil.copy(file, new_name) - return '%s%s' % (MEDIA_URL, new_name[len(MEDIA_ROOT):]) + return '%s%s' % (settings.MEDIA_URL, new_name[len(settings.MEDIA_ROOT):]) def _parse_workers(self, base_directory, workersinfo): """Put the workers into the database.""" @@ -283,9 +283,9 @@ help =\ '''Regenerates and parses the json files in a current checkout. ''' - def handle(self, directory=os.path.normpath(WIDELANDS_SVN_DIR + '/data'), **kwargs): + def handle(self, directory=os.path.normpath(settings.WIDELANDS_SVN_DIR + '/data'), **kwargs): - json_directory = os.path.normpath(MEDIA_ROOT + '/map_object_info') + json_directory = os.path.normpath(settings.MEDIA_ROOT + '/map_object_info') if not os.path.exists(json_directory): os.makedirs(json_directory) @@ -295,7 +295,7 @@ # First, we make sure that JSON files have been generated. current_dir = os.path.dirname(os.path.realpath(__file__)) is_json_valid = False - os.chdir(WIDELANDS_SVN_DIR) + os.chdir(settings.WIDELANDS_SVN_DIR) try: subprocess.check_call( [os.path.normpath('wl_map_object_info'), json_directory]) @@ -306,7 +306,7 @@ # Now we validate that they are indeed JSON files (syntax check only) validator_script = os.path.normpath( - WIDELANDS_SVN_DIR + '/utils/validate_json.py') + settings.WIDELANDS_SVN_DIR + '/utils/validate_json.py') if not os.path.isfile(validator_script): print("Wrong path for 'utils/validate_json.py': " + validator_script + ' does not exist!') === modified file 'wlhelp/management/commands/update_help_pdf.py' --- wlhelp/management/commands/update_help_pdf.py 2016-07-02 12:38:06 +0000 +++ wlhelp/management/commands/update_help_pdf.py 2019-04-07 09:29:16 +0000 @@ -1,7 +1,7 @@ from ...models import Tribe as TribeModel from django.core.management.base import BaseCommand, CommandError -from settings import MEDIA_ROOT, WIDELANDS_SVN_DIR, MEDIA_URL +from django.conf import settings import os import shutil @@ -17,7 +17,7 @@ help =\ """Update the overview pdfs of all tribes in a current checkout""" - def handle(self, json_directory=os.path.normpath(MEDIA_ROOT + '/map_object_info'), **kwargs): + def handle(self, json_directory=os.path.normpath(settings.MEDIA_ROOT + '/map_object_info'), **kwargs): source_file = open(os.path.normpath( json_directory + '/tribes.json'), 'r') tribesinfo = json.load(source_file) @@ -31,7 +31,7 @@ pdffile = path.join(gdir, tribename + '.pdf') giffile = path.join(gdir, tribename + '.gif') - targetdir = path.normpath(path.join(MEDIA_ROOT, 'wlhelp', + targetdir = path.normpath(path.join(settings.MEDIA_ROOT, 'wlhelp', 'network_graphs', tribename)) try: @@ -45,9 +45,9 @@ tribe = Tribe.objects.get(name=tribename) if tribe: tribe.network_pdf_url = path.normpath( - '%s/%s/%s' % (MEDIA_URL, targetdir[len(MEDIA_ROOT):], tribename + '.pdf')) + '%s/%s/%s' % (settings.MEDIA_URL, targetdir[len(settings.MEDIA_ROOT):], tribename + '.pdf')) tribe.network_gif_url = path.normpath( - '%s/%s/%s' % (MEDIA_URL, targetdir[len(MEDIA_ROOT):], tribename + '.gif')) + '%s/%s/%s' % (settings.MEDIA_URL, targetdir[len(settings.MEDIA_ROOT):], tribename + '.gif')) tribe.save() else: print 'Could not set tribe urls' === modified file 'wlhelp/views.py' --- wlhelp/views.py 2018-03-09 12:12:02 +0000 +++ wlhelp/views.py 2019-04-07 09:29:16 +0000 @@ -3,8 +3,6 @@ from django.http import HttpResponse from .models import Worker, Ware, Building, Tribe -from settings import WIDELANDS_SVN_DIR, MEDIA_ROOT - def index(request): tribes = Tribe.objects.all().order_by('displayname') === modified file 'wlimages/models.py' --- wlimages/models.py 2018-10-03 20:25:05 +0000 +++ wlimages/models.py 2019-04-07 09:29:16 +0000 @@ -6,7 +6,7 @@ from django.utils.translation import ugettext_lazy as _ from django.db import IntegrityError from datetime import datetime -from settings import MEDIA_ROOT, MEDIA_URL +from django.conf import settings from django.core.files.storage import FileSystemStorage @@ -39,7 +39,7 @@ safe_filename = storage.get_valid_name(image.name) im = self.create(content_type=content_type, object_id=object_id, user=user, revision=1, name=image.name) - path = '%swlimages/%s' % (MEDIA_ROOT, safe_filename) + path = '%swlimages/%s' % (settings.MEDIA_ROOT, safe_filename) destination = open(path, 'wb') for chunk in image.chunks(): === modified file 'wlmaps/forms.py' --- wlmaps/forms.py 2017-03-07 16:02:24 +0000 +++ wlmaps/forms.py 2019-04-07 09:29:16 +0000 @@ -7,11 +7,10 @@ from django import forms from django.forms import ModelForm from django.core.files.storage import default_storage +from django.conf import settings -from settings import MEDIA_ROOT from wlmaps.models import Map import os -from settings import WIDELANDS_SVN_DIR class UploadMapForm(ModelForm): """ @@ -46,7 +45,7 @@ try: # Try to make a safe filename safe_name = default_storage.get_valid_name(mem_file_obj.name) - file_path = MEDIA_ROOT + 'wlmaps/maps/' + safe_name + file_path = settings.MEDIA_ROOT + 'wlmaps/maps/' + safe_name saved_file = default_storage.save(file_path, mem_file_obj) except UnicodeEncodeError: self._errors['file'] = self.error_class( @@ -57,7 +56,7 @@ try: # call map info tool to generate minimap and json info file old_cwd = os.getcwd() - os.chdir(WIDELANDS_SVN_DIR) + os.chdir(settings.WIDELANDS_SVN_DIR) check_call(['wl_map_info', saved_file]) # TODO(shevonar): delete file because it will be saved again when @@ -90,7 +89,7 @@ # mapinfo["minimap"] is an absolute path. # We partition it to get the correct file path - minimap_path = mapinfo['minimap'].partition(MEDIA_ROOT)[2] + minimap_path = mapinfo['minimap'].partition(settings.MEDIA_ROOT)[2] self.instance.minimap = '/' + minimap_path # the json file is no longer needed === modified file 'wlmaps/tests/test_views.py' --- wlmaps/tests/test_views.py 2018-11-18 17:22:39 +0000 +++ wlmaps/tests/test_views.py 2019-04-07 09:29:16 +0000 @@ -11,8 +11,6 @@ import os -from settings import MEDIA_ROOT - elven_forests = os.path.dirname(__file__) + '/data/Elven Forests.wmf' ########### === modified file 'wlmaps/views.py' --- wlmaps/views.py 2018-11-18 17:22:39 +0000 +++ wlmaps/views.py 2019-04-07 09:29:16 +0000 @@ -7,9 +7,10 @@ from django.contrib.auth.decorators import login_required from django.http import HttpResponseRedirect, HttpResponseNotAllowed, HttpResponse, HttpResponseBadRequest from django.urls import reverse +from django.conf import settings import models -from settings import MAPS_PER_PAGE -from wl_utils import get_real_ip + +from mainpage.wl_utils import get_real_ip import os @@ -20,7 +21,7 @@ maps = models.Map.objects.all() return render(request, 'wlmaps/index.html', {'maps': maps, - 'maps_per_page': MAPS_PER_PAGE, + 'maps_per_page': settings.MAPS_PER_PAGE, }) === modified file 'wlprofile/forms.py' --- wlprofile/forms.py 2016-12-13 18:28:51 +0000 +++ wlprofile/forms.py 2019-04-07 09:29:16 +0000 @@ -9,7 +9,7 @@ from django import forms from models import Profile -import settings +from django.conf import settings import re === modified file 'wlprofile/migrations/0001_initial.py' --- wlprofile/migrations/0001_initial.py 2016-12-13 18:28:51 +0000 +++ wlprofile/migrations/0001_initial.py 2019-04-07 09:29:16 +0000 @@ -3,7 +3,7 @@ from django.db import models, migrations from django.conf import settings -import wl_utils +import mainpage.wl_utils as wl_utils import wlprofile.fields === modified file 'wlprofile/models.py' --- wlprofile/models.py 2018-12-21 09:50:32 +0000 +++ wlprofile/models.py 2019-04-07 09:29:16 +0000 @@ -1,11 +1,11 @@ from django.db import models from django.contrib.auth.models import User from fields import ExtendedImageField -from wl_utils import AutoOneToOneField +from mainpage.wl_utils import AutoOneToOneField from django.utils.translation import ugettext_lazy as _ from pybb.models import Post -import settings +from django.conf import settings TZ_CHOICES = [(float(x[0]), x[1]) for x in ( (-12, '-12'), (-11, '-11'), (-10, '-10'), (-9.5, '-09.5'), (-9, '-09'), === modified file 'wlprofile/templatetags/custom_date.py' --- wlprofile/templatetags/custom_date.py 2018-04-08 14:40:17 +0000 +++ wlprofile/templatetags/custom_date.py 2019-04-07 09:29:16 +0000 @@ -18,7 +18,7 @@ from django.contrib.auth.models import User import re from datetime import date as ddate, tzinfo, timedelta, datetime -from settings import DEFAULT_TIME_ZONE, DEFAULT_TIME_DISPLAY +from django.conf import settings register = template.Library() @@ -132,12 +132,12 @@ """If this user is logged in, return his representation, otherwise, return a sane default.""" if not user.is_authenticated: - return do_custom_date(DEFAULT_TIME_DISPLAY, date, float(DEFAULT_TIME_ZONE)) + return do_custom_date(settings.DEFAULT_TIME_DISPLAY, date, float(settings.DEFAULT_TIME_ZONE)) try: userprofile = User.objects.get(username=user).wlprofile return do_custom_date(userprofile.time_display, date, userprofile.time_zone) except ObjectDoesNotExist: - return do_custom_date(DEFAULT_TIME_DISPLAY, date, float(DEFAULT_TIME_ZONE)) + return do_custom_date(settings.DEFAULT_TIME_DISPLAY, date, float(settings.DEFAULT_TIME_ZONE)) custom_date.is_safe = False === modified file 'wlscreens/models.py' --- wlscreens/models.py 2018-04-08 16:23:55 +0000 +++ wlscreens/models.py 2019-04-07 09:29:16 +0000 @@ -7,7 +7,7 @@ from django.core.files.uploadedfile import SimpleUploadedFile, UploadedFile from django.core.files.storage import FileSystemStorage import os -from settings import THUMBNAIL_SIZE, MEDIA_ROOT +from django.conf import settings from django.urls import reverse @@ -21,7 +21,7 @@ # If the filename already exists, remove it as if it was a true file # system if self.exists(name): - os.remove(os.path.join(MEDIA_ROOT, name)) + os.remove(os.path.join(settings.MEDIA_ROOT, name)) return name @@ -80,7 +80,7 @@ if image.mode not in ('L', 'RGB'): image = image.convert('RGB') - image.thumbnail(THUMBNAIL_SIZE, Image.ANTIALIAS) + image.thumbnail(settings.THUMBNAIL_SIZE, Image.ANTIALIAS) # Save the thumbnail temp_handle = StringIO() === modified file 'wlscreens/tests/test_models.py' --- wlscreens/tests/test_models.py 2016-12-13 18:28:51 +0000 +++ wlscreens/tests/test_models.py 2019-04-07 09:29:16 +0000 @@ -9,7 +9,7 @@ # Last Modified: $Date$ # -from settings import THUMBNAIL_SIZE +from django.conf import settings from django.test import TestCase as DjangoTest from django.db import IntegrityError from django.core.files.uploadedfile import SimpleUploadedFile @@ -71,7 +71,7 @@ screenshot=self.img, comment='This rockz!') self.assertEqual(i.pk, 1) - self.assertEqual(i.thumbnail.width, THUMBNAIL_SIZE[0]) + self.assertEqual(i.thumbnail.width, settings.THUMBNAIL_SIZE[0]) class TestScreenshot(_ScreenshotBase):
_______________________________________________ Mailing list: https://launchpad.net/~widelands-dev Post to : widelands-dev@lists.launchpad.net Unsubscribe : https://launchpad.net/~widelands-dev More help : https://help.launchpad.net/ListHelp