Posts

Showing posts from July 3, 2018

Django ModelForm: How to Add ForeignKey as Field in Form?

Image
Django ModelForm: How to Add ForeignKey as Field in Form? I have Three Models StudentInfo , StdSubject , Marks class StdSubject(StdCommon): REGULAR='R' OPTIONAL='O' SUBJECT_TYPE_CHOICE=( (REGULAR, 'REGULAR'), (OPTIONAL, 'OPTIONAL') ) subject_name = models.CharField('Subject Name', max_length=100) subject_type = models.CharField( 'Subject Type', max_length=1, default=REGULAR, choices=SUBJECT_TYPE_CHOICE) subject_full_marks = models.DecimalField( 'Full Marks', max_digits=5, decimal_places=2, default=100) subject_pass_marks = models.DecimalField( 'Pass Marks', max_digits=5, decimal_places=2) def __str__(self): return self.subject_name class StudentInfo(StdCommon): STD_CLASS=( ('6','Six'), ('7','Seven'), ('8','Eight'), ('9','Nine'), ('

How can I find closest date value from an array according to the current date?

How can I find closest date value from an array according to the current date? I want to get the next closest date on this array according to the current date. var dates = [ 'Aug 18, 2018 03:24:00', 'August 19, 2018 03:24:00', 'September 17, 2018 03:24:00', 'September 14, 2018 03:24:00', 'August 18, 2018 03:24:00', 'July 16, 2018 03:24:00', 'July 15, 2018 03:24:00', 'December 15, 2018 03:24:00', 'July 13, 2018 03:24:00', ]; var now = new Date(); 4 Answers 4 First you need to convert each date into a timestamp then subtract each of them by the current date and store the timestamp difference in the temp array then get the index of the minimum value and use the index to access the closest date in the original array. var dates = [ 'July 16, 1995 03:24:00', 'Aug 18, 1995 03:

undefined variable that equals to a node module

undefined variable that equals to a node module I try to transpire my file using browserify or webpack. This is my code: let rangy = require('rangy') rangy.init() const rang = () => rangy After transpire my code and add in a html page, I try to get rangy in console, but when i type rangy and press enter button, js says: rangy Uncaught ReferenceError: rangy is not defined When i type rang() and press enter, js says: rang() undefined But line 2 runs correctly. I need to use rangy in script tag of my index.html . rangy index.html How can I do this? This is my transpired file: (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n

How to display @Lob image from mysql database using spring mvc and jsp

How to display @Lob image from mysql database using spring mvc and jsp There is link to github: https://github.com/Lukszn/ProjectProfile I'm using Spring 4.3.7.RELEASE, MySQL Connector Java: 5.1.39 and hibrnate: 5.2.9. Finaly There i have User and his Account model. In account i have @Lob accPicture and some Strings(+ get/set). I'm trying a lot of answers from stackoverflow and documentation to show Account image, but without success. Last think what I do : created own ImageController. I successfully stored image in database but when I'm trying to display it in my jsp, it is showing "HTTP Status 400 - The request sent by the client was syntactically incorrect." Firstly I show you my User model: @Entity @Table(name = "users") public class User implements Serializable{ /** * */ private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; @Column(unique = true)

Delete column after conditional formatting (formula) using xlsxwriter

Delete column after conditional formatting (formula) using xlsxwriter I have a column (column V) that I used to conditionally format another column (column U) using engine xlsxwriter. So I have this: # Light yellow fill with dark yellow text. format1 = workbook.add_format({'bg_color': '#FFEB9C'}) # Light red fill with dark red text. format2 = workbook.add_format({'bg_color': '#FFC7CE', 'font_color': '#9C0006'}) worksheet.conditional_format('U2:U1000', {'type': 'formula', 'criteria': '=V2>25', 'format': format1}) worksheet.conditional_format('U2:U1000', {'type': 'formula', 'criteria': '=V2<-20', 'format': format2}) So now after highlighting column U with conditional formatting,

How to accept a quoted sentence as argument in shell script [duplicate]

How to accept a quoted sentence as argument in shell script [duplicate] This question already has an answer here: I am trying to accept a quoted sentence as a parameter in bash similar to: git commit -m "your message as a sentence" git commit -m "your message as a sentence" I am trying to get this done like this: if [[ "$2" =~ "-m" ]]; then if [ -z $3 ]; then echo "Must have a message" else # TODO accept message and check if it is inside quotes fi fi Any ideas? This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. Something including getopts 'm:' seems like a good start. – Benjamin W. Jun 30 at 6:07 getopts 'm:'

prefersStatusBarHidden not updating after calling setNeedsStatusBarAppearanceUpdate()

prefersStatusBarHidden not updating after calling setNeedsStatusBarAppearanceUpdate() Different vcs inside my app show the status bar visible and others are hidden. This is set to YES in the info.pList "View controller-based status bar appearance": YES // also tried togging this between yes and no "Status bar is initially hidden": YES The app has 2 windows, the main window and a second window. The second window gets presented it front of the main window on a button push. The vc in the second window has the status bar hidden. The problem is if I'm on a vc (mainVC) inside the main window that shows the status bar, I press the button to show the second window, mainVC's status bar disappears. The second window gets presented and after I dismiss it I send a notification to mainVC to call setNeedsStatusBarAppearanceUpdate() but prefersStatusBarHidden isn't triggered so the status bar stays hidden even though it shouldn't be. I even subclassed a Naviga

Django makemessages to get custom translatable strings

Django makemessages to get custom translatable strings In my Django project I use Vue + vue-gettext for i18n. To make translatable strings I have the following code in my my .vue files: <translate>Hello %{name}</translate> <a href="..." v-translate>Click here</a> (using translate tags and v-translate attributes) Is there a way to configure manage.py makemessages to parse this code as well? By default it does not look into .vue files or parse this i18n code format. manage.py makemessages Did you find a solution? – user3599803 May 17 at 20:26 @user3599803 only via makefile - see answer below – Pydev UA May 18 at 8:45 1 Answer

Eclipse Photon - SVN / Maven not handled as Java-Project

Eclipse Photon - SVN / Maven not handled as Java-Project I moved forward to Eclipse 4.8. My Projects Maven projects under subversion is not displayed as Java Project and the pom.xml is displayed in XML-Editor instead of the well-meant pom-editor. pom.xml Steps I done: The Project's icon is showing the M-Icon-Overlay let me think it is a maven project. The Project's icon does not contain the J-Icon-Overlay what let me think he does not treat it as a Java project. Any ideas? Try to delete the file without deleting its content, delete the .project file and reopen it via File > Open Projects from File System... . – howlger Jun 30 at 10:54 .project 1 Answer 1 Doesnt work at the moment. I created a workspace in an older version and opend the works

How can I get location on map when I click the button?

Image
How can I get location on map when I click the button? I wanna show the location on MapActivity when I clicked the button. I tried to use interface to send data from fragment to activity. However, it's not working as I expect. By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Can not find module “@angular-devkit/build-angular”

Can not find module “@angular-devkit/build-angular” Using npm, I followed the getting started directions on the Angular CLI quick start page. Angular CLI Quickstart Running ng serve --open after creating and going into my new project "frontend" gave this error: ng serve --open Could not find module "@angular-devkit/build-angular" from "C:UsersBrandonproject-namefrontend". Error: Could not find module "@angular-devkit/build-angular" from "C:UsersBrandonproject-namefrontend". at Object.resolve (C:UsersBrandonproject-namenode_modules@angular-devkitcorenoderesolve.js:141:11) at Observable.rxjs_1.Observable [as _subscribe] (C:UsersBrandonproject-namenode_modules@angular-devkitarchitectsrcarchitect.js:132:40) I have tried suggestions from the other question similar to mine but it did not work. Answer was to run npm install --save-dev @angular-devkit/build-angular . npm install --save-dev @angular-devkit/build-angular Similar Question I hav

Parse JSON in Swift 24hours of problems

Parse JSON in Swift 24hours of problems I am really struggling to parse a json file into my iOS app in Swift. I have a JSOn output from an SQL db. I think the formatting is wrong and the data headers are a bit ambiguous but my developer who I hired to create the process is happy with the output. Link below. So in the last 3 days I have read all of the Apple Developer materials on parsing JSON, also watched numerous tutorials which all cover pretty much the same data, and I don't know how much I have read and converted into actual projects which have all failed. I am really needing some guidance here. I have even in a desperate attempt to understand my problem from a different perspective I have looked at how it is done in other languages. This is the latest iteration: func flightData()-> [[String: String]]{ let url = URL(string: "http://35.237.114.234/api/index.php?uid=Bx7faf08A9fYJ7bZCNMUX9EzxYN2") guard let jsonFileURL = Bundle.main.url(forResource: "jso

Trying to populate 16 random images using Math.random and a filter

Trying to populate 16 random images using Math.random and a filter ``import React from 'react' import { getCard } from '../redux' import { connect } from 'react-redux' import CardBoard from './CardBoard' class Board extends React.Component{ componentDidMount(){ this.props.getCard() } render(){ let gameCard = Math.floor(Math.random() * (54 - 2) +2); const game = () => { let cards = ; if(cards.length < 16) { cards.push(gameCard); } return cards; }; return( {this.props.cards .filter(one => one.number === gameCard) .map(card => ( ))} ); } } export default connect(state => state, { getCard })(Board)`` Welcome to stackoverflow B L! There is not quite enough information in your q

Setting `GOPATH` for each vscode project

Setting `GOPATH` for each vscode project Setting the GOPATH variable global as an enviroment variable works fine with Visual Studio Code. GOPATH But setting a project specific variable globally doesn't seem very nice to me. Consider you have multiple Go projects, you would have to change this variable each time you, compile, debug, ... etc. a project. Go Is there a possibility to set the GOPATH variable as a project variable in Visual Studio Code? Ether in settings.json or launch.json ? GOPATH settings.json launch.json don't try to change GOPATH for each project, use vendor folder – n00dl3 Nov 21 '16 at 8:56 GOPATH vendor 4 Answers 4 Go 1.5 added the vendor directory that allows a per-project dependency management. If there is a source