Exemplo n.º 1
0
def register(request):
    if request.GET.get('username'):
        username = request.GET['username']
        password = request.GET['password1']
        email = request.GET['email']
        data = {}
        if User.objects.filter(username=username):
            data['invalid_user'] = True
        if User.objects.filter(email=email):
            data['invalid_email'] = True
        if (not data.get('invalid_user') and (not data.get('invalid_email'))):
            user = User.objects.create_user(username, request.GET['email'],
                                            password)
            user.save()

            sett = Settings()
            sett.usuario = user
            sett.clave = "tooltips"
            sett.valor = "true"
            sett.save()

            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active:
                    djlogin(request, user)
                    data['user'] = username
        return js(data)

    return render_to_response('registrar.html',
                              context_instance=RequestContext(request))
Exemplo n.º 2
0
def runProcess():
    jar = cookielib.CookieJar()
    u = get("https://www.rbi.org.in/Scripts/bs_viewcontent.aspx?Id=2009", cookies=jar)
    pattern = re.compile(r'<th>.*as on\s(.*)</th>')
    dateString = pattern.findall(u.content)[0]
    rbiLastModifiedDate = datetime.strptime(dateString.strip(), '%B %d, %Y')

    if(Settings.objects(settingsID="datesettings").first()):
        settings = Settings.objects.get(settingsID="datesettings")
        if rbiLastModifiedDate > settings.lastUpdated:
            print ("Data modified in rbi website.\nDownloading new data..")
            settings.lastUpdated = rbiLastModifiedDate
            settings.save()

            #Download files from rbi and save to xls/
            downloadFiles()

            #Parse details from xls files and insert into mongodb
            parseFiles()
        else:
            print ("Data is up to date.\n")
    else:
        print ("Running for the first time.")
        settings = Settings()
        settings.lastUpdated = rbiLastModifiedDate
        settings.yomLastFetched = rbiLastModifiedDate
        settings.save()

        downloadFiles()
        parseFiles()

    return True
Exemplo n.º 3
0
def register(request):
	if request.GET.get('username'):
		username = request.GET['username']
		password = request.GET['password1']
		email = request.GET['email']
		data = {}
		if User.objects.filter(username=username):
			data['invalid_user']=True
		if User.objects.filter(email=email):
			data['invalid_email']=True
		if (not data.get('invalid_user') and (not data.get('invalid_email'))):
			user = User.objects.create_user(username, request.GET['email'], password)
			user.save()
			
			sett = Settings()
			sett.usuario = user;
			sett.clave = "tooltips"
			sett.valor = "true"
			sett.save()
			
			user = authenticate(username=username, password=password)
			if user is not None:
				if user.is_active:
					djlogin(request, user)
					data['user']=username
		return js(data)

	return render_to_response('registrar.html',
								context_instance=RequestContext(request))
Exemplo n.º 4
0
def register(request):
    if request.method == 'POST':
        span = {1:False}
        form = NewUserForm(request.POST)
        if form.is_valid():
            new_user = form.save()
            user = auth.authenticate(
                email=request.POST.get('email', ''),
                password=request.POST.get('password1',''))
            if user is not None:
                auth.login(request, user)
                profile = Profile(user=user)
                profile.save()
                settings = Settings(user=user)
                settings.save()
                return HttpResponseRedirect("/create/profile/")
            else:
                span[1] = True
                form = NewUserForm()
    else:
        form = NewUserForm()
        span = {1:False}
    return render(request, "registration/register.html", {
        'form': form,
        'span': span
        })
Exemplo n.º 5
0
 def post(self, request, *args, **kwargs):
     visble_q_types = []
     for key in request.POST:
         if key.startswith('quest-type'):
             visble_q_types.append(int(key[-1]))
     if Settings.objects.filter(user=request.user).exists():
         setting = Settings.objects.get(user=request.user)
         setting.options = {'visible_type': visble_q_types}
     else:
         setting = Settings()
         setting.user = request.user
         setting.options = {'visible_type': visble_q_types}
     setting.save()
     return self.get(request, *args, **kwargs)
Exemplo n.º 6
0
def api_saveSettings(request):
    if request.user.is_authenticated():
        try:
            settings = Settings.objects.get(user=request.user)
        except:
            settings = Settings()
            settings.user = request.user
        
        form = SettingsForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            if form.cleaned_data['reminders']:
                settings.reminderDays = form.cleaned_data['reminderDays']
            else:
                settings.reminderDays = 0
            settings.defaultFB = form.cleaned_data['defaultFB']
            settings.defaultPublic = form.cleaned_data['defaultPublic']
            settings.save()
            return HttpResponse("Saved.") 
        else:
            return HttpResponse("Something broke.")
    else:
        return HttpResponseForbidden()
Exemplo n.º 7
0
def testdb(request):
    test1 = Settings(name='runoob')
    test1.save()
    return HttpResponse("<p>db add success</p>")
Exemplo n.º 8
0
def index(request,username=None,inFb=False):

    if request.user.is_authenticated() or username is not None:
        
        import datetime
        if request.user.is_authenticated(): gtForm = GoodThingForm()
        else: gtForm = None
        
        #get some stats for the user
        if username is not None: 
            try:
                statsuser = User.objects.get(username=username)
            except:
                return HttpResponseNotFound("User not found.")
        else:
            #someone is looking at their homepage. let's make sure we have a current token.
            fb = django_facebook.api.get_persistent_graph(request)
            try: 
                trial = fb.get('me/friends')
            except:
                #no valid oauth token, get them to log in again.
                logout(request) 
                t = loader.get_template('index.html')
                c = RequestContext(request,{'inFb':inFb})
                return HttpResponse(t.render(c))
            
            statsuser = request.user
            #okay, so we should add some settings
            try:
                settings = Settings.objects.select_related().get(user=request.user)
            except:
                settings = Settings()
                settings.user = request.user
                settings.save()
            
            initial={'defaultFB': settings.defaultFB, 'defaultPublic': settings.defaultPublic}
            if settings.reminderDays != 0:
                initial['reminders']=True
                initial['reminderDays']=settings.reminderDays
            else: 
                initial['reminders'] = False;
            
            settingsForm = SettingsForm(initial=initial)
            
        gtcount = GoodThing.objects.filter(user=statsuser).filter(deleted=False).count()
        perday = float(gtcount)/max(((timezone.now() - statsuser.date_joined).days),1)
        
        if gtcount > 0:
            try:
                wc = WordClouds.objects.get(user=statsuser)
            except:
                wc = WordClouds()
                wc.user = statsuser
                wc.updateClouds()
        else: wc = None
        
        t = loader.get_template('myview.html')
        cdict = {'form':gtForm,'gtcount':gtcount,'perday':perday,'wc':wc,'inFb':inFb}
        if username is not None: cdict['viewuser'] = statsuser
        else:
            cdict['settings'] = settings
            cdict['settingsform'] = settingsForm
        
        c = RequestContext(request,cdict)
        
        return HttpResponse(t.render(c))
    #and if not, let's get them logged in
    
    else:
        #return HttpResponse(request.__str__())
        t = loader.get_template('index.html')
        c = RequestContext(request,{'inFb':inFb})
        return HttpResponse(t.render(c))