def create_users(users): for person in users: try: print("Update User: "******"Create User: "******"Summary of results for " + str(user)) wsrg.save() user_stats = StatsUser(user=user, ws_report_group=wsrg) user_stats.save() if person[0] != 'anonymous': stats_reg_users.user_stats.add(user_stats) stats_reg_users.save()
def create_users(users): for person in users: is_anonymous = person[0] == 'anonymous' try: print("Update User: "******"Create User: "******"Summary of results for " + str(user)) wsrg.save() user_stats = StatsUser(user=user, ws_report_group=wsrg) user_stats.save() if not is_anonymous: stats_reg_users.user_stats.add(user_stats) stats_reg_users.save()
def user_registered_callback(sender, user, request, **kwargs): profile = UserProfile(user = user) profile.account_type = AccountType.objects.get(type_id=DEFAULT_ACCOUNT_TYPE) profile.org = '' profile.save() # Update first and last name for user user.first_name = request.POST['first_name'] user.last_name = request.POST['last_name'] user.save() wsrg = WebsiteReportGroup(title="Summary of results for " + str(user)) wsrg.save() user_stats = StatsUser(user=user, ws_report_group=wsrg) user_stats.save()
def user_registered_callback(sender, user, request, **kwargs): profile = UserProfile(user=user) profile.account_type = AccountType.objects.get( type_id=DEFAULT_ACCOUNT_TYPE) profile.org = '' profile.save() # Update first and last name for user user.first_name = request.POST['first_name'] user.last_name = request.POST['last_name'] user.save() wsrg = WebsiteReportGroup(title="Summary of results for " + str(user)) wsrg.save() user_stats = StatsUser(user=user, ws_report_group=wsrg) user_stats.save()
def get_profile(user): try: profile = UserProfile.objects.get(user=user) except: atype = AccountType.objects.get(type_id=DEFAULT_ACCOUNT_TYPE) profile = UserProfile(user=user, account_type=atype) profile.save() profile.update_institutional_subscription() try: stats = StatsUser.objects.get(user=user) except ObjectDoesNotExist: wsrg = WebsiteReportGroup(title="Summary of results for " + str(user)) wsrg.save() stats = StatsUser(user=user, ws_report_group=wsrg) stats.save() return profile
def get_redirect_url(self, *args, **kwargs): user = self.request.user if user.username == SHIBBOLETH_SUPERUSER: user.is_staff = True user.is_superuser = True user.save() try: profile = UserProfile.objects.get(user=user) except: atype = AccountType.objects.get(type_id=DEFAULT_ACCOUNT_TYPE) profile = UserProfile(user=user, account_type=atype) profile.save() try: stats = StatsUser.objects.get(user=user) except ObjectDoesNotExist: wsrg = WebsiteReportGroup(title="Summary of results for " + str(user)) wsrg.save() stats = StatsUser(user=user, ws_report_group=wsrg) stats.save() # Try to populate user information from shibboleth information if user.first_name == '' or user.last_name == '' or user.email == '': try: user.first_name = self.request.META['givenName'] user.last_name = self.request.META['sn'] user.email = self.request.META['mail'] user.save() except: pass self.url = SITE_URL return super(ShibbolethLogin, self).get_redirect_url(*args, **kwargs)
def get_context_data(self, **kwargs): context = super(ShowUsageStatistics, self).get_context_data(**kwargs) try: stats_all = StatsAll.objects.all()[0] except: wsrg = WebsiteReportGroup(title="Summary of all reports") wsrg.save() stats_all = StatsAll(ws_report_group=wsrg) stats_all.save() today = datetime.date.today() year = StatsYear.objects.filter(year=today.year) if len(year) == 0: wsrg = WebsiteReportGroup(title="Summary of results year: " + str(today.year)) wsrg.save() year = StatsYear(year=today.year, ws_report_group=wsrg, stats_all=stats_all) year.save() else: year = year[0] years = StatsYear.objects.all() month = StatsMonth.objects.filter(stats_year=year, month=today.month) if len(month) == 0: wsrg = WebsiteReportGroup(title="Summary of results month: " + str(today.year) + "-" + str(today.month)) wsrg.save() month = StatsMonth(stats_year=year, month=today.month, ws_report_group=wsrg) month.save() else: month = month[0] months = StatsMonth.objects.all() day = StatsDay.objects.filter(stats_month=month, day=today.day) if len(day) == 0: wsrg = WebsiteReportGroup(title="Summary of results day: " + str(today.year) + "-" + str(today.month) + "-" + str(today.day)) wsrg.save() day = StatsDay(stats_month=month, day=today.day, date=today, ws_report_group=wsrg) day.save() else: day = day[0] days = [] days.append(day) d = day.get_previous_day() if d: days.append(d) d = d.get_previous_day() if d: days.append(d) d = d.get_previous_day() if d: days.append(d) d = d.get_previous_day() if d: days.append(d) d = day.get_previous_day() if d: days.append(d) d = d.get_previous_day() if d: days.append(d) seven_days = WebsiteReportGroup(title="Summary of last seven days") for d in days: seven_days.num_total_reports += d.ws_report_group.num_total_reports seven_days.num_total_pages += d.ws_report_group.num_total_pages stats_reg_users = StatsRegisteredUsers.objects.all() if len(stats_reg_users) > 0: stats_reg_users = stats_reg_users[0] else: wsrg = WebsiteReportGroup(title="Summary of registered users") wsrg.save() stats_reg_users = StatsRegisteredUsers(ws_report_group=wsrg) stats_reg_users.save() stats_anonymous = StatsUser.objects.get(user__username='******') stats_rulesets = StatsRuleset.objects.all() context['stats_all'] = stats_all context['stats_year'] = year context['stats_month'] = month context['stats_day'] = day context['stats_seven_days'] = seven_days context['stats_all_years'] = StatsYear.objects.all() context['stats_all_months'] = StatsMonth.objects.all() context['stats_reg_users'] = stats_reg_users context['stats_anonymous'] = stats_anonymous context['stats_rulesets'] = stats_rulesets return context
def get_context_data(self, **kwargs): context = super(ShowUsageStatistics, self).get_context_data(**kwargs) try: stats_all = StatsAll.objects.all()[0] except: wsrg = WebsiteReportGroup(title="Summary of all reports") wsrg.save() stats_all = StatsAll(ws_report_group=wsrg) stats_all.save() today= datetime.date.today() try: year = StatsYear.objects.get(year=today.year) except ObjectDoesNotExist: wsrg = WebsiteReportGroup(title="Summary of results year: " + str(today.year)) wsrg.save() year = StatsYear(year=today.year, ws_report_group=wsrg, stats_all=stats_all) year.save() years = StatsYear.objects.all() try: month = StatsMonth.objects.get(stats_year=year, month=today.month) except ObjectDoesNotExist: wsrg = WebsiteReportGroup(title="Summary of results month: " + str(today.year) + "-" + str(today.month)) wsrg.save() month = StatsMonth(stats_year=year, month=today.month, ws_report_group=wsrg) month.save() months = StatsMonth.objects.all() try: day = StatsDay.objects.get(stats_month=month, day=today.day) except ObjectDoesNotExist: wsrg = WebsiteReportGroup(title="Summary of results day: " + str(today.year) + "-" + str(today.month) + "-" + str(today.day)) wsrg.save() day = StatsDay(stats_month=month, day=today.day, date=today, ws_report_group=wsrg) day.save() seven_days = StatsDay.objects.all()[:7] wsrg = WebsiteReportGroup(title="Summary of last seven days") for d in seven_days: wsrg.num_total_reports += d.ws_report_group.num_total_reports wsrg.num_total_pages += d.ws_report_group.num_total_pages seven_days.ws_report_group = wsrg stats_reg_users = StatsRegisteredUsers.objects.all() if len(stats_reg_users) > 0: stats_reg_users = stats_reg_users[0] else: wsrg = WebsiteReportGroup(title="Summary of registered users") wsrg.save() stats_reg_users = StatsRegisteredUsers(ws_report_group=wsrg) stats_reg_users.save() stats_anonymous = StatsUser.objects.get(user__username='******') stats_rulesets = StatsRuleset.objects.all() context['stats_all'] = stats_all context['stats_year'] = year context['stats_month'] = month context['stats_day'] = day context['stats_seven_days'] = seven_days context['stats_reg_users'] = stats_reg_users context['stats_anonymous'] = stats_anonymous context['stats_rulesets'] = stats_rulesets return context
from websiteResultGroups.models import WebsiteReportGroup from stats.models import StatsUser from stats.models import StatsRegisteredUsers users = ( (settings.ADMIN_USER_NAME, settings.ADMIN_PASSWORD, settings.ADMIN_EMAIL, settings.ADMIN_FIRST_NAME, settings.ADMIN_LAST_NAME, True, True, True), ('anonymous', settings.ANONYMOUS_PASSWORD, '', 'Anonymous', 'Anonymous', True, False, False), ) try: stats_reg_users = StatsRegisteredUsers.objects.all()[0] except: wsrg = WebsiteReportGroup(title="Summary of all registered users") wsrg.save() stats_reg_users = StatsRegisteredUsers(ws_report_group=wsrg) stats_reg_users.save() def create_users(users): for person in users: is_anonymous = person[0] == 'anonymous' try: print("Update User: " + person[0]) user = User.objects.get(username=person[0]) user.email = person[2] user.first_name = person[3] user.last_name = person[4]