Get multiple models in single QuerySet ordered by timestamp

I’m working on a table consisting of all events performed on a user despite that these events are represented by 4 different models.

The models are:

  • WebhookSubscription
  • WebhookEvent
  • TokenRefresh
  • LogEvent

I want these to all be visible to the user in their dashboard, but in a single table ordered by timestamp. I could do a single query for each model then append to a dictionary which I’ll then sort by date, however, I don’t want to go against a native solution if there is one (and I don’t believe this is an edge case so I could foresee it).

Is there a native way of retrieving multiple models in a single QuerySet?

bundle vs single quantity discount

I write you because I am trying to create a shopping cart rule that applies a discount to a bundle of materials (2 different materials in each BOM) if the user places more than 10 bundles in the basket.

What I did is creating a discount that only applies if quantity of material 1 and the quantity of material 2 are both above 10 (material 1 and material 2 form the bundle).

So far everything was working but now I have an additional material that I would like to include in the action discount. This material (material 3) is not part of any bundle but I would like to have an action that says: “if the total quantity in the basket is above 10 (e.g. 5 bundles and 5 material 3), then apply discount”.

The only solution that I found so far was to state all the different combinations of quantity but I found out that Magento has a limited amount of rows of formulas 🙂

Material 1 > 1; Material 2> 1; Material 3 > 9

Material 1 > 2; Material 2> 2; Material 3 > 8

Material 1 > 3; Material 2> 3; Material 3 > 7

Material 1 > 4; Material 2> 4; Material 3 > 6

Material 1 > 5; Material 2> 5; Material 3 > 5

Material 1 > 6; Material 2> 6; Material 3 > 4

……….

I think there should be a better way to do it.

Thanks a lot for your help.

Boot to Single User Mode with Startup Manager

I need enter safe mode on my Mac after selecting select macOS with Startup Manager (option while booting). Pressing + S has no effect.

The Mac currently uses Bootcamp for dual boot into Windows or macOS. By default it boots into Windows. I cannot change the default boot OS. Possibly because I don’t have an administrator account in macOS.

The following link is what I’m trying to accomplish using safe mode:

I don't have administrator account on my mac

TL;DR How to enter macOS safe mode after selecting macOS in Startup Manager?

How to block a single specific Office update on Windows 10 Pro

My laptop is currently Windows 10.0.17763.379. I have a fully licensed installation of Office 2007. Windows 10 perpetually nags me about the “Microsoft Office File Validation Add-in”.

The last time I pressed “Accept”, it completely undermined me and installed loads of Office 365 products, for which I have no licence. It prevented some of my Office 2007 products from working. I tried a Microsoft repair tool, which instead of removing the uninvited Office 365, removed my no-longer functional Office 2007.

To repair this, I had to remove everything related to Office 2007 and Office 365. Then I successfully re-installed and re-activated Office 2007.

I am very reluctant to press “Accept” again, as I do not want to repeat this process. Is there any way to prevent the nag message that keeps appearing on the right of the toolbar?

User class: How do I handle different user “subjects” and still keep my single responsability principal?

I have a User class, this class handles things like:

  • login (UserAuthenticateModel)
  • Handle user sessions: user login tokens, fetching user from session if set in session, ect’ (UserSessionsModel)
  • Fetch & Set user data to populate $ this user object. (UserFetchModel)
  • Update & change my user data (to this user object – and in the database) (UserUpdateModel)

I’m asking out loud and please correct me if I’m wrong: Does every point is a single responability of some sort of subject inside the “User” class and needs a different class?

I’ll describe 2 examples with some code:

  1. Setting sessios: Insead of just pasting a whole bunch of code in my construct that “does something with sessions”, I use a UserSessionsModel specifically with the method that does whatever it has to do – get data from session if exist. single responability – Setting/changing my user sessions, and populating my user object. and some of this session handling methods might be used elsewhere (example 2).

Code ex:

User class  {      public function __construct()     {         # look for a user in the session if set         $  this->getFromSession();     }      public function getFromSession()      {         # Create UserSession obj         if ( !$  this->UserSessions instanceof UserSessions )             $  this->UserSessions = new \myapp\Models\User\UserSessionsModel();          $  this->UserSessions->getUserFromSession($  this);     }  }  class UserSessionsModel {      public function getUserFromSession(User $  User)     {         if (Session::exists(Config::$  user)) {              $  session = unserialize(Session::get(Config::$  user));              $  User->id             = $  session->id;              $  User->firstName      = $  session->firstName;              $  User->lastName       = $  session->lastName;              $  User->userName       = $  session->userName;              $  User->email          = $  session->email;              $  User->lastLogin      = $  session->lastLogin;              $  User->password       = $  session->password;              $  User->ip             = $  session->ip;              $  User->loginTimestamp = $  session->loginTimestamp;              $  User->isLoggedIn     = $  session->isLoggedIn;               return $  User;         }     }     public function setUserToSession(User $  User)     {         Session::set(Config::$  user, serialize($  User));     }  } 
  1. Logging in: This has 2 parts:
    • First to authenticate the user credentials
    • Set security sessions (token, loggedin flag, ect’.) – using the UserSessionModel from example 1 – since it handles the same “subject”. So both are under the login method (one insice an other or separately – this example handles them the first way) and both are 2 different responsibilities – one is checking a user authentication, the second is handeling the sessions/tokens.

code ex:

User class {      // after setting $  this->username & $  this->password to this object     public function login()     {         if ( !$  this->UserAuthenticator instanceof \myapp\Models\User\UserAuthenticatorModel )             $  this->UserAuthenticatorModel = new \myapp\Models\User\UserAuthenticatorModel();          return $  this->UserAuthenticatorModel->login($  this);     } }   class UserAuthenticatorModel extends Model {      public function login(User $  User)     {         try {              # Connect to new database with $  User->username & $  User->password             ...               # If status is connected              if ($  newConnection) {                  # Check for user credentials data                  $  userData = $  this->UserLoginValidation($  User->userName, $  User->password);                   # If the result isn't a valid array - EXEPTION                   if ( (!is_array($  userData)) || (empty($  userData)) )                     throw new LoginException("Invalid username ({$  User->userName}) or password ({$  User->password})");                  if ($  userData["require_password_change"] === 1) {                     $  this->set($  User, $  userData);                     return true;                 }                  $  this->set($  User, $  userData);                 # Set logged-in security sessions                 $  User->UserSessions = new UserSessionsModel();                 $  User->UserSessions->setSecuritySession($  User);                 # Set User obj to session                 $  User->UserSessions->UserToSession($  User);                  # Update last_login for this user                 $  this->updateLastLogin($  User->id, $  User->loginTimestamp);                  return true;              } else {                 throw new LoginException('User does not exist');                 return false;             }          } catch (LoginException $  e) {             $  e->log($  e);             return false;         }     } 

SharePoint 2010 PDF file not opening for a Single User

A user of SharePoint 2010 site is not able to open any PDF file with in the site. PDF files are uploaded into document library and user is having contribute rights to the library. When user click on the document nothing happens. Other users with same access rights can open the PDF files. This is high priority issue for us.

Please help me to identify the cause or resolve the issue.

Replicate multiple server databases to single slave server

I have several databases in several locations running with MySQL 5.7.25. Now i want to replicate all these databases to single server.

Master database servers (All databases are with same name)

Location 1 database: my_system Location 2 database: my_system Location 3 database: my_system Location 4 database: my_system Location 5 database: my_system 

Expected slave server;

database 1: my_system_location_1 database 2: my_system_location_2 database 3: my_system_location_3 database 4: my_system_location_4 database 5: my_system_location_5 

How can i setup this environment using MySQL replication.

I have tried MySQL multi source replication channels by renaming databases in to slave,

location1.replicate-rewrite-db=my_system->my_system_location_1 location2.replicate-rewrite-db=my_system->my_system_location_2 location3.replicate-rewrite-db=my_system->my_system_location_3 location4.replicate-rewrite-db=my_system->my_system_location_4 location5.replicate-rewrite-db=my_system->my_system_location_5 

but it is not replicating data. It does not show any errors. All status are fine. But no data replicating.

combining various lines of code for a single desktop application in c# [on hold]

So I’ve been trying to learn to code in c# for about two or three weeks now. As a project I came up with a calculator program. Now I’m trying to convert it into a desktop application. I have it to where all the basic operations work (+,-,* and /). In the program I can also raise the first number to the power of the second number for example: num1 * num1 num2 times(so if num1 = 3 & num2 = 4) == 3 * 3 * 3 * 3

Now I’m trying to figure out how to get this function to work in the new application.

In the program the code for basic operators is: else if (op == “+”) { Console.WriteLine(“num1 + num2); } It’s pretty copy and paste for all four operations. the only thing that changes is the operator between all four.(+,-,* & /)

In the new code for the desktop version the basic operators are written like this: case “+”; textBox_Result.Text = resultValue + Double.Parse(textBox_Result.Text)).ToString(); break; And again it’s pretty copy and paste for all four operations. The only difference is the operator being added to the couple lines of code.

To get the first number raised to the power of the second number in the original code I wrote it like this: else if (op == “^”) { double result = 1; for (double i = 0; i < num2; i ++;) { result = result * num1; } Console.WriteLine(“result”); }

For the new application I came up with:

case “^”; double result = 1; for (double i = 0; textBox_Result.Text; i ++;) { result = result * resultValue; } textBox_Result.Text = Double.Parse(textBox_Result.Text)).ToString; break;

Does anyone know if this looks right or not? Thanks for any help.