FLOSS Project Planets

Real Python: When to Use a List Comprehension in Python

Planet Python - Sat, 2024-12-07 09:00

List comprehensions in Python provide a concise way to create lists by embedding a loop and optional conditional logic in a single line. You use a list comprehension to transform and filter elements from an iterable efficiently. It allows you to replace complex loops and map() functions with more readable and often faster expressions. By understanding list comprehensions, you can optimize your code for better performance and clarity.

You can add conditional logic to a list comprehension in Python by appending an if statement to the end of the expression. This allows you to filter elements based on a condition, effectively replacing the need for filter() in many cases. Additionally, you can use conditional expressions at the beginning to choose between different outcomes, enhancing the versatility of your list comprehensions.

By the end of this tutorial, you’ll understand that:

  • A list comprehension in Python is a tool for creating lists by iterating over an iterable and optionally applying a condition.
  • You should use list comprehensions instead of loops when you want concise, readable code that performs transformations or filtering.
  • You add conditional logic to a list comprehension by including an if statement within the comprehension.
  • A list comprehension can be faster than a for loop because it’s optimized for performance by Python’s internal mechanisms.
  • A Python list comprehension is not lazy—it generates and stores the entire list in memory eagerly.
  • The difference between list comprehensions and map() is that the former creates a list, while the latter returns a map object, which is iterable.
  • To optimize performance with list comprehensions, use them for small to medium-sized lists and profile different approaches to choose the fastest one.

In this tutorial, you’ll explore how to leverage list comprehensions to simplify your code. You’ll also gain an understanding of the trade-offs that come with using them so that you can determine when other approaches are preferable.

Get Your Code: Click here to download the free code that shows you how and when to use list comprehensions in Python.

Take the Quiz: Test your knowledge with our interactive “When to Use a List Comprehension in Python” quiz. You’ll receive a score upon completion to help you track your learning progress:

Interactive Quiz

When to Use a List Comprehension in Python

In this quiz, you'll test your understanding of Python list comprehensions. You'll revisit how to rewrite loops as list comprehensions, how to choose between comprehensions and loops, and how to use conditional logic in your comprehensions.

Transforming Lists in Python

There are a few different ways to create and add items to a lists in Python. In this section, you’ll explore for loops and the map() function to perform these tasks. Then, you’ll move on to learn about how to use list comprehensions and when list comprehensions can benefit your Python program.

Use for Loops

The most common type of loop is the for loop. You can use a for loop to create a list of elements in three steps:

  1. Instantiate an empty list.
  2. Loop over an iterable or range of elements.
  3. Append each element to the end of the list.

If you want to create a list containing the first ten perfect squares, then you can complete these steps in three lines of code:

Python >>> squares = [] >>> for number in range(10): ... squares.append(number * number) ... >>> squares [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] Copied!

Here, you instantiate an empty list, squares. Then, you use a for loop to iterate over range(10). Finally, you multiply each number by itself and append the result to the end of the list.

Work With map Objects

For an alternative approach that’s based in functional programming, you can use map(). You pass in a function and an iterable, and map() will create an object. This object contains the result that you’d get from running each iterable element through the supplied function.

As an example, consider a situation in which you need to calculate the price after tax for a list of transactions:

Python >>> prices = [1.09, 23.56, 57.84, 4.56, 6.78] >>> TAX_RATE = .08 >>> def get_price_with_tax(price): ... return price * (1 + TAX_RATE) ... >>> final_prices = map(get_price_with_tax, prices) >>> final_prices <map object at 0x7f34da341f90> >>> list(final_prices) [1.1772000000000002, 25.4448, 62.467200000000005, 4.9248, 7.322400000000001] Copied!

Here, you have an iterable, prices, and a function, get_price_with_tax(). You pass both of these arguments to map() and store the resulting map object in final_prices. Finally, you convert final_prices into a list using list().

Leverage List Comprehensions

List comprehensions are a third way of making or transforming lists. With this elegant approach, you could rewrite the for loop from the first example in just a single line of code:

Python >>> squares = [number * number for number in range(10)] >>> squares [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] Copied!

Rather than creating an empty list and adding each element to the end, you simply define the list and its contents at the same time by following this format:

Python Syntax new_list = [expression for member in iterable] Copied! Read the full article at https://realpython.com/list-comprehension-python/ »

[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]

Categories: FLOSS Project Planets

The Drop Times: Meet the Speakers: DrupalCon Singapore 2024 Part III

Planet Drupal - Sat, 2024-12-07 07:33
The excitement is palpable as DrupalCon Singapore 2024 kicks off tomorrow! In the final episode of our "Meet the Speakers" series, discover how Owen Lansbury of PreviousNext is redefining profitability through open-source business models, and learn from Aastha Shrivastava of QED42 as she spotlights Drupal’s role as a Digital Public Good. Get ready for three action-packed days of innovation, insights, and community from December 9-11, 2024. This is the moment the APAC Drupal community has been waiting for – don’t miss it!
Categories: FLOSS Project Planets

LostCarPark Drupal Blog: Drupal Advent Calendar day 7 - Base Recipe

Planet Drupal - Sat, 2024-12-07 04:00
Drupal Advent Calendar day 7 - Base Recipe james Sat, 12/07/2024 - 09:00

Today we are looking at one of the central elements of Starshot, but also one of the easiest to overlook.

Drupal CMS will come preinstalled with a set of base modules and themes, as the basis on which other recipes will be built. The base theme track is responsible for this. Not only does this provide essential functionality to make a new Drupal site much more usable, it also provides an important baseline for the other tracks to build upon.

Some of the functionality either already implemented, or planned past Drupal CMS 1.0, is listed below.

Pathauto is now installed by default. This is a small…

Tags
Categories: FLOSS Project Planets

Russ Allbery: Review: Dark Minds

Planet Debian - Sat, 2024-12-07 00:22

Review: Dark Minds, by Michelle Diener

Series: Class 5 #3 Publisher: Eclipse Copyright: 2016 ISBN: 0-6454658-5-2 Format: Kindle Pages: 328

Dark Minds is the third book in the self-published Class 5 science-fiction romance series. It is a sequel to Dark Deeds and should not be read out of order, but as with the other books of the series, it follows new protagonists.

Imogen, like another Earth woman before her, was kidnapped by a Class 5 for experimentation by the Tecran. She was subsequently transferred to a research facility and has been held in cages and secret military bases for over three months. As the story opens, she had been imprisoned in a Tecran transport for a couple of weeks when the transport is taken by the Krik who kill all of the Tecran crew. Next stop: another Class 5.

That same Class 5 is where the Krik are taking Camlar Kalor and his team. Cam is a Grih investigator from the United Council, sent to look into reports of a second Earth woman rescued from a Garmman ship. (The series reader will recognize this as the plot of Dark Deeds.) Now he's trapped with the crews of a bunch of other random ships in the cargo hold of a Class 5 with Krik instead of Tecran roaming the halls, apparently at the behest of the ship's banned AI, and a mysterious third Earth woman already appears to be befriending it.

Imogen is the woman Fiona saw signs of in Dark Deeds. She's had a rougher time than the protagonists of the previous two books in this series, and she's been dropped into a less stable situation. The Class 5 she's brought to at the start of the story is far more suspicious (with quite a lot of cause) and somewhat more hostile than the AIs we've encountered previously. The rest of the story formula is roughly the same, though: hunky Grih officer with a personality completely indistinguishable from the hunky Grih officers in the previous two books, an AI with a sketchy concept of morality that desperately needs an ally, the Grih obsession with singing, the eventual discovery of useful armor and weaponry that Imogen can use to surprise people, and more political maneuvering over the Sentient Beings Agreement.

This entry in the series mostly abandons the Grih shock and horror at how badly the Earth women have been treated. This makes sense, given how dangerous Earth women have proven over the course of this series, and I like that Diener is changing the political dynamics as the story develops. I do sometimes miss that appalled anger of Dark Horse, but Dark Minds focuses more on the politics and corridor fighting of a tense multi-sided stand-off.

I found the action more gripping in Dark Minds than in Dark Deeds, and I liked Imogen more as a character than Fiona. She doesn't have the delightfully calm competence of Rose from Dark Horse, but she's a bit more hardened, a bit more canny, and is better at taking control of situations. I also like that Diener avoids simplistically pairing Earth women off with Class 5s. The series plot is progressing faster than I had expected, and that gives this book a somewhat different shape than the previous ones.

Cam is probably the least interesting of the men in this series so far and appears to exist solely to take up the man-shaped hole in the plot. This is not a great series for gender roles; thankfully, the romance is a small part of the plot and largely ignorable. The story is about the women and the AIs, and all of the women and most of the AIs of the previous books make an appearance. It's clear they're forming an alliance whether the Grih like it or not, and that part of the story was very satisfying.

Up to this book, this series had been all feel-good happy endings. I will risk the small spoiler and warn that this is not true to the same degree here, so you may not want to read this one if you want something entirely fluffy, light, and positive (inasmuch as a series involving off-screen experimentation on humans can be fluffy, light, and positive). That caught me by surprise in a way I didn't entirely like, and I wish Diener had stuck with the entirely positive tone.

Other than that, though, this was fun, light, readable entertainment. It's not going to win any literary awards, it's formulaic, the male protagonist comes from central casting, and the emphasis by paragraph break is still a bit grating in places, but I will probably pick up the next book when I'm in the mood for something light. Dark Minds is an improvement over book two, which bodes well for the rest of the series.

Followed by Dark Matters.

Rating: 7 out of 10

Categories: FLOSS Project Planets

This Week in Plasma: Oodles of features!

Planet KDE - Fri, 2024-12-06 23:00

I promised new features soon, and here they are! There are plenty of positive UI changes too. Hopefully what this week's post lacks in quantity will be made up by depth, because these are some nice changes that have been in development for quite some time. Have a look:

Notable New Features

It's now possible to clone a panel! (Niccolò Venerandi, 6.3.0. Link)

KWin's Custom Tiling system now remembers tile arrangement on a per-virtual-desktop basis. (Marco Martin, 6.3.0. Link)

You can now set keyboard shortcuts to move windows between Custom Tiling (as opposed to Quick Tiling) tile zones based on directionality. No default shortcuts were set up for now because all the obvious Modifier+Arrow combinations were already taken. This is an avenue to ponder further in the future. (Akseli Lahtinen, 6.3.0. Link)

It's now possible to limit the upper and lower ranges for tablet pen pressure, not just the shape of the pressure curve. (Joshua Goins, 6.3.0. Link)

Notable UI Improvements

Categories in Kickoff no longer automatically switch on hover by default; they have to be clicked like all other list items elsewhere. This fixes a host of issues related to unexpected category switching and freezes when moving the pointer rapidly over categories. Those who preferred switch-on-hover can turn it back on if they like. (Noah Davis, 6.3.0. Link)

The way Quick Tiling (i.e. with Meta+Arrow keys) works has been slightly changed; now when trying to tile a window in a direction it can't be tiled in anymore because it has hit a screen edge with nothing beyond it, it will simply sit there, rather than un-tiling and teleporting to a potentially unexpected place. (Vlad Zahorodnii, 6.3.0. Link)

System Settings' Display & Monitor page now shows a slider for normal/SDR brightness for each screen, just in case you expected to find it there rather than in the System Tray's Brightness and Color widget. (Xaver Hugl, 6.3.0. Link)

When you hold down Alt+Tab to open the window switcher and then keep those keys held down, the selection highlight will now go all the way to the end, but will no longer hilariously wrap around infinitely until you release the keys again. (Ismael Asensio, 6.3.0. Link)

The active virtual desktop is now remembered per activity. (Xaver Hugl, 6.3.0. Link)

Notable Bug Fixes

Fixed a bug that could cause placeholder and typed text to overlap in KRunner's search field under certain circumstances. (Jack Xu, 6.2.5. Link)

Metadata displayed for Bing picture of the day wallpapers is now displayed correctly. (George Travelbacon, 6.2.5. Link)

When you copy images from Plasma notifications, they can now be pasted into sandboxed apps. (Alessandro Astone, 6.2.5. Link)

After using an application that goes through the input capture portal (e.g. Input Leap) and it quits unexpectedly, you now regain full control of your pointer and keyboard immediately. (David Redondo, 6.2.5 Link)

Keyboard navigation between a filtered subset of windows in the Overview effect now works as you expect it to. (Niccolò Venerandi, 6.3.0. Link)

When you delete a panel but haven't yet dismissed the option to unto this, the deleted panel no longer inappropriately and surprisingly responds to any keyboard shortcuts that toggle any of their widgets. (Niccolò Venerandi, 6.3.0. Link)

Other bug information of note:

Notable in Performance & Technical

Slightly increased the performance of every app and window that uses KWindowStateSaver. (David Edmundson, Frameworks 6.9, Link)

How You Can Help

KDE has become important in the world, and your time and contributions have helped us get there. As we grow, we need your support to keep KDE sustainable.

Thankfully, thousands of you have stepped up in the past week to do just that financially, donating a record-breaking amount of money to KDE e.V., which is just incredible, awe-inspiring even.

So that's a great way to help out. But if you've got more time than money or want to make a difference more directly, then you can help KDE by becoming an active community member and getting involved somehow. Each contributor makes a huge difference in KDE — you are not a number or a cog in a machine!

You don’t have to be a programmer, either. Many other opportunities exist:

To get a new Plasma feature or a bugfix mentioned here, feel free to push a commit to the relevant merge request on invent.kde.org.

Categories: FLOSS Project Planets

Louis-Philippe Véronneau: lintian.debian.org: Episode IV – A New Hope

Planet Debian - Fri, 2024-12-06 20:45

After weeks – dare I say months – of work, it is finally done. lintian.debian.org is back online!

Many, many thanks to everyone who worked hard to make this possible:

  • Thanks to Nicolas Peugnet, the author of lintian-ssg, who handed us this custom static site generator on a silver platter. I'm happy I didn't have to code this myself :)
  • Thanks to Otto Kekäläinen, maintainer of the lintian-ssg package in Debian, who worked in tandem with Nicolas to iron out problems.
  • Thanks to Philipp Kern, who did the work on the DSA side to put the website back online.

All in all, I did very little (mostly coordinating these fine folks) and they should get the credit for this very useful service being back.

Categories: FLOSS Project Planets

KPhotoAlbum 6.0.0 released

Planet KDE - Fri, 2024-12-06 19:00

This time, it’s a short one: We ported KPhotoAlbum to Qt6/KF6. That’s it ;-)

The port itself has been done by Johannes and me, additional commits have been contributed by Randall Rude and Fabian Würfl. Thanks for working on KPA with us!

One thing that’s worth mentioning is: For the map/geodata functionality, we need Marble. The Qt5/KF5 version of Marble can’t be co-installed with the Qt6/KF6 version, and this one is not released yet. But Marble 24.12.0 (which will be the first official Qt6/KF6 release) will be released in a few days. So just wait until it's out before upgrading to KPA 6, to not lose the map parts.

Maybe, the Qt6/KF6 version contains some regressions. The codebase is quite well advanced in years in some parts, and we had to mess with quite some legacy issues to make the whole thing fit for Qt6/KF6. So if you notice anything, please file a respective bug report and/or contact us via our mailing list or Matrix channel (cf. User support → Communication). Thanks for your participation (hopefully, it won’t be necessary too much).

Have a lot of fun with KPhotoAlbum 6 :-)

— Tobias

Categories: FLOSS Project Planets

Plasma Wayland Protocols 1.15.0

Planet KDE - Fri, 2024-12-06 19:00

Plasma Wayland Protocols 1.15.0 is now available for packaging. It is needed for the forthcoming KDE Frameworks.

URL: https://download.kde.org/stable/plasma-wayland-protocols/
SHA256: e5aedfe7c0b2443aa67882b4792d08814570e00dd82f719a35c922a0993f621e Signed by: E0A3EB202F8E57528E13E72FD7574483BB57B18D Jonathan Riddell jr@jriddell.org

Full changelog:

  • Add a request to create a virtual output stream with description
  • Add alpine CI
  • Add modifier information to keystate
  • gitignore: use same as KWin
  • Add a destructor to appmenu manager
  • Add protocol tests
  • Add CI for static builds on Linux
Categories: FLOSS Project Planets

Bálint Réczey: Firebuild 0.8.3 is out with 100+ fixes and experimental macOS support!

Planet Debian - Fri, 2024-12-06 16:53

The new Firebuild release contains plenty of small fixes and a few notable improvements.

Experimental macOS support

The most frequently asked question from people getting to know Firebuild was if it worked on their Mac and the answer sadly used to be that well, it did, but only in a Linux VM. This was far from what they were looking for. 🙁

Linux and macOS have common UNIX roots, but porting Firebuild to macOS included bigger challenges, like ensuring that dyld(1), macOS’s dynamic loader initializes the preloaded interceptor library early enough to catch all interesting calls, and avoid using anything that uses malloc() or thread local variables which are not yet set up then.

Preloading libraries on Linux is really easy, running LD_PRELOAD=my_lib.so ls just works if the library exports the symbols to be interposed, while macOS employs multiple lines of defense to prevent applications from using unknown libraries. Firebuild’s guide for making DYLD_INSERT_LIBRARIES honored on Macs can be helpful with other projects as well that rely on injecting libraries.

Since GitHub’s Arm64 macOS runners don’t allow intercepting binaries with arm64e ABI yet, Firebuild’s Apple Silicon tests are run at Bitrise, who are proud to be first to provide the latest Xcode stacks and were also quick to make the needed changes to their infrastructure to support Firebuild (thanks! ).

Firebuild on macOS can already accelerate simple projects and rebuild itself with Xcode. Since Xcode introduces a lot of nondeterminism to the build, Firebuild can’t shine in acceleration with Xcode yet, but can provide nice reports to show which part of the build is the most time consuming and how each sub-command is called.

If you would like to try Firebuild on macOS please compile it from the GitHub repository for now. Precompiled binaries will be distributed on the Mac App Store and via CI providers. Contact us to get notified when those channels become available.

Dealing with the ‘Epochalypse’

Glibc’s API provides many functions with time parameters and some of those functions are intercepted by Firebuild. Time parameters used to be passed as 32-bit values on 32-bit systems, preventing them to accurately represent timestamps after year 2038, which is known as the Y2038 problem or the Epochalypse.

To deal with the problem glibc 2.34 started providing new function symbol variants with 64-bit time parameters, e.g clock_gettime64() in addition to clock_gettime(). The new 64-bit variants are used when compiling consumers of the API with _TIME_BITS=64 defined.

Processes intercepted by Firebuild may have been compiled with or without _TIME_BITS=64, thus libfirebuild now provides both variants on affected systems running glibc >= 34 to work safely with binaries using 64-bit and 32-bit time representation.

Many Linux distributions already stopped supporting 32-bit architectures, but Debian and Ubuntu still supports armhf, for example, where the Y2038 problem still applies. Both Debian and Ubuntu performed a transition rebuilding every library (and their reverse dependencies) with -D_FILE_OFFSET_BITS=64 set where the libraries exported symbols that changed when switching to 64-bit time representation (thanks to Steve Langasek for driving this!) . Thanks to the transition most programs are ready for 2038, but interposer libraries are trickier to fix and if you maintain one it might be a good idea to check if it works well both 32-bit and 64-bit libraries. Faketime, for example is not fixed yet, see #1064555.

Select passed through environment variables with regular expressions

Firebuild filters out most of the environment variables set when starting a build to make the build more reproducible and achieve higher cache hit rate. Extra environment variables to pass through can be specified on the command line one by one, but with many similarly named variables this may become hard to maintain. With regular expressions this just became easier:

firebuild -o 'env_vars.pass_through += "MY_VARS_.*"' my_build_command

If you are not interested in acceleration just would like to explore what the build does by generating a report you can simply pass all variables:

firebuild -r -o 'env_vars.pass_through += ".*"' my_build_command Other highlights from the 0.8.3 release
  • Fixed and nicer report in Chrome and other WebKit based browsers
  • Support GLibc 2.39 by intercepting pidfd_spawn() and pidfd_spawnp()
  • Even faster Rust build acceleration

For all the changes please check out the release page on GitHub!

(This post is also published on The Firebuild blog.)

Categories: FLOSS Project Planets

Centarro: Drupal Commerce support for CPQ and product customization

Planet Drupal - Fri, 2024-12-06 16:48

Drupal Commerce is an open source eCommerce platform that natively extends Drupal to sell any type of product to anyone in the world. This includes sales of products that are customized at the point of sale, like an engraved piece of jewelry or an event registration. It also includes sales to B2B customers and others who require a configure, price, quote (CPQ) workflow to review and authorize a purchase.

This post explains the feature set at a high level with an example configuration.

Drupal's data architecture

Supporting this feature set is Drupal's data architecture, which lets the Commerce modules define new data types for entities like products, orders, order items, and more. These are defined with sets of base fields, and they can be extended further with custom fields as needed. (Read more about this subject at Drupalize.Me.)

For example, one of our merchants sells scuba equipment. While product variations include price and SKU base fields by default, this merchant added custom fields for the specifications of different models. This structured product information is then rendered to PDPs, displayed in product comparison charts, and exposed as facets in search interfaces to help customers find the right product.

When you add custom fields to an entity, you don't just get to determine where and how they are displayed but also the form interface(s) used to input field data. You can control the number of values a field supports and the type of form element used to set those values (e.g., checkboxes, select list, free tagging textfield, etc.). For data types that support multiple form modes, like order items, you can also determine the context in which a particular field will be editable by a user.

Read more
Categories: FLOSS Project Planets

FSD meeting recap 2024 12 06

FSF Blogs - Fri, 2024-12-06 15:44
Check out the important work our volunteers accomplished at today's Free Software Directory (FSD) IRC meeting.
Categories: FLOSS Project Planets

FSF Blogs: FSD meeting recap 2024 12 06

GNU Planet! - Fri, 2024-12-06 15:44
Check out the important work our volunteers accomplished at today's Free Software Directory (FSD) IRC meeting.
Categories: FLOSS Project Planets

Bojan Mihelac: Finding Blocks Across a Wagtail Site

Planet Python - Fri, 2024-12-06 14:37
Discover how to efficiently locate and update specific blocks across your Wagtail site, even when they're deeply nested.
Categories: FLOSS Project Planets

Dirk Eddelbuettel: RcppArmadillo 14.2.2-1 on CRAN: Small Upstream Fixes

Planet Debian - Fri, 2024-12-06 13:34

Armadillo is a powerful and expressive C++ template library for linear algebra and scientific computing. It aims towards a good balance between speed and ease of use, has a syntax deliberately close to Matlab, and is useful for algorithm development directly in C++, or quick conversion of research code into production environments. RcppArmadillo integrates this library with the R environment and language–and is widely used by (currently) 1197 other packages on CRAN, downloaded 37.5 million times (per the partial logs from the cloud mirrors of CRAN), and the CSDA paper (preprint / vignette) by Conrad and myself has been cited 605 times according to Google Scholar.

Conrad released a minor version 14.2.2 yesterday. This followed a bit of recent work a few of us did in the ensmallen and mlpack repositories following the [14.2.0 release]. Use of (member functions) .min(index) and .max(index) was deprecated in Armadillo in favor of .index_mix() and .index_max(). By now ensmallen and mlpack have been updated at CRAN. To add some spice, CRAN emailed that the (very much unreleased as of now, but coming likely next spring) gcc-15 was unhappy with RcppArmadillo due to some Armadillo code. This likely related to the listed gcc-15 C++ change about “Qualified name lookup failure into the current instantiation”. Anyway, Conrad fixed it within days and that change too is part of this new version (as is a small behaviour normalization between the two indexing methods that matters in case of ties, this was in 14.2.1).

The changes since the last CRAN release are summarised below.

Changes in RcppArmadillo version 14.2.2-1 (2024-12-05)
  • Upgraded to Armadillo release 14.2.2 (Smooth Caffeine)

    • Workarounds for regressions in pre-release versions of GCC 15

    • More selective detection of symmetric/hermitian matrices by various functions

Changes in RcppArmadillo version 14.2.1-1 (2024-11-24) (GitHub Only)
  • Upgraded to Armadillo release 14.2.1 (Smooth Caffeine)

    • Fix for index_min() and index_max() to ensure that the first index of equal extremum values is found

Courtesy of my CRANberries, there is a diffstat report relative to previous release. More detailed information is on the RcppArmadillo page. Questions, comments etc should go to the rcpp-devel mailing list off the Rcpp R-Forge page.

If you like this or other open-source work I do, you can sponsor me at GitHub.

This post by Dirk Eddelbuettel originated on his Thinking inside the box blog. Please report excessive re-aggregation in third-party for-profit settings.

Categories: FLOSS Project Planets

Aten Design Group: Drupal 11 is Here! What you Need to Know about New Development Features

Planet Drupal - Fri, 2024-12-06 12:25
Drupal 11 is Here! What you Need to Know about New Development Features jenna Fri, 12/06/2024 - 10:25 Drupal

Your organization may use Drupal as a CMS, application framework, site builder, or all of the above. Within the context of this article about new features in the latest version, I'd like you to think about Drupal as a system.

It provides some standard pieces—things like content types, users and roles, taxonomies—and standard ways of connecting them to one another. But out of the box, it's sort of a jumble of pieces, and requires putting those pieces together for it to be meaningful.

A lot of the features that you'll see in Drupal 11.0 are developer-focused, and mostly benefit people who are building or maintaining sites, and your end users won't necessarily notice anything different. But there are some new features that can impact content administrators.

Content Admin

There's a new admin menu available using the Navigation module, which was brought into Drupal core as an experimental module. It's been a long time coming, and I think it's wonderful. It works well with the default Claro admin theme, and makes working in Drupal admin UI feel more modern and friendly. If you've used the Gin admin theme, the new menu will feel familiar, because it shares many of the same ideas.

There are some cool things in CKEditor 5 like markdown shortcuts similar to those we’re used to in Slack and Google Docs. For example, if you start typing something like 1-period-space, those tools automatically start creating a numbered list for you. It also supports other shortcuts like asterisks for bold, underscores for italics, or number-signs for heading levels. I prefer keyboard shortcuts wherever possible, and this makes working within CKEditor significantly faster. 

Recipes

Recipes are a way of packaging up configurations and settings that deliver a certain kind of functionality. In Drupal 11 core, there are recipes for things like the basic page content type, document media type, and editorial workflow. These are site features that previously were created during site installation using the Standard profile, which then became a permanent part of your project.

Recipes are applied rather than installed, so they don't end up becoming a dependency of your site, and therefore, you don't get locked in. You can remove modules or update configuration without changing the original recipe. And if the recipe changes, it doesn't change your site unless you reapply it.

Unlike configuration management, recipes aren't all-or-nothing – meaning you can make a recipe for broad, general functionality or something super specific. Because recipes are so flexible and don't create dependencies to themselves, they can be easily combined and shared, or adapted to fit your own needs.

For site owners, recipes will be really useful because it will make adding new features considerably faster because you can apply one or more recipes, rather than having to build everything up yourself. Because recipes are easily shareable, you'll also be able to find recipes created by others. In fact there's already a “Recipes Cookbook” on drupal.org with various site starters and functionality-specific recipes.

At Aten, our Drupal developers will be able to use recipes to quickly recreate commonly-needed features that our projects require. For example: installing Aten's Mercury Editor module, standing up our default Single Directory Components, configuring our QA service and module, or setting up search functionality. And they'll allow us to share our work with others in a way that doesn't bind them to all the parts of our standard processes.

Single Directory Components

Speaking of Single Directory Components, that module is now stable in Drupal 11.

Here we're using the term component as a piece of a web page that's modular and needs to be reusable. These are generic building blocks of pages that will appear throughout your site such as an accordion, call to action, banners, and slideshows.

Single Directory Components (SDC) are a way of organizing the files needed to display a single component (the Twig template, CSS, and JavaScript) into a folder. If you follow the naming conventions, Drupal will automatically generate a library to combine all of these for you. When you add an SDC to a page, Drupal will load the CSS and JavaScript for the components automatically.

Because SDCs are essentially self-contained, it's fairly easy to reuse them across different projects and entity types—things like Paragraphs or custom block types.

SDCs make the implementation of component libraries or design systems much easier because you can change Drupal's output to match whatever structure is needed.  Aten makes heavy use of Single Directory Components for projects using Mercury Editor, our drag-and-drop content authoring experience that allows editors to preview content changes in real time. 

Workspaces

The Workspaces module is stable in Drupal 11. Workspaces allow you to create multiple copies of your live site and within these copies, you can work on changes like content edits or structural changes, and then deploy those changes to the live workspace.

It can allow you to do things like test out menu changes, completely reorganize a section of your site; or maybe you have seasonal content that all needs to go live at the same time. You could work on those within a new workspace (or in multiple workspaces). And then when those changes are ready to go live, they all happen at once.

Currently, we can do that with individual pages using content moderation and workflow, but it's always been hard to work on a big set of changes over time and preview them. 

I've experimented with Workspaces in the past and with this stable release. Although I think it's a fantastic idea, because it's a different way of handling content changes, it may be incompatible with your content model or modules you're using.

If you're already doing anything with content moderation, layouts, or translations, Workspaces is going to add a new layer of complexity. It may require a lot of training and continued support before content administrators are comfortable with a new workflow. 

Time to upgrade

Now that I’ve laid out all of the new features of Drupal 11, it’s time to determine when and how to best upgrade your Drupal site. Get in touch with us for upgrade help.
 

Seth Hill
Categories: FLOSS Project Planets

Drupalize.Me: Understanding the Difference Between Cache Keys and Cache Tags in Drupal

Planet Drupal - Fri, 2024-12-06 12:16
Understanding the Difference Between Cache Keys and Cache Tags in Drupal

Have you ever wondered "What is the difference between cache keys and cache tags?" One of our Drupalize.Me members wrote in asking about it, and the answer provides insight into how Drupal's Cache API works.

joe Fri, 12/06/2024 - 11:16
Categories: FLOSS Project Planets

MidCamp - Midwest Drupal Camp: MidCamp 2025 Planning Meetings Now on Wednesdays!

Planet Drupal - Fri, 2024-12-06 11:00
MidCamp 2025 Planning Meetings Now on Wednesdays!

We’ve got an important scheduling update for all our MidCamp 2025 organizers! Starting in December 2024, our bi-weekly planning meetings will be moving from Mondays to Wednesdays.

Why the change?

We’re shifting to Wednesdays to better accommodate everyone’s schedules and keep our planning momentum strong. These meetings are crucial for getting everything in place for MidCamp 2025, and we want as many voices as possible in the conversation.

What to Expect:
  • New Meeting Time: Every other Wednesday at 3:00 PM CT.
  • First Meeting: Our first Wednesday meeting will be on December 11, 2024.

We appreciate everyone’s flexibility and can’t wait to keep the MidCamp 2025 planning energy high! If you have any questions or can’t make the new time, reach out in Slack or email us. We’re here to make sure you’re involved!

How to Join:

All planning details will continue to be shared in our MidCamp Slack, so keep an eye on the #midcamp-organizers channel for updates and links. Not yet in Slack? Join the MidCamp Slack here!

Categories: FLOSS Project Planets

ComputerMinds.co.uk: Views Data Export: Re-maintainership

Planet Drupal - Fri, 2024-12-06 10:38

If you have some data in a Drupal site, say a list of contact form submissions, or a list of content, you might want to provide a way for visitors to download that list as a CSV or Excel file: there's a module for that.

Views Data Export - The story

This module has its roots firmly in the Drupal 6 glory days where basically every list in Drupal was a view. Had some blog posts: view; list of comments: view; images needing copyright review: view.

That made a simple extension module that could export that content to CSV or Excel really appealing, and the Views Bonus Pack module provided this functionality however, there were a number of issues. Top of our list of problems with it was that it tried to do the entire export in one big go, if you had a lot of data, then you were out of luck, you simply couldn't export it all. You'd have to do it page by page or something like that.

In our old office, we dreamed up a way to have Drupal's batch API iterate over the result pages and collect them all up into a single file for download.

Additionally, at the time we had a client who wanted to export data that was coming in pretty rapidly: they were getting submissions at the rate of several a second and needed to be able to accurately export all the submissions in one go, not getting any duplicates, etc.

We really wanted to be able to get this working nicely with the SQL backend for Views and found a way in MySQL to query and populate a table with the resultset in a single transaction. In this way, we would make an initial point-in-time copy of the data required to render the view, and then we could take our time to process through that data. As long as MySQL could query and write the data fast enough we could then use Drupal's Batch API to loop through the data at our leisure.

This approach worked nicely but needed to fork the Views Bonus module and so the Views Data Export module was born. In the years that followed: the module gained popularity, a Drupal 7 port, and something like 75,000 active sites using it.

Decline and Drupal 8

ComputerMinds had never put in place any sort of proper amount of time to do maintenance for Views Data Export and so after many years and unattended bug reports, Drupal 8 rolled around and we didn't invest time in doing a Drupal 8 port either.

However, Drupal has a great community and someone else stepped up and offered to port and maintain Views Data Export.

However, the bugs and feature requests continued to pile up, and the port was more of a re-imagining than a direct port of the code. This was completely understandable since the underlying systems of Drupal and Views had massively changed in those years. And basically, we weren't involved in explaining what the Drupal 7 version was doing and why.

The module entered a period of very minimal maintenance and essentially only got further updates for critical bug fixes and new Drupal core versions.

Let me be clear that this is no slight against anyone who has done brilliant work on the Drupal 8, 9 or 10 versions of Views Data Export, but proper amounts of time and resources were never put into the module...until now.

Re-maintainership

Recently we've changed some internal priorities around so that we can spend more time giving back to the Drupal community, and this coincided with someone asking me to be a co-maintainer for Views Data Export so that they could add Drupal 11 support.

I thought about it a lot and waited for the other maintainers to weigh in, but ultimately decided that I wanted to get back involved in the maintainership of Views Data Export and thus declined the generous offer of help. I did then work to get a Drupal 11 version out.

Going forward

I aim to maintain Views Data Export.

I'm working on exactly how this works, but it starts by regularly spending time working on the project.

Now...the project pages and issue tracker on Drupal.org are in a bit of a dire state:

  • The project page documentation is almost entirely the original text I wrote for Views Data Export for Drupal 6, so some of the information there is completely out of data.
  • The issue queues have been left relatively unattended for a decent while, so we have (at the time of writing):
    • 204 open bugs
    • 276 other open issues.
    • Several issues that are marked as RTBC that haven't been given any attention by the maintainers.
    • Plenty of duplicate issues.
    • Drupal.org issue queues are hard to read and work with, and slow :(
  • The documentation is for Drupal 6/7 and is pretty bare-bones.

The code...well I've not read every line of code in the latest version of Views Data Export, I'm going to be doing that today to break up some of the issue queue management I'm going to be doing.

Drupal 7 version

According to the stats on Drupal.org there are still around 41,000 active Drupal 7 installs, and while those will be community EOLd in a month, I don't want to prematurely cut them off, so while I plan to close almost all of the Drupal 7 issues that I find, I won't mark the module unsupported as such. But that will happen in January 2025 anyway, when Drupal.org does that automatically.

Progress check

I intend to write an article like this one every 2 weeks detailing what has been done and what the plans for the future are. Mostly to keep me honest and focused! It's easy when starting on a bit of a big project like this to get lost and despondent about the size of the problem, so by trying to write about it, I'm hoping that I'll be able to look back and see progress even if won't always feel like any progress has been made!

Categories: FLOSS Project Planets

Nonprofit Drupal posts: 2025 Nonprofit Summit Update: Breakout Leaders Wanted!

Planet Drupal - Fri, 2024-12-06 10:26

Hey nonprofit Drupal users, do you want a free ticket to DrupalCon Atlanta? Submit to be a breakout discussion leader at the Nonprofit Summit!

What are you talking about?

The DA is interested in supporting community-driven content that is specifically relevant to nonprofit organization staff and related agencies at DrupalCon North America in Atlanta, Georgia, at the Nonprofit Summit on March 24, 2025.

We are looking for volunteers who would be interested in giving back to the community by contributing some subject matter expertise via a day of informal breakout sessions or other group activities. We are open to ideas!

Who are we looking for?

Do you have some Drupal expertise or a recent experience with a Drupal project that you would like to share with others? Is there something about Drupal that you think is really cool that you would love to share with the nonprofit Drupal community?

What’s required?

You will not be required to make slides! You don’t need to have lots of (or any) speaking experience! All you need is a willingness to facilitate a discussion group or engaging activity around a particular topic, and some expertise or enthusiasm for that topic that you wish to share.

How to Submit an Idea or Topic

Please fill out this form by January 31st. https://forms.gle/HBv1Za55MXr2sriPA

Discussion leaders will be selected by the Nonprofit Summit Planning Committee and will be notified by the middle of February.

Questions?

Email nonprofitsummit@association.drupal.org.

Categories: FLOSS Project Planets

Freelock Blog: Automatically track documentation requirements

Planet Drupal - Fri, 2024-12-06 10:00
Automatically track documentation requirements Anonymous (not verified) Fri, 12/06/2024 - 07:00 Tags Nonprofits ECA Drupal Planet Automation

One of our clients is a yacht club that has their own moorage, which they lease out to members. With several hundred slips, their insurance requires them to maintain proof of insurance, up-to-date vessel registrations, and regular electrical inspections for all boats moored at their facility.

In Washington all vessel registrations renew in June, but insurance and inspections can expire any time of year. The office needs to keep copies of these documents on file.

Categories: FLOSS Project Planets

Pages