<commit_before>from django.db import models
from django.contrib.auth.models import User

from django.core.exceptions import ValidationError

from django.contrib import admin

from settings.models import VotingSystem

import json

# Create your models here.
class Admin(models.Model):
	user = models.ForeignKey(User)
	system = models.ForeignKey(VotingSystem)

	class Meta():
		unique_together = (("system", "user"))

	def __str__(self):
		return u'[%s] %s' % (self.system.machine_name, self.user)



class SuperAdmin(models.Model):
	user = models.ForeignKey(User, unique = True)

	def __str__(self):
		return u'%s' % (self.user)

class UserProfile(models.Model):
	user = models.OneToOneField(User, related_name="profile")
	details = models.TextField()

	def __str__(self):
		return u'[Profile] %s' % (self.user.username)

	def clean(self):
		# make sure that the details are a valid json object
		try:
			json.loads(self.details)
		except:
			raise ValidationError({
				'details': ValidationError('Details needs to be a valid JSON object', code='invalid')
			})
	def isSuperAdmin(self):
		"""
			Returns if this user is a SuperAdmin.
		"""
		return self.user.superadmin_set.count() > 0
	def isAdminFor(self, system):
		"""
			Checks if this user can administer a certain voting system.
		"""
		return system in self.getAdministratedSystems()<commit_msg>Workaround to supress :warning: fields.W342<commit_after>from django.db import models
from django.contrib.auth.models import User

from django.core.exceptions import ValidationError

from django.contrib import admin

from settings.models import VotingSystem

import json

# Create your models here.
class Admin(models.Model):
	user = models.ForeignKey(User)
	system = models.ForeignKey(VotingSystem)

	class Meta():
		unique_together = (("system", "user"))

	def __str__(self):
		return u'[%s] %s' % (self.system.machine_name, self.user)



class SuperAdmin(models.Model):
	user = models.ForeignKey(User)
	
	class Meta():
		unique_together = (("user",),)

	def __str__(self):
		return u'%s' % (self.user)

class UserProfile(models.Model):
	user = models.OneToOneField(User, related_name="profile")
	details = models.TextField()

	def __str__(self):
		return u'[Profile] %s' % (self.user.username)

	def clean(self):
		# make sure that the details are a valid json object
		try:
			json.loads(self.details)
		except:
			raise ValidationError({
				'details': ValidationError('Details needs to be a valid JSON object', code='invalid')
			})
	def isSuperAdmin(self):
		"""
			Returns if this user is a SuperAdmin.
		"""
		return self.user.superadmin_set.count() > 0
	def isAdminFor(self, system):
		"""
			Checks if this user can administer a certain voting system.
		"""
		return system in self.getAdministratedSystems()
{'fraction_non_alphanumeric': 0.11872970046914472, 'fraction_numerical': 0.001804402742692169, 'mean_word_length': 4.5551102204408815, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2434081', 'n_tokens_mistral': 941, 'n_tokens_neox': 860, 'n_words': 253}