2018-10-22         Joyce

How to use the serializer in part

I have several viewsets, several endpoints in them use one serializer. One endpoint does not even have a Meta class, It performs a certain action and uses the same serializer in the method to_representation. In this serializer I use the methodfield like this:some_field = serializers.SerializerMethodField()def get_some_field(self, obj): return bool(obj.something_attr)something_attr I get in viewset in queryset =MyModel.objects.annotate(something_attr=(...))In others viewsets there is no such field, so they use other queriesets. Can I work around this problem without crea...

 django                     1 answers                     29 view
 2018-10-22         Joyce

Running shell commands without a shell window

With either subprocess.call or subprocess.Popen, executing a shell command makes a shell window quicky appear and disappear.How can I run the shell command without the shell window? I imagine your observation is limited to Windows, since that, I believe, is the only platform on which you'll get that "console flash" issue. If so, then the docs offer the following semi-helpful paragraph: The startupinfo and creationflags, if given, will be passed to the underlying CreateProcess() function. They can specify things such as appearance of the main window and priority fo...

 python                     1 answers                     73 view
 2018-10-22         Joyce

Checking whether element is there or not

This question already has an answer here: Check if element exists python selenium 2 answers Error message...selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: "method":"xpath","selector":"//div[@role='button' and @title='Status']"}...implies that the XPath you have used was unable to locate any element within the HTML DOM.If you want to validate the presence of the desired element you need to induce a try-catch{} block as follows:def s...

 python                     2 answers                     81 view
 2018-10-22         Joyce

Routing in child component using react-router-dom

I’m using the CoreUI Pro template for a React dashboard, and trying to integrate logging in functionality into it. My log in is using AWS Cognito, so I’m using this tutorial for that part.The problem I have is that once logged in, the links don’t work.My top level routes.js is below. export default ({ childProps }) => <HashRouter> <Switch> <AppliedRoute path='/' exact component={Login} props={childProps} /> <UnauthenticatedRoute path='/login' exact component={Login} props={childProps} /> <AuthenticatedRoute path='/dashboard' ...

 reactjs                     1 answers                     48 view
 2018-10-22         Joyce

Spring 4 security login users-by-username-query is always login error

security-context.xml<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:security="http://www.springframework.org/schema/security" xsi:schemaLocation="http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <security:authentication-manager> <security:authenticati...

 spring                     1 answers                     51 view
 2018-10-22         Joyce

How to Create interrelated items in xml file android

I have created a couple of questions for my android app, question two depends on one, i want to create it that if you fill that zero persons were tested it will automatically fill the next segment of the question.Am stranded, how do i do it? here is my XML `<?xml version="1.0" encoding="utf-8"?><ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res...

 android                     1 answers                     79 view
 2018-10-22         Joyce

How to optimize a UNION with a final ORDER BY/OFFSET

I got a complex table on a webpage (with datatable.js) that use with 3 differents "sources". This datatable is paginated in the front, but the back is not.I want to put a server processing of the pagination, my request works, but I want to optimize it:SELECT toto, titiFROM (SELECT toto, titi FROM S1 UNION SELECT toto, titi FROM S2 UNION SELECT toto, titi FROM S3)ORDER BY titi, totoOFFSET 50 ROWS FETCH NEXT 50 ROWS ONLYMy real code is more complex, but you have the main idea of my problem here.S1, S2 and S3 may have 1 000 000 rows each, but at the end...

 sql                     1 answers                     43 view
 2018-10-22         Joyce

Mysql Sub Select Query Optimization

I'm running a query daily to compile stats - but it seems really inefficient. This is the Query:SELECT a.id, tstamp, label_id, (SELECT author_id FROM b WHERE b.tid = a.id ORDER BY b.tstamp DESC LIMIT 1) AS author_idFROM a, bWHERE (status = '2' OR status = '3') AND category != 6AND a.id = b.tidAND (b.type = 'C' OR b.type = 'R')AND a.tstamp1 BETWEEN {$timestamp_start} AND {$timestamp_end}ORDER BY b.tstamp DESCLIMIT 500This query seems to run really slow. Apologies for the crap naming - I've been asked to not reveal the actual table names.The reason there is a sub select is ...

 php                     2 answers                     63 view
 2018-10-22         Joyce

Linux Bash count and summarize by unique columns

I have a text file with lines like this (in Linux Bash):A B C DA B C JE B C PE F G NE F G PA B C QH F S LG Y F QH F S LI need to find the lines with unique values for the first 3 columns, print their count and then print summarized last column for each unique line, so the result is like this:3 A B C D,J,Q1 E B C P2 E F G N,P1 G Y F Q2 H F S LWhat I have tried:cat FILE | sort -k1,3 | uniq -f3 -c | sort -k3,5nrIs there maybe any advice?Thanks in advance! The easiest is to do the following:awk '{key=$1 OFS $2 OFS $3; a[key]=a[key]","$4; c[key]++} END{for(key in a) { pri...

 bash                     4 answers                     5 view
 2018-10-22         Joyce

WHERE Clause to find all records in a specific month

I want to be able to give a stored procedure a Month and Year and have it return everything that happens in that month, how do I do this as I can't compare between as some months have different numbers of days etc?What's the best way to do this? Can I just ask to compare based on the year and month?Thanks. I think the function you're looking for is MONTH(date). You'll probably want to use 'YEAR' too.Let's assume you have a table named things that looks something like this:id happend_at-- ----------------1 2009-01-01 12:082 2009-02-01 12:003 2009-01-12 09:404 2009-0...

 sql                     10 answers                     20 view
 2018-10-22         Joyce

Finding checked QRadioButton among many into a QVBoxLayout

I used the code below to dynamically create a group of radio buttons:self.wPaymantType.qgbSomeSelectionGroup = QtGui.QGroupBox()vbox = QtGui.QVBoxLayout()for row in listOfChoices: radio = QtGui.QRadioButton(row) if bIsFirst: radio.setChecked(True) bIsFirst = False if len(row.name) > nMaxLen: nMaxLen = len(row.name) vbox.addWidget(radio)self.wPaymantType.qgbSomeSelectionGroup.setLayout(vbox)How can I iterate through all radio buttons to find out which one is checked?I tried something like this, but I didn't get anything good from it:qvbl =...

 python                     3 answers                     48 view
 2018-10-22         Joyce

SQL Developer - Auto Formatting option

As you know, the shortcut for auto formatting the code written in Oracle SQL Developer is [Ctrl] + [F7], by default. My question is how I can edit the style of formatting of the code and especially if I can export this formatting, so that it can be applied to another computer? Thank you! From the Tools menu (or on OS X, the SQL Developer menu) go to Preferences. In versions up to 4.1.5, in the preference pane expand the Database section, and then the SQL Formatter section.The top level lets you import and export settings, and the Oracle Formatting section lets you choose...

 formatting                     2 answers                     27 view
 2018-10-22         Joyce

Getting user's IP address through Cloudflare and Azure

I have a website in Azure, the website is routed through Cloudflare for extra protection. Cloudflare adds a header CF-Connecting-IP which is supposed to be the client's IP address, however sometimes this gives a real IP address but most of the time I'm getting reserved IP addresses instead of the client's IP. I tested it going to the website through my office internet and cloudflare returns a reserved IP address, however when I go to whatsmyip.org I get my real office IP address.How can I make sure to always obtained the client's IP address unless of course they are behind ...

 c#                     1 answers                     37 view
 2018-10-22         Joyce

How to duplicate/clone a Linux-VM in Microsoft Azure?

I am trying to duplicate a Linux (Ubuntu 14.04 LTS) virtual machine in Microsoft Azure. The only idea I have is cloning the blob storage, creating a new VM and mount the blob storage but I cannot make it work.Is there a better way to get a running clone? Any advice?Thank you in advance. There is some great information on how to use your current Linux VM to create a template for spinning up multiple copies of your VM configuration.https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-capture-image/Your scenario would be two steps: Create your ...

 azure                     2 answers                     39 view
 2018-10-22         Joyce

.htaccess redirect taking site to "Index of" page instead of redirecting to specified domain

I recently modified my .htaccess file's redirects. The reason for this was because my my old file's individual RedirectPermanent links that point at specific pages were not working. This is because previously I had the wildcard code on top. The only thing that was working was my main redirect from this. With the new code, I tried to putting the RedirectPermanent code on top. Now nothing is redirecting at all. When going to the site, I get the "Index of" page (see img below).Does anyone see what I am doing wrong with my new code for this to not work?Newest - not redirectingR...

 apache                     1 answers                     39 view
 2018-10-22         Joyce

Angular Data URLs processing

I use the flag-icon-css library and for some flags the size is not correct due to the background-image property which is interpreted differently. I did not manage to create a Stackblitz so here is the minimal step to reproduce:ng new bug-socd bug-sonpm install flag-icon-cssIn angular.json, I added the CSS: "styles": [ "src/styles.css", "node_modules/flag-icon-css/css/flag-icon.min.css" ],In app.component.html<div style="padding: 5em"> <span class="flag-icon flag-icon-es" style="border: 1px solid black"></span><br/> &...

 css                     1 answers                     5 view

Page 1 of 146  |  Show More Pages:  Top Prev Next Last