Giter Site home page Giter Site logo

tutorial's Introduction

Django Girls website

Build Status codecov

This repository contains the Django application which powers DjangoGirls.org.

What's in it?

It's a simple CMS that contains 3 main models:

  • Event - a list of events and their website configuration
  • EventPageContent - blocks of content that are visible on the website
  • EventPageMenu - items of menu of every website

How to create new event?

Simply go to command line and run this command:

python ./manage.py new_event

And then follow the instructions.

How to manage your website?

Event

http://djangogirls.org/admin/core/event/

Here you can change:

  • Meta tags - title and description of the website
  • Main color - main color on the website in HEX (default is FF9400)
  • Custom CSS - customize CSS on the website
  • URL - url that goes after the domain (http://djangogirls.org/__url__)
  • Is live? - live website is available on the homepage and can be accessed by anyone

EventPageContent

http://djangogirls.org/admin/core/eventpagecontent/

Each website comes with some default content that you can adjust to your needs. Each object is a "block" on the website that you can modify in following ways:

  • Name - it's also a permalink that you can link to like this: #name
  • Content - HTML is allowed
  • Background - there are two available types of blocks: without background and with background. By uploading image you're choosing the type with background.
  • Is public - check this if you want this block to be visible

EventPageMenu

http://djangogirls.org/admin/core/eventpagemenu/add/

To manage menu available on the website, you can add objects to EventPageMenu. Available options:

  • Title
  • URL

Contributing to Django Girls website

The website is hosted on PythonAnywhere and is available here: http://djangogirls.org/

Please note that we use Python 3 only, so make sure that you use correct version when running commands below.

Setting up a development environment

First, fork and clone the repository:

git clone [email protected]:your-username/djangogirls.git

Step into newly created djangogirls directory:

cd djangogirls

Docker

If you have Docker and Docker compose installed, run docker-compose up

Non Docker

Create a new virtual environment (Python 3.10) if needed. Then, install all the required dependencies.

The dependencies are compiled by pip-tools, which compiles requirements.txt ensuring compatibility between packages.

pip install pip-tools
pip-sync

There is more information on how pip-tools work below in Using pip-tools.

Install the pre-commit hook. It's useful so we automatically format and lint code before committing any changes.

pre-commit install

Start the PostgreSQL database server and enter the psql shell (you need to have PostgreSQL installed):

psql

In the psql shell, create a database and a role with the necessary permissions:

CREATE DATABASE djangogirls;
CREATE ROLE postgres;
GRANT ALL privileges ON DATABASE djangogirls TO postgres;
ALTER ROLE postgres WITH LOGIN;

Exit the psql shell:

\q

Run the migration to create database schema:

./manage.py migrate

Load sample data to the database

./manage.py loaddata sample_db.json

Create a user so you can login to the admin:

./manage.py createsuperuser

Install dependencies for static files:

npm install

Compile CSS and JS files:

gulp watch

Run your local server:

./manage.py runserver

🎉 You're done.

Run the tests

You can run the tests like this:

python -m pytest

Or if you want coverage reports:

python -m pytest --cov

For a coverage report with information about missing lines, run this:

python -m pytest --cov-report term-missing --cov

Static files

We're using a Stylus as our CSS pre-processor. Get styling with Stylus.

This means you shouldn't change any css files, but .styl files. They're in /static/source/css/ directory.

Autocompiling of .styl files to .css:

npx gulp watch

We're also using gulp for our static files builds (see below). To build static files for production, run this:

npx gulp build

For local development:

npx gulp local

Gulp Tasks

Static files are generated and maintained using gulp.js. To use, you'll need Node.js installed. Then, run npm install. You can now use npx gulp (note that it's np**x**), followed by one of the following commands:

  • gulp local - run a one-off local build of css & js
  • gulp watch - compile and watch static assets for changes
  • gulp build - run a one-off production build, which involves minifying code and asset revision markers
  • gulp clean - remove the results of any of the above commands

Running gulp on its own runs watch by default.

Developing Gulp Tasks

Each gulp task is a single function, which are combined using the series operator so they run as a workflow. Each are commented with what they do and why they're important.

The biggest gotcha is async completion. Each task much signal to gulp when it has finished. The easiest way to do this is using an aysnc function, but if your functionality uses gulp streams (most native gulp functionality does), then you should not use an async function. Instead, return the gulp stream from the function and it will be handled correctly.

// WRONG - uses gulp's streams in an async function; subsequent tasks won't wait for completion correctly:
const copyFiles = async () => {
    return gulp.src(...).pipe(gulp.dest(...))
}

// RIGHT - either returns a gulp stream _or_ uses an `async` function:
const copyFiles = () => {
    return gulp.src(...).pipe(gulp.dest(...))
}
const deleteFiles = async () => {
    await del(...)
}

Hosting on PythonAnywhere

Key bits of config and secrets are stored in environment variables in two places:

  • in the WSGI file (linked from the Web Tab)
  • in the virtualenv postactivate at ~/.virtualenvs/djangogirls.com/bin/postactivate

Google Apps API integration

We're using Google Apps Admin SDK for creating email accounts in djangogirls.org domain automatically.

Several things were needed to get this working:

  1. Create an app in Developer Console
  2. Create a service account to enable 2 legged oauth (https://developers.google.com/identity/protocols/OAuth2ServiceAccount)
  3. Enable delegation of domain-wide authority for the service account.
  4. Enable Admin SDK for the domain.
  5. Give the service account permission to access admin.directory.users service (https://admin.google.com/AdminHome?chromeless=1#OGX:ManageOauthClients).

Using pip-tools

The packages required by the project are in requirements.in which looks like a regular requirements file. Specific versions of packages can be specified, or left without a version in which case the latest version which is compatible with the other packages will be used.

If you are working on a feature which requires a new package, add it to requirements.in, specifying a version if necessary. It's dependencies will be included in requirements.txt by the compile process.

The only time a dependency of a third party package needs adding to requirements.in is when a version has to be pinned.

By running pip-compile the requirements are compiled into requirements.txt.

Periodically requirements should be updated to ensure that new versions, most importantly security patches, are used. This is done using the -U flag.

Once requirements are compiled, pip-sync will install the requirements, but also remove any packages not required. This helps to ensure you have the packages required, but also that there isn't something installed that's missed from requirements.txt.

For example:

pip-compile -U
pip-sync

Handling environment variables

The requirements.txt installs python-dotenv which provides the option for developers to load environment variables via a single file.

You'll see .environment-example in the project root. This contains environment variables used by the project so that you can create your own copy of this and load it with values relevant to your development environment.

To make use of this feature, create a copy of the example file and call it .environment. This file will be ignored by version control, but loaded by manage.py. So when you run django commands like manage.py runserver during development python-dotenv will load the environment variables from your .environment file so that they are available to the application.

This is an optional feature. If you do not have a .environment file then it won't impact on the application at all.

Before you Open a Pull Request

This project runs a linting check with flake8 whenever a pull request is merged. Before you create a pull request, it's advisable to fix any linting issues locally to avoid errors while merging. In order to have flake8 run in your local machine automatically you can do the following:

  1. Run pip install pre-commit to install pre-commit. This package helps setting up git hooks.

  2. Run pre-commit install to install the git hook. After this, whenever you run git commit in your local machine, flake8 will run and report any linting errors that it found.

  3. If you've already committed your changes before installing pre-commit, you can follow steps 1 and 2 and then run pre-commit run --all-files to run flake8 against all of the files.

Help with translation of the website

Join us on poeditor.com to help with translation of the website so that non-English speakers can view the website based on their locale.

Languages available for translation are;

  • French
  • German
  • Korean
  • Persian
  • Portuguese
  • Portuguese (BR)
  • Russian
  • Spanish

See issue 571- Website internationalization/translations for further details. Alternatively submit the pull request to the translations branch.

tutorial's People

Contributors

agatku avatar amakarudze avatar aniav avatar asendecka avatar baradrb avatar bcopy avatar bmispelon avatar cgl avatar citmusa avatar das-g avatar ekohl avatar helenst avatar hjwp avatar hpfn avatar jhodgdon-drp avatar kaizumaki avatar kieczkowska avatar kyzn avatar magul avatar mrsqd avatar nikhiljohn10 avatar normade avatar oinopion avatar olasitarska avatar patjouk avatar phalt avatar rapoulson avatar rsip22 avatar tricoder42 avatar wagyx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tutorial's Issues

Problems with heroku-push

  1. Looks like heroku-push ignores the .gitignore file, and pushes local-settings.py.
    We solved this by putting all the settings in settings.py and got rid of local-settings.py.
  2. It doesn't trigger the creation of a Postgres database on Heroku. We had to do this manually.

Decide on one, either localhost or 127.0.0.1

It is mixed right now, we should stick to one notation. Argument for 127.0.0.1: when you use runserver it says you should go to 127.0.0.1:8000. Argument for locahost: it's easier to write :).

Heroku static files

There were some problems with static files on Heroku (when you change DEBUG to False). @jezdez had a solution for that, can you remind us what it was?

Creating blog entries while not logged in results in an ugly error

The current tutorial plays around with the admin-interface first and thus a user is logged in and everything is working fine.

But once people play around and redo their database, the authenticated user is lost. When you then try to save a new blog-post, everything blows up as it tries to set the anonymous user as author.

Resolve PostgreSQL issues

Possibly doing a sqlite setup on local and using Postgres only for Heroku as suggested by @lukaszb and few others would be a much (much, much!) better way.

Deploy chapter - heroku create

In the deploy chapter, we're using the command:

$ heroku create

This is fine, but it could be worth pointing out that it's possible to do:

$ heroku create {NAME}

where {NAME} is replaced with the desired app name (rather than using a default one generated by Heroku).

Env setup instructions not sufficient for Ubuntu 14.04

Following the tutorial instructions will not work cleanly on Ubuntu 14.04; I encountered issues with both the virtual environment and the PostgreSQL setup instructions:

Virtualenv:

$ python3 -m venv venv
Error: Command '['/home/eddie/Slask/tmp/venv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1

PostgreSQL:

$ psql
psql: FATAL:  role "eddie" does not exist

I managed to solve the problems with some googling, but since this is supposed to be a very n00b-friendly guide, that should not be required.

The virtualenv-issue can be solved by installing python-virtualenv and then using the virtualenv-command instead of the command supplied in the tutorial. A fix for the problem is submitted upstream but I have no idea when it will trickle down to Trusty Tahr.

From what I can determine, the psql issue is due to the fact that, by default, only the user postgres has access to the PostgreSQL server by default. I solved it by adding myself as a PostgreSQL superuser, and editing some config files.

I can update the documentation to include the solutions to these issues. Would you like a pull request?

Check everything for style

  • consistent style for talking to reader ("you", "us", etc)
  • reward readers for progress with "congrats", and "keep up the good work!" a lot
  • add some cupcakes, illustrations and jokes :)
  • easy explanations for hard terms

Inconsistent terminology

As the code is OS agnostic and focuses on CLI not GUI the tutorial starts off making directories and later switches between folder/directory terminology.

Querysets

After adding models it'd be cool to go to shell and have a little fun with Querysets to show what models can do.

Make a glossary

Gitbook has a nice feature of making glossaries and it automatically links the words to their explanations. We need to add GLOSSARY.md file in the main directory and the structure of the file is really simple:

# Keyword
Explanation

# Keyword
Explanation

Advanced Tutorial on Authentication

Current state when the blog is finished is that there is no authentication on authoring stuff. So anyone can add/edit posts on any of the created blogs. Not good...

There should be an advanced tutorial on adding authentication and authorization. I might even volunteer to start that now...

Please have a teacher make a deep review of the course

As a teacher I have to say that this course is not very well designed in terms of learning curve. The golden rule of all good handbooks is to make solid grounds - explain and excercise easy things and then gradually introduce more complex topics. I found that just at the very beginning of "Introduction to Python" the reader is bashed with methods and dot notation in VERY confusing way that almost stops them from further reading. It's supposed to be introduction for newbies! Let them play with numbers and strings, give them lists and dictionaries. And then introduce objects with their attributes and methods.

Having said all that I urge you to hand this course to at least a couple of CS teachers and note their comments. I will help as much as I can but unfortunatelly I don't have that much time.

Static files on Heroku

Setting DEBUG = False breaks static files on Heroku. The simple solution would be to switch DEBUG on again but that's not the best solution in terms of security...

Command Line chapter more interactive

I think that it's good that command line chapter was added, but I think we should try to make it more interactive. Not only list and explain commands, but let people try them and see how they work.

Improvements to deploy chapter

  • moving it earlier in the process so we can deploy more often
  • slowing things down a little bit - a lot of new things happen there very fast

Visit your application - what's process type and dyno running?

In the Deploy chapter, in the Visit your application section, there are two paragraphs there are not clear for me:

You’ve deployed your code to Heroku, and specified the process types in a Procfile. You can now instruct Heroku to execute a process type.

Let’s ensure we have one dyno running the web process type:

You lost me there.

Can anyone maybe add a sentence or two to explain what's process type and dyno? Or maybe to phrase it differently so it's easier to understand?

Thanks a lot for anyone that will! :)

RFC: Re-order the tutorial

A beer-driven idea from Tomek and me: What if the tutorial is reordered?

Currently the deployment happens near the end of the day (with a version that is working but insecure...), what if deployment to a public space was moved more in front after the step where one can see first results. So after the step where blog-posts are added via admin-interface and displayed on the front-page, it would be a good point to deploy to heroku and be proud of it.

Treats should not only be unhealthy food

"Grab yourself a cupcake and go to the next chapter :)"
"Works like a charm? We're proud! Treat yourself something sweet, you have earned it :)"

Puts a pretty cliche picture on women, don't you think? What about changing these two lines and pictures to:

"Well done so far! Celebrate by doing something good for you - taking a short walk, go have a little chat with someone, watch your favorite youtube video or do anything else you would like to do right now."

"Works like a charm? We're proud! Treat yourself with something special, you have earned it :)"

Tutorial Chapter 10 "Bug"

In my environment there is no initial user created, when arriving at this passage in the tutorial (section 10 Django ORM (Querysets)):

What users do we have in our database? Try this:

>>> User.objects.all()
[<User: ola>]

I simply ran the following, to get a dummyuser to use:

>>> User.objects.create(username='myuser')

What about adding this command to the tutorial section?

Add "real" README

The README is currently the first page of the book. But in my opinion it would be better if the README would explain the purpose of the project and how to create, edit and contribute to it.

For example it is not obvious for someone who has no experience with gitbook how to install it and serve the book locally.

Better explanation of Models

During after-workshop coaches meeting someone suggested that explaining Models as tables (and comparing to spreadsheet) is a much better idea than our current one.

Is there someone who is against this?

Proofreading

If you're a native English speaker (or just know English well!), have some time on your hands and want to help, we would really appreciate if you could help proof read this tutorial!

You can see preview here: http://book.djangogirls.org/.

How to do it?

  • comment this thread with the names of chapter you want to proofread. Make sure that anyone else is not reading them already. If all the chapters are "taken", just read from the beginning to see if there is something others didn't catch.
  • fork this repository, change and pull request
  • receive a 👍 and 😍 from DjangoGirls! :)

Already corrected chapters:

In progress:

TO DO:

  • Django ORM
  • Django templates
  • CSS
  • Template extending
  • Extend your application
  • Deploy!
  • Django Forms
  • Domain
  • Homework

I'll be updating this post.

Improvements in HTML/Template chapters

A friend (Andrew Nesbitt) just went through our tutorial as a Python newbie and sent me his feedback. There are two things we can improve on, so I am just adding it here because I will forget it :)

  1. When first adding the templates in http://tutorial.djangogirls.org/html/README.html I had to restart the server to get it to find the new templates, you mention about restarting the server in a later stage in the tutorial but not in that one.
  2. I couldn't get http://tutorial.djangogirls.org/template_extending/README.html to work using just the content on the page, kept getting the TemplateDoesNotExists error, even after restarting, I ended up adding the following code to get it to work: https://github.com/andrew/django-girls-tutorial/blob/master/mysite/settings.py#L90-L92

The "Installation" book should not include "What is Django?" chapter

I hope this is the right place for this issue, I couldn't find anything better!

I'm just going through the Installation book that was linked in the recent email to teams and coaches. I've notices that the "What is Django?" chapter seems a little out of place. Could we remove it from there (it should still stay in the main tutorial ofcourse!) and maybe add the one about the Code Editor instead?

Thanks!

Newly added part on dictionaries (Intro to Python chapter)

Just went looking at the newly added part in the intro chapter (dictionaries, see #77) to check for mistakes and wanted to ask: does anyone mind if I replace the example (django "dolls") with something else?

I was actually a little confused at first - I thought "dolls" (which is sometimes used a little condescendingly) was used instead of "girls" so as not to be too repetitive - but even now that I've realised that it refers indeed to toy dolls, it seems a little... off, especially considering that the tutorial isn't aimed at little girls but adult women mostly.

Proposal to move Deploy section to the end of tutorial

During the workshop Deployment section took us quite some time so we decided to skip it and finish it at the end if time persists. Other mentors did the same thing after number of different minor errors.

I'd propose to move it at the end of tutorial.

Add LICENSE and appropriate credit

Currently the tutorial does not contain a LICENSE. This means all content can't be changed, used and published by others without explicit allowance by the original authors. This is even true for all people that contributed so far.

Because I believe that this is not the intention of the original authors a LICENSE file should be added to the repository.

Parts of the tutorial use content from other tutorials. One of them is my Django tutorial django-marcador. It is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. In my opinion there are two things that need to be changed to meet the requirements of the license:

  1. The way credit is given does not match the terms of the CC-BY-SA 4.0 license. it says that a user must "provide the name of the creator and attribution parties, a copyright notice, a license notice, a disclaimer notice, and a link to the material".
  2. Because the license is a "ShareAlike" license the Django Girls tutorial must also be licensed under a CC-BY-SA 4.0 license.

License and proper credits could look like this:

# License

This work is licensed under the Creative Commons Attribution-ShareAlike 4.0
International License. To view a copy of this license, visit
http://creativecommons.org/licenses/by-sa/4.0/ or send a letter to Creative
Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

## Authors

- Ola Sitarska
- Ola Sendecka
- Baptiste Mispelon
- ...

## Credits

Parts of this work are based on the [django-marcador
tutorial](http://django-marcador.keimlink.de/) licensed under Creative Commons
Attribution-ShareAlike 4.0 International License. The django-marcador tutorial
is copyrighted by Markus Zapke-Gründemann et al.

Of course you can split the authors section into main authors and contributors if you want to.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.