Search Results

Search found 5330 results on 214 pages for 'django auth'.

Page 130/214 | < Previous Page | 126 127 128 129 130 131 132 133 134 135 136 137  | Next Page >

  • add extra data to response object to render in template

    - by mp0int
    I ned to write a code sniplet that enables to disable connection to some parts of a site. Admin and the mainpage will be displayable, but user section (which uses ajax) will be displayed, but can not be used (vith a transparent div set over the page). Also there is a few pages which will be disabled. my logic is that, i write a middleware, def process_request(self, request): if ayar.tonline_kapali: url_parcalari = request.path.split('/') if url_parcalari[0] not in settings.BAGIMSIZ_URLLER: if not request.is_ajax(): return render_to_response('bakim_modu.html') else: return None that code let me to display a "site closed" message for the urls not in BAGIMSIZ_URLLER (which contains urls that will be accessible) But i do not figure out how can i solve the problem about ajax pages... i need to set a header or something to the response and need to check it in the template.

    Read the article

  • Python and ReportLab: add a string at the end of every page

    - by user608341
    Hi peoples, I'm building a pdf document with reportlab, using the Paragraph class: doc = SimpleDocTemplate(response, leftMargin=lateral_margin, rightMargin=lateral_margin, topMargin=top_bottom_margin, bottomMargin=top_bottom_margin) Document = [] Document.append(Paragraph("bla bla bla bla", my_style)) doc.build(Document) Now I want to add at the end of every page a string, how can I do that??

    Read the article

  • how to made a "admin-only" for in html page (not view.py),has this method :user.is_superuser ??

    - by zjm1126
    in views.py: @user_passes_test(lambda u: u.is_superuser) def h_view(request): return render_to_response('mytest/news.html',context_instance=RequestContext(request)) but i want to show this page when admin login,and my now page is : <li id="tab_mytest"><a href="{% url mytest_list %}" class="{% block mytest_css_name %}{% endblock %}">{% trans "mytest" %}</a></li> how to change it, has this method :user.is_superuser ?? thanks

    Read the article

  • How do I translate a ISO 8601 datetime string into a Python datetime object?

    - by Andrey Fedorov
    I'm getting a datetime string in a format like "2009-05-28T16:15:00" (this is ISO 8601, I believe) one hack-ish option seems to be to parse the string using time.strptime and passing the first 6 elements of the touple into the datetime constructor, like: datetime.datetime(*time.strptime("2007-03-04T21:08:12", "%Y-%m-%dT%H:%M:%S")[:6]) I haven't been able to find a "cleaner" way of doing this, is there one?

    Read the article

  • Attribute Address getting displayed instead of Attribute Value

    - by Manish
    I am try to create the following. I want to have one drop down menu. Depending on the option selected in the first drop down menu, options in second drop down menu will be displayed. The options in 2nd drop down menu is supposed by dynamic, i.e., options change with the change of values in first menu. Here, instead of getting the drop down menus, I am getting the following Choose your Option1: Choose your Option2: Note: I strictly don't want to use javascript. home_form.py class HomeForm(forms.Form): def __init__(self, *args, **kwargs): var_filter_con = kwargs.pop('filter_con', None) super(HomeForm, self).__init__(*args, **kwargs) if var_filter_con == '***': var_empty_label = None else: var_empty_label = ' ' self.option2 = forms.ModelChoiceField(queryset = db_option2.objects.filter(option1_id = var_filter_con).order_by("name"), empty_label = var_empty_label, widget = forms.Select(attrs={"onChange":'this.form.submit();'}) ) self.option1 = forms.ModelChoiceField(queryset = db_option1.objects.all().order_by("name"), empty_label=None, widget=forms.Select(attrs={"onChange":'this.form.submit();'}) ) view.py def option_view(request): if request.method == 'POST': form = HomeForm(request.POST) if form.is_valid(): cd = form.cleaned_data if cd.has_key('option1'): f = HomeForm(filter_con = cd.get('option1')) return render_to_response('homepage.html', {'home_form':f,}, context_instance=RequestContext(request)) return render_to_response('invalid_data.html', {'form':form,}, context_instance=RequestContext(request)) else: f = HomeForm(filter_con = '***') return render_to_response('homepage.html', {'home_form':f,}, context_instance=RequestContext(request)) homepage.html <!DOCTYPE HTML> <head> <title>Nivaaran</title> </head> <body> <form method="post" name = 'choose_opt' action=""> {% csrf_token %} Choose your Option1: {{ home_form.option1 }} <br/> Choose your Option2: {{ home_form.option2 }} </form> </body>

    Read the article

  • asynchronous writing and reading of a file

    - by tazim
    hi, I have two processes. 1.) One processes is redirecting output of some unix command to a file on server side.the data is always appended to the file eg : find / > tmp.txt 2.)Another process is opening and reading the same file and storing it in a string and sending the entire string to the client Now, this things take simultaneously. I am using python. Any suggestion as in what can be possible ways to implement this scenario . Please explain with sample code . Thanks in advance . Tazim.

    Read the article

  • How to handle expired items?

    - by Mark
    My site allows users to post things on the site with an expiry date. Once the item has expired, it will no longer be displayed in the listings. Posts can also be closed, canceled, or completed. I think it would be be nicest just to be able to check for one attribute or status ("is active") rather than having to check for [is not expired, is not completed, is not closed, is not canceled]. Handling the rest of those is easy because I can just have one "status" field which is essentially an enum, but AFAIK, it's impossible to set the status to "expired" as soon as that time occurs. How do people typically handle this?

    Read the article

  • Drawbacks of using an integer as a bitfield?

    - by Mark
    I have a bunch of boolean options for things like "accepted payment types" which can include things like cash, credit card, cheque, paypal, etc. Rather than having a half dozen booleans in my DB, I can just use an integer and assign each payment method an integer, like so PAYMENT_METHODS = ( (1<<0, 'Cash'), (1<<1, 'Credit Card'), (1<<2, 'Cheque'), (1<<3, 'Other'), ) and then query the specific bit in python to retrieve the flag. I know this means the database can't index by specific flags, but are there any other drawbacks?

    Read the article

  • writing javascripts function using jquery

    - by tazim
    Some template written using jquery is as follows . it is not working . Any suggestions to use jquery efficiently . <html> <head> <script type="text/javascript" src="/jquerycall/"></script> <script type="text/javascript"> $(document).ready(function() { self.setInterval("clock()",1000); $("button").click(function() { clock; }); function clock() { clock(); time=new Date(); var s = "<p>" + time + "</p>"; $(s).appendTo("div"); } }); </script> </head> <body> <form method="post"> <button type="button">Click Me</button> <div id="someid"></div> </form> </body> </html>

    Read the article

  • can't save form content to database, help plsss!!

    - by dana
    i'm trying to save 100 caracters form user in a 'microblog' minimal application. my code seems to not have any mystakes, but doesn't work. the mistake is in views.py, i can't save the foreign key to user table models.py looks like this: class NewManager(models.Manager): def create_post(self, post, username): new = self.model(post=post, created_by=username) new.save() return new class New(models.Model): post = models.CharField(max_length=120) date = models.DateTimeField(auto_now_add=True) created_by = models.ForeignKey(User, blank=True) objects = NewManager() class NewForm(ModelForm): class Meta: model = New fields = ['post'] # widgets = {'post': Textarea(attrs={'cols': 80, 'rows': 20}) def save_new(request): if request.method == 'POST': created_by = User.objects.get(created_by = user) date = request.POST.get('date', '') post = request.POST.get('post', '') new_obj = New(post=post, date=date, created_by=created_by) new_obj.save() return HttpResponseRedirect('/') else: form = NewForm() return render_to_response('news/new_form.html', {'form': form},context_instance=RequestContext(request)) i didn't mention imports here - they're done right, anyway. my mistake is in views.py, when i try to save it says: local variable 'created_by' referenced before assignment it i put created_py as a parameter, the save needs more parameters... it is really weird help please!!

    Read the article

  • Amazon S3 permissions

    - by Joe
    Trying to understand S3...How do you limit access to a file you upload to S3? For example, from a web application, each user has files they can upload, but how do you limit access so only that user has access to that file? It seems like the query string authentication requires an expiration date and that won't work for me, is there another way to do this?

    Read the article

  • reading input file from server and displaying output on client side

    - by tazim
    Hi, I have to read a file from server side . Obtained its contents stored it in a list and sent it to template Now, My question is how to access this list so as to display the contents of files line by line . I am using ajax and jquery to obtain the data on client side def showfiledata(request): f = open("/home/tazim/webexample/test.txt") list = f.readlines() return_dict = {'list':list} json = simplejson.dumps(list) return HttpResponse(json,mimetype="application/json")

    Read the article

  • Setting a form field's value during validation

    - by LaundroMat
    I read about this issue already, but I'm having trouble understanding why I can't change the value of a form's field during validation. I have a form where a user can enter a decimal value. This value has to be higher than the initial value of the item the user is changing. During clean(), the value that was entered is checked against the item's previous value. I would like to be able to re-set the form field's value to the item's initial value when a user enters a lower value. Is this possible from within the clean() method, or am I forced to do this in the view? Somehow, it doesn't feel right to do this in the view... (To make matters more complicated, the form's fields are built up dynamically, meaning I have to override the form's clean() method instead of using the clean_() method).

    Read the article

  • Normalising book titles - Python

    - by RadiantHex
    Hi folks, I have a list of books titles: "The Hobbit: 70th Anniversary Edition" "The Hobbit" "The Hobbit (Illustrated/Collector Edition)[There and Back Again]" "The Hobbit: or, There and Back Again" "The Hobbit: Gift Pack" and so on... I thought that if I normalised the titles somehow, it would be easier to implement an automated way to know what book each edition is referring to. normalised = ''.join([char for char in title if char in (string.ascii_letters + string.digits)]) or normalised = '' for char in title: if char in ':/()|': break normalised += char return normalised But obviously they are not working as intended, as titles can contain special characters and editions can basically have very different title layouts. Help would be very much appreciated! Thanks :)

    Read the article

  • Design question?

    - by Mohamed
    I am building music app, where user can do several tasks including but not limited to listening song, like song, recommend song to a friend and extra. currently I have this model: class Activity(models.Model): activity = models.TextField() user = models.ForeignKey(User) date = models.DateTimeField(auto_now=True) so far I thought about two solutions. 1. saving a string to database. e.g "you listened song xyz" 2. create a dictionary about the activity and save to the database using pickle or json. e.g. dict_ = {"activity_type":"listening", "song":song_obj} I am leaning to the second implementation, but not quite sure. so what do you think about those two methods? do you know better way to achieve the goal?

    Read the article

  • using javascript with help of jquery

    - by tazim
    Code written by me based on previous suggestions as follows . Any help to efficinetly use jquery in order to make this code work . Thanks in advance $(document).ready(function() { self.setInterval("clock()",1000); $("button").click(function() { clock; }); function clock() { clock(); time=new Date(); var s = "<p>" + time + "</p>"; $(s).appendTo("div"); } }); <button > Click Me button </div> <div id="someid"></div>

    Read the article

  • importing data using get or create - identity error 1062

    - by hamackey
    I am importing data from a mssql database into mysql. Works except when it encounters the id of a previous entry. id is unique. I need to get entries that already exist so that they can be placed in the work of the day. Error is IntegrityError: (1062, "Duplicate entry '001355338' for key 2") This entry is already in the database. I need it entered for that day, but can not have it added to the table. It is already there. def handle(self, *args, **options): 59 #patients_local = Patient.objects.all() 60 #attendings_local = Attending.objects.all() 61 connection = pyodbc.connect("XXXXXXXXXXX") 62 cursor = connection.cursor() 63 cursor.execute(COMMAND) 64 rows = cursor.fetchall() 65 for row in rows: 66 # get_or_create returns (object, boolean) 67 p, created = Patient.objects.get_or_create( 68 first_name = row.Firstname, 69 middle_name = '', 70 last_name = row.Lastname, 71 id = row.id, 72 )

    Read the article

  • There is a system alert of (13, 'Permission denied'), how to solve that?

    - by Semanty
    def upload_file(request, step_id): def handle_uploaded_file (file): current_step = Step.objects.get(pk=step_id) current_project = Project.objects.get(pk=current_step.project.pk) path = "%s/upload/file/%s/%s" % (settings.MEDIA_ROOT, current_project.project_no, current_step.name) if not os.path.exists (path): os.makedirs(path) fd = open(path) for chunk in file.chunks(): fd.write(chunk) fd.close() if request.method == 'POST': form = UploadFileForm(request.POST, request.FILES) if form.is_valid(): handle_uploaded_file(request.FILES['file']) return HttpResponseRedirect('/success/url/') else: form = UploadFileForm() return render_to_response('projects/upload_file.html', { 'step_id': step_id, 'form': form, })

    Read the article

  • displaying the file data in correct format

    - by tazim
    hi, In views.py def showfiledata(request): with open("/home/tazim/webexample/tmp.txt") as f: read_data = f.read() f.closed return_dict = {'filedata':read_data} json = simplejson.dumps(return_dict) return HttpResponse(json,mimetype="application/json") In the template: < html < head < script type="text/javascript" src="/jquerycall/" < script type="text/javascript" $(document).ready(function() { $("button").click(function() { $.ajax({ type:"POST", url:"/showfiledata/", datatype:"json", success:function(data) { var s = data.filedata; $("#someid").html(s); } }); }); }); < /script < /head < body < form method="post" < button type="button"Click Me< /button < div id="someid"< /div < /form < /body < /html I am suppose to display file line by line . But, right now the lines get displayed withoout any linebreaks.

    Read the article

< Previous Page | 126 127 128 129 130 131 132 133 134 135 136 137  | Next Page >